Function in io compiler

capture_begin

fn capture_begin()
Import
use io::{capture_begin};
Source: 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_end
  • stdin: 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 at path with mode and returns a stream on it.
  • close: Closes s.
  • read: Reads bytes from s into the front of buf without waiting.
  • write: Writes bytes from buf to s without waiting and returns how many were written.
↑ ↓ navigate ↵ open