#[macro_export]
macro_rules! assert_command_stdout_ge_x_as_result {
($a_command:expr, $b_expr:expr $(,)?) => {
match ($a_command.output(), &$b_expr) {
(Ok(a_output), b_expr) => {
let a = a_output.stdout;
if a.ge(b_expr) {
Ok(a)
} else {
Err(format!(
concat!(
"assertion failed: `assert_command_stdout_ge_x!(command, expr)`\n",
"https://docs.rs/assertables/9.9.0/assertables/macro.assert_command_stdout_ge_x.html\n",
" command label: `{}`,\n",
" command debug: `{:?}`,\n",
" command value: `{:?}`,\n",
" expr label: `{}`,\n",
" expr debug: `{:?}`,\n",
" expr value: `{:?}`"
),
stringify!($a_command),
$a_command,
a,
stringify!($b_expr),
$b_expr,
b_expr
))
}
}
(a, b) => Err(format!(
concat!(
"assertion failed: `assert_command_stdout_ge_x!(command, expr)`\n",
"https://docs.rs/assertables/9.9.0/assertables/macro.assert_command_stdout_ge_x.html\n",
" command label: `{}`,\n",
" command debug: `{:?}`,\n",
" command value: `{:?}`,\n",
" expr label: `{}`,\n",
" expr debug: `{:?}`,\n",
" expr value: `{:?}`"
),
stringify!($a_command),
$a_command,
a,
stringify!($b_expr),
$b_expr,
b
)),
}
};
}
#[cfg(test)]
mod test_assert_command_stdout_ge_x_as_result {
use std::process::Command;
use std::sync::Once;
#[test]
fn gt() {
let mut a = Command::new("bin/printf-stdout");
a.args(["%s", "alfa"]);
let b = vec![b'a', b'a'];
for _ in 0..1 {
let actual = assert_command_stdout_ge_x_as_result!(a, b);
assert_eq!(actual.unwrap(), vec![b'a', b'l', b'f', b'a']);
}
}
#[test]
fn gt_once() {
static A: Once = Once::new();
fn a() -> Command {
if A.is_completed() {
panic!("A.is_completed()")
} else {
A.call_once(|| {})
}
let mut a = Command::new("bin/printf-stdout");
a.args(["%s", "alfa"]);
a
}
static B: Once = Once::new();
fn b() -> Vec<u8> {
if B.is_completed() {
panic!("B.is_completed()")
} else {
B.call_once(|| {})
}
vec![b'a', b'a']
}
assert_eq!(A.is_completed(), false);
assert_eq!(B.is_completed(), false);
let result = assert_command_stdout_ge_x_as_result!(a(), b());
assert!(result.is_ok());
assert_eq!(A.is_completed(), true);
assert_eq!(B.is_completed(), true);
}
#[test]
fn eq() {
let mut a = Command::new("bin/printf-stdout");
a.args(["%s", "alfa"]);
let b = vec![b'a', b'l', b'f', b'a'];
for _ in 0..1 {
let actual = assert_command_stdout_ge_x_as_result!(a, b);
assert_eq!(actual.unwrap(), vec![b'a', b'l', b'f', b'a']);
}
}
#[test]
fn eq_once() {
static A: Once = Once::new();
fn a() -> Command {
if A.is_completed() {
panic!("A.is_completed()")
} else {
A.call_once(|| {})
}
let mut a = Command::new("bin/printf-stdout");
a.args(["%s", "alfa"]);
a
}
static B: Once = Once::new();
fn b() -> Vec<u8> {
if B.is_completed() {
panic!("B.is_completed()")
} else {
B.call_once(|| {})
}
vec![b'a', b'l', b'f', b'a']
}
assert_eq!(A.is_completed(), false);
assert_eq!(B.is_completed(), false);
let result = assert_command_stdout_ge_x_as_result!(a(), b());
assert!(result.is_ok());
assert_eq!(A.is_completed(), true);
assert_eq!(B.is_completed(), true);
}
#[test]
fn lt() {
let mut a = Command::new("bin/printf-stdout");
a.args(["%s", "alfa"]);
let b = vec![b'z', b'z'];
let actual = assert_command_stdout_ge_x_as_result!(a, b);
let message = concat!(
"assertion failed: `assert_command_stdout_ge_x!(command, expr)`\n",
"https://docs.rs/assertables/9.9.0/assertables/macro.assert_command_stdout_ge_x.html\n",
" command label: `a`,\n",
" command debug: `\"bin/printf-stdout\" \"%s\" \"alfa\"`,\n",
" command value: `[97, 108, 102, 97]`,\n",
" expr label: `b`,\n",
" expr debug: `[122, 122]`,\n",
" expr value: `[122, 122]`"
);
assert_eq!(actual.unwrap_err(), message);
}
}
#[macro_export]
macro_rules! assert_command_stdout_ge_x {
($a_command:expr, $b_expr:expr $(,)?) => {
match $crate::assert_command_stdout_ge_x_as_result!($a_command, $b_expr) {
Ok(x) => x,
Err(err) => panic!("{}", err),
}
};
($a_command:expr, $b_expr:expr, $($message:tt)+) => {
match $crate::assert_command_stdout_ge_x_as_result!($a_command, $b_expr) {
Ok(x) => x,
Err(err) => panic!("{}\n{}", format_args!($($message)+), err),
}
};
}
#[cfg(test)]
mod test_assert_command_stdout_ge_x {
use std::panic;
use std::process::Command;
#[test]
fn gt() {
let mut a = Command::new("bin/printf-stdout");
a.args(["%s", "alfa"]);
let b = vec![b'a', b'a'];
for _ in 0..1 {
let actual = assert_command_stdout_ge_x!(a, b);
assert_eq!(actual, vec![b'a', b'l', b'f', b'a']);
}
}
#[test]
fn eq() {
let mut a = Command::new("bin/printf-stdout");
a.args(["%s", "alfa"]);
let b = vec![b'a', b'l', b'f', b'a'];
for _ in 0..1 {
let actual = assert_command_stdout_ge_x!(a, b);
assert_eq!(actual, vec![b'a', b'l', b'f', b'a']);
}
}
#[test]
fn lt() {
let result = panic::catch_unwind(|| {
let mut a = Command::new("bin/printf-stdout");
a.args(["%s", "alfa"]);
let b = vec![b'z', b'z'];
let _actual = assert_command_stdout_ge_x!(a, b);
});
let message = concat!(
"assertion failed: `assert_command_stdout_ge_x!(command, expr)`\n",
"https://docs.rs/assertables/9.9.0/assertables/macro.assert_command_stdout_ge_x.html\n",
" command label: `a`,\n",
" command debug: `\"bin/printf-stdout\" \"%s\" \"alfa\"`,\n",
" command value: `[97, 108, 102, 97]`,\n",
" expr label: `b`,\n",
" expr debug: `[122, 122]`,\n",
" expr value: `[122, 122]`"
);
assert_eq!(
result
.unwrap_err()
.downcast::<String>()
.unwrap()
.to_string(),
message
);
}
}
#[macro_export]
macro_rules! debug_assert_command_stdout_ge_x {
($($arg:tt)*) => {
if cfg!(debug_assertions) {
$crate::assert_command_stdout_ge_x!($($arg)*);
}
};
}
#[cfg(test)]
mod test_debug_assert_command_stdout_ge_x {
use std::panic;
use std::process::Command;
#[test]
fn gt() {
let mut a = Command::new("bin/printf-stdout");
a.args(["%s", "alfa"]);
let b = vec![b'a', b'a'];
for _ in 0..1 {
let _actual = debug_assert_command_stdout_ge_x!(a, b);
}
}
#[test]
fn eq() {
let mut a = Command::new("bin/printf-stdout");
a.args(["%s", "alfa"]);
let b = vec![b'a', b'l', b'f', b'a'];
for _ in 0..1 {
let _actual = debug_assert_command_stdout_ge_x!(a, b);
}
}
#[test]
fn lt() {
let result = panic::catch_unwind(|| {
let mut a = Command::new("bin/printf-stdout");
a.args(["%s", "alfa"]);
let b = vec![b'z', b'z'];
let _actual = debug_assert_command_stdout_ge_x!(a, b);
});
let message = concat!(
"assertion failed: `assert_command_stdout_ge_x!(command, expr)`\n",
"https://docs.rs/assertables/9.9.0/assertables/macro.assert_command_stdout_ge_x.html\n",
" command label: `a`,\n",
" command debug: `\"bin/printf-stdout\" \"%s\" \"alfa\"`,\n",
" command value: `[97, 108, 102, 97]`,\n",
" expr label: `b`,\n",
" expr debug: `[122, 122]`,\n",
" expr value: `[122, 122]`"
);
assert_eq!(
result
.unwrap_err()
.downcast::<String>()
.unwrap()
.to_string(),
message
);
}
}