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:
assert_program_args_stdout_eq!(a_program, a_args, b_program, b_args)≈ command using a_program and a_args to stdout = b_command with b_program and b_args to stdoutassert_program_args_stdout_ne!(a_program, a_args, b_program, b_args)≈ command using a_program and a_args to stdout ≠ b_command with b_program and b_args to stdoutassert_program_args_stdout_lt!(a_program, a_args, b_program, b_args)≈ command using a_program and a_args to stdout < b_command with b_program and b_args to stdoutassert_program_args_stdout_le!(a_program, a_args, b_program, b_args)≈ command using a_program and a_args to stdout ≤ b_command with b_program and b_args to stdoutassert_program_args_stdout_gt!(a_program, a_args, b_program, b_args)≈ command using a_program and a_args to stdout > b_command with b_program and b_args to stdoutassert_program_args_stdout_ge!(a_program, a_args, b_program, b_args)≈ command using a_program and a_args to stdout ≥ b_command with b_program and b_args to stdout
Compare program and arguments standard output to an expression:
assert_program_args_stdout_eq_x!(program, args, expr)≈ command using program and args to stdout = exprassert_program_args_stdout_ne_x!(program, args, expr)≈ command using program and args to stdout ≠ exprassert_program_args_stdout_lt_x!(program, args, expr)≈ command using program and args to stdout < exprassert_program_args_stdout_le_x!(program, args, expr)≈ command using program and args to stdout ≤ exprassert_program_args_stdout_gt_x!(program, args, expr)≈ command using program and args to stdout > exprassert_program_args_stdout_ge_x!(program, args, expr)≈ command using program and args to stdout ≥ expr
Assert program and arguments standard output as a string:
assert_program_args_stdout_string_contains!(program, args, containee)≈ command using program and args to stdout string contains containeeassert_program_args_stdout_string_is_match!(program, args, matcher)≈ matcher is match with command using program and args
§Program args stderr
Compare program and arguments standard error to another program and arguments standard error:
assert_program_args_stderr_eq!(a_program, a_args, b_program, b_args)≈ command using a_program and a_args to stderr = b_command with b_program and b_args to stderrassert_program_args_stderr_ne!(a_program, a_args, b_program, b_args)≈ command using a_program and a_args to stderr ≠ b_command with b_program and b_args to stderrassert_program_args_stderr_lt!(a_program, a_args, b_program, b_args)≈ command using a_program and a_args to stderr < b_command with b_program and b_args to stderrassert_program_args_stderr_le!(a_program, a_args, b_program, b_args)≈ command using a_program and a_args to stderr ≤ b_command with b_program and b_args to stderrassert_program_args_stderr_gt!(a_program, a_args, b_program, b_args)≈ command using a_program and a_args to stderr > b_command with b_program and b_args to stderrassert_program_args_stderr_ge!(a_program, a_args, b_program, b_args)≈ command using a_program and a_args to stderr ≥ b_command with b_program and b_args to stderr
Compare program and arguments standard error to an expression:
assert_program_args_stderr_eq_x!(program, args, expr)≈ command using program and args to stderr = exprassert_program_args_stderr_ne_x!(program, args, expr)≈ command using program and args to stderr ≠ exprassert_program_args_stderr_lt_x!(program, args, expr)≈ command using program and args to stderr < exprassert_program_args_stderr_le_x!(program, args, expr)≈ command using program and args to stderr ≤ exprassert_program_args_stderr_gt_x!(program, args, expr)≈ command using program and args to stderr > exprassert_program_args_stderr_ge_x!(program, args, expr)≈ command using program and args to stderr ≥ expr
Assert program and arguments standard error as a string:
assert_program_args_stderr_string_contains!(program, args, containee)≈ command using program and args to stderr string contains containeeassert_program_args_stderr_string_is_match!(program, args, matcher)≈ matcher is match with command using program and args
§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 helloRust 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.