Skip to main content

Output

Trait Output 

Source
pub trait Output {
    // Required methods
    fn writeln(&mut self, line: &str);
    fn write(&mut self, text: &str);
    fn verbose(&mut self, f: Box<dyn FnOnce() -> String>);
    fn shell_command(&mut self, cmd: &str);
    fn shell_line(&mut self, line: &str);
    fn step_result(
        &mut self,
        label: &str,
        success: bool,
        elapsed_ms: u128,
        viewport: &[String],
    );

    // Provided methods
    fn dry_run_shell(&mut self, _cmd: &str) { ... }
    fn dry_run_write(&mut self, _path: &str) { ... }
    fn dry_run_delete(&mut self, _path: &str) { ... }
    fn log(&mut self, mode: OutputMode, msg: &str) { ... }
    fn log_exec(&mut self, mode: OutputMode, cmd: &Command) { ... }
}
Expand description

Abstraction over console output, enabling tests to capture output in memory.

The three standard implementations are:

  • ConsoleOutput — writes to stdout, respecting quiet / verbose.
  • StringOutput — captures everything in a String for assertions.
  • MockShell’s internal output — not part of this trait, but follows the same pattern.

Implement this trait to redirect output to a logger, a file, or anywhere else.

Required Methods§

Source

fn writeln(&mut self, line: &str)

Write line followed by a newline. Suppressed in quiet mode.

Source

fn write(&mut self, text: &str)

Write text without a trailing newline. Suppressed in quiet mode.

Source

fn verbose(&mut self, f: Box<dyn FnOnce() -> String>)

Emit a lazily-evaluated message, only in verbose mode.

The closure is only called when the implementation decides to display it, avoiding string allocation cost in non-verbose builds.

Source

fn shell_command(&mut self, cmd: &str)

Echo a shell command about to be run (verbose mode only).

Source

fn shell_line(&mut self, line: &str)

Echo a single line of output from a running shell command.

Source

fn step_result( &mut self, label: &str, success: bool, elapsed_ms: u128, viewport: &[String], )

Render the result of a completed step: a tick/cross, label, elapsed time, and (on failure) the last few lines of output from the viewport.

Provided Methods§

Source

fn dry_run_shell(&mut self, _cmd: &str)

Dry-run: announce a shell command that would be executed.

Source

fn dry_run_write(&mut self, _path: &str)

Dry-run: announce a file that would be written.

Source

fn dry_run_delete(&mut self, _path: &str)

Dry-run: announce a file or directory that would be deleted.

Source

fn log(&mut self, mode: OutputMode, msg: &str)

Log a message in verbose mode without any extra ceremony.

Source

fn log_exec(&mut self, mode: OutputMode, cmd: &Command)

Log a command about to be executed (verbose mode).

Implementors§