Expand description
Assert for comparing commands and their stdout & stderr.
These macros help with calling external commands, then capturing the standard output stream and standard error stream. See tutorial below.
These macros have corresponding the macros in the module assert_program_args
.
§Macros for command standard output
Compare command standard output to another command standard output:
assert_command_stdout_eq!(a_command, b_command)
≈ a_command stdout = b_command stdoutassert_command_stdout_ne!(a_command, b_command)
≈ a_command stdout ≠ b_command stdoutassert_command_stdout_lt!(a_command, b_command)
≈ a_command stdout < b_command stdoutassert_command_stdout_le!(a_command, b_command)
≈ a_command stdout ≤ b_command stdoutassert_command_stdout_gt!(a_command, b_command)
≈ a_command stdout > b_command stdoutassert_command_stdout_ge!(a_command, b_command)
≈ a_command stdout ≥ b_command stdout
Compare command standard output to an expression:
assert_command_stdout_eq_x!(command, expr)
≈ command stdout = exprassert_command_stdout_ne_x!(command, expr)
≈ command stdout ≠ exprassert_command_stdout_lt_x!(command, expr)
≈ command stdout < exprassert_command_stdout_le_x!(command, expr)
≈ command stdout ≤ exprassert_command_stdout_gt_x!(command, expr)
≈ command stdout > exprassert_command_stdout_ge_x!(command, expr)
≈ command stdout ≥ expr
Assert command standard output as a string:
assert_command_stdout_string_contains!(command, containee)
≈ command stdout string contains containeeassert_command_stdout_string_is_match!(command, matcher)
≈ command stdout string is a matcher match
§Macros for command standard error
Compare command standard error to another command standard error:
assert_command_stderr_eq!(a_command, b_command)
≈ a_command stderr = b_command stderrassert_command_stderr_ne!(a_command, b_command)
≈ a_command stderr ≠ b_command stderrassert_command_stderr_lt!(a_command, b_command)
≈ a_command stderr < b_command stderrassert_command_stderr_le!(a_command, b_command)
≈ a_command stderr ≤ b_command stderrassert_command_stderr_gt!(a_command, b_command)
≈ a_command stderr > b_command stderrassert_command_stderr_ge!(a_command, b_command)
≈ a_command stderr ≥ b_command stderr
Compare command standard error to an expression:
assert_command_stderr_eq_x!(command, expr)
≈ command stderr = exprassert_command_stderr_ne_x!(command, expr)
≈ command stderr ≠ exprassert_command_stderr_lt_x!(command, expr)
≈ command stderr < exprassert_command_stderr_le_x!(command, expr)
≈ command stderr ≤ exprassert_command_stderr_gt_x!(command, expr)
≈ command stderr > exprassert_command_stderr_ge_x!(command, expr)
≈ command stderr ≥ expr
Assert standard error as a string:
assert_command_stderr_string_contains!(command, containee)
≈ command stderr string contains containeeassert_command_stderr_string_is_match!(command, matcher)
≈ command stderr string is a matcher match
§Example
use assertables::*;
use std::process::Command;
let mut a = Command::new("bin/printf-stdout");
a.args(["%s", "alfa"]);
let mut b = Command::new("bin/printf-stdout");
b.args(["%s%s%s%s", "a", "l", "f", "a"]);
assert_command_stdout_eq!(a, b);
§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 mut command = Command::new("printf"); command.args(["%s", "hello"]);
let stdout = command.output().unwrap().stdout;
Rust can compare a command’s standard output to another command’s standard output, by using:
let mut a_command = Command::new("printf"); a_command.args(["%s", "hello"]);
let mut b_command = Command::new("printf"); a_command.args(["%s", "world"]);
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 each command into standard output:
let mut a_command = Command::new("printf"); a_command.args(["%s", "hello"]);
let mut b_command = Command::new("printf"); a_command.args(["%s", "world"]);
assert_command_stdout_ne!(a_command, b_command);
Modules§
- assert_
command_ stderr_ contains - Assert a command stderr string contains a given containee.
- assert_
command_ stderr_ eq - Assert a command stderr string is equal to another.
- assert_
command_ stderr_ eq_ x - Assert a command stderr string is equal to an expression.
- assert_
command_ stderr_ ge - Assert a command stderr string is greater than or equal to another.
- assert_
command_ stderr_ ge_ x - Assert a command stderr string is greater than or equal to an expression.
- assert_
command_ stderr_ gt - Assert a command stderr string is greater than another.
- assert_
command_ stderr_ gt_ x - Assert a command stderr string is greater than an expression.
- assert_
command_ stderr_ is_ match - Assert a command stderr string is a match to a regex.
- assert_
command_ stderr_ le - Assert a command stderr string is less than or equal to another.
- assert_
command_ stderr_ le_ x - Assert a command stderr string is less than or equal to an expression.
- assert_
command_ stderr_ lt - Assert a command stderr string is less than another.
- assert_
command_ stderr_ lt_ x - Assert a command stderr string is less than an expression.
- assert_
command_ stderr_ ne - Assert a command stderr string is not equal to another.
- assert_
command_ stderr_ ne_ x - Assert a command stderr string is not equal to an expression.
- assert_
command_ stderr_ string_ contains - Assert a command stderr string contains a given containee.
- assert_
command_ stderr_ string_ is_ match - Assert a command stderr string is a match to a regex.
- assert_
command_ stdout_ contains - Assert a command stdout string contains a given containee.
- assert_
command_ stdout_ eq - Assert a command stdout string is equal to another.
- assert_
command_ stdout_ eq_ x - Assert a command stdout string is equal to an expression.
- assert_
command_ stdout_ ge - Assert a command stdout string is greater than or equal to another.
- assert_
command_ stdout_ ge_ x - Assert a command stdout string is greater than or equal to an expression.
- assert_
command_ stdout_ gt - Assert a command stdout string is greater than another.
- assert_
command_ stdout_ gt_ x - Assert a command stdout string is greater than an expression.
- assert_
command_ stdout_ is_ match - Assert a command stdout string is a match to a regex.
- assert_
command_ stdout_ le - Assert a command stdout string is less than or equal to another.
- assert_
command_ stdout_ le_ x - Assert a command stdout string is less than or equal to an expression.
- assert_
command_ stdout_ lt - Assert a command stdout string is less than another.
- assert_
command_ stdout_ lt_ x - Assert a command stdout string is less than an expression.
- assert_
command_ stdout_ ne - Assert a command stdout string is not equal to another.
- assert_
command_ stdout_ ne_ x - Assert a command stdout string is not equal to an expression.
- assert_
command_ stdout_ string_ contains - Assert a command stdout string contains a given containee.
- assert_
command_ stdout_ string_ is_ match - Assert a command stdout string is a match to a regex.