capture_begin
fn capture_begin() Import
Source: use io::{capture_begin}; compiler/src/builtin_docs/io.hy Starts keeping this thread’s stdout and stderr writes in memory instead of writing them, until the matching capture_end().
Captures nest: each capture_end() closes the innermost one. Use it in
tests to check what code prints. Threads spawned while capturing write
to their own output. A capture still open when a test case ends goes to
that case’s output.
Examples#
use io::{capture_begin, capture_end, stdout, write};
use string::{to_bytes};
use tests::assert;
capture_begin();
let _ = write(stdout(), to_bytes("hi\n"));
let (out, err) = capture_end();
assert!(out == "hi\n" && err == "");
See also#
io::capture_endstdin: Returns a new stream on the process’s standard input.stdout: Returns a new stream on the process’s standard output.stderr: Returns a new stream on the process’s standard error.open: Opens the file atpathwithmodeand returns a stream on it.close: Closess.read: Reads bytes fromsinto the front ofbufwithout waiting.write: Writes bytes frombuftoswithout waiting and returns how many were written.