Module assert_program_args

Source
Expand description

Assert for comparing programs with arguments.

These macros help with calling external programs with arguments, then capturing the standard output stream and standard error stream. See tutorial below.

These macros have corresponding macros in the module assert_command.

§Program args stdout

Compare program and arguments standard output to another program and arguments standard output:

Compare program and arguments standard output to an expression:

Assert program and arguments standard output as a string:

§Program args stderr

Compare program and arguments standard error to another program and arguments standard error:

Compare program and arguments standard error to an expression:

Assert program and arguments standard error as a string:

§Example

use assertables::*;

let a_program = "bin/printf-stdout";
let a_args = ["%s", "alfa"];
let b_program = "bin/printf-stdout";
let b_args = ["%s%s%s%s", "a", "l", "f", "a"];
assert_program_args_stdout_eq!(&a_program, &a_args, &b_program, &b_args);

§Tutorial

Rust programs can call system commands.

For example this system command will print the word hello:

printf %s hello

Rust can create a system command then capture its standard output, by using:

let program = "printf";
let args = ["%s", "hello"];
let mut command = Command::new(program);
command.args(args);
let stdout = command.output().unwrap().stdout;

Rust can compare a command’s standard output to another command’s standard output, by using:

let a_program = "printf";
let a_args = ["%s", "hello"];
let b_program = "printf";
let b_args = ["%s", "world"];
let mut a_command = Command::new(a_program); a_command.args(a_args);
let mut b_command = Command::new(b_program); b_command.args(b_args);
let a_stdout = a_command.output().unwrap().stdout;
let b_stdout = b_command.output().unwrap().stdout;
assert_ne!(a_stdout, b_stdout);

The assertables crate provides macros that do the same kind of processing, by automatically converting programs and args into commands, then to standard outputs:

let a_program = "printf";
let a_args = ["%s", "hello"];
let b_program = "printf";
let b_args = ["%s", "world"];
assert_program_args_stdout_ne!(a_program, a_args, b_program, b_args);

Modules§

assert_program_args_stderr_contains
Assert a command (built with program and args) stderr into a string contains a given containee.
assert_program_args_stderr_eq
Assert a command (built with program and args) stderr is equal to another.
assert_program_args_stderr_eq_x
Assert a command (built with program and args) stderr is equal to an expression.
assert_program_args_stderr_ge
Assert a command (built with program and args) stderr is greater than or equal to another.
assert_program_args_stderr_ge_x
Assert a command (built with program and args) stderr is greater than or equal to an expression.
assert_program_args_stderr_gt
Assert a command (built with program and args) stderr is greater than to another.
assert_program_args_stderr_gt_x
Assert a command (built with program and args) stderr is greater than an expression.
assert_program_args_stderr_is_match
Assert a command (built with program and args) stderr into a string is a match to a regex.
assert_program_args_stderr_le
Assert a command (built with program and args) stderr is less than or equal to another.
assert_program_args_stderr_le_x
Assert a command (built with program and args) stderr is less than or equal to an expression.
assert_program_args_stderr_lt
Assert a command (built with program and args) stderr is less than another.
assert_program_args_stderr_lt_x
Assert a command (built with program and args) stderr is less than an expression.
assert_program_args_stderr_ne
Assert a command (built with program and args) stderr is not equal to another.
assert_program_args_stderr_ne_x
Assert a command (built with program and args) stderr is not equal to an expression.
assert_program_args_stderr_string_contains
Assert a command (built with program and args) stderr into a string contains a given containee.
assert_program_args_stderr_string_is_match
Assert a command (built with program and args) stderr into a string is a match to a regex.
assert_program_args_stdout_contains
Assert a command (built with program and args) stdout into a string contains a given containee.
assert_program_args_stdout_eq
Assert a command (built with program and args) stdout is equal to another.
assert_program_args_stdout_eq_x
Assert a command (built with program and args) stdout is equal to an expression.
assert_program_args_stdout_ge
Assert a command (built with program and args) stdout is greater than or equal to another.
assert_program_args_stdout_ge_x
Assert a command (built with program and args) stdout is greater than or equal to an expression.
assert_program_args_stdout_gt
Assert a command (built with program and args) stdout is greater than another.
assert_program_args_stdout_gt_x
Assert a command (built with program and args) stdout is greater than an expression.
assert_program_args_stdout_is_match
Assert a command (built with program and args) stdout into a string is a match to a regex.
assert_program_args_stdout_le
Assert a command (built with program and args) stdout is less than or equal to another.
assert_program_args_stdout_le_x
Assert a command (built with program and args) stdout is less than or equal to an expression.
assert_program_args_stdout_lt
Assert a command (built with program and args) stdout is less than another.
assert_program_args_stdout_lt_x
Assert a command (built with program and args) stdout is less than an expression.
assert_program_args_stdout_ne
Assert a command (built with program and args) stdout is not equal to another.
assert_program_args_stdout_ne_x
Assert a command (built with program and args) stdout is not equal to an expression.
assert_program_args_stdout_string_contains
Assert a command (built with program and args) stdout into a string contains a given containee.
assert_program_args_stdout_string_is_match
Assert a command (built with program and args) stdout into a string is a match to a regex.