mirror of
https://github.com/uutils/coreutils
synced 2024-11-16 09:48:03 +00:00
99b39e4237
Although for some tests this adds characters we still use them there because the brevity cost is now worth the benefit in terms of instant, natural-language readability and recognizability for people not familiar with this tests of this module or even the project
39 lines
1.2 KiB
Rust
39 lines
1.2 KiB
Rust
macro_rules! get_hash(
|
|
($str:expr) => (
|
|
$str.split(' ').collect::<Vec<&str>>()[0]
|
|
);
|
|
);
|
|
|
|
macro_rules! test_digest {
|
|
($($t:ident)*) => ($(
|
|
|
|
mod $t {
|
|
use::common::util::*;
|
|
static UTIL_NAME: &'static str = "hashsum";
|
|
fn at_and_ucmd() -> (AtPath, UCommand) {
|
|
let ts = TestScenario::new(UTIL_NAME);
|
|
let ucmd = ts.ucmd();
|
|
(ts.fixtures, ucmd)
|
|
}
|
|
static DIGEST_ARG: &'static str = concat!("--", stringify!($t));
|
|
static EXPECTED_FILE: &'static str = concat!(stringify!($t), ".expected");
|
|
|
|
#[test]
|
|
fn test_single_file() {
|
|
let (at, mut ucmd) = at_and_ucmd();
|
|
assert_eq!(at.read(EXPECTED_FILE),
|
|
get_hash!(ucmd.arg(DIGEST_ARG).arg("input.txt").succeeds().no_stderr().stdout));
|
|
}
|
|
|
|
#[test]
|
|
fn test_stdin() {
|
|
let (at, mut ucmd) = at_and_ucmd();
|
|
let input = at.read("input.txt");
|
|
assert_eq!(at.read(EXPECTED_FILE),
|
|
get_hash!(ucmd.arg(DIGEST_ARG).pipe_in(input).succeeds().no_stderr().stdout));
|
|
}
|
|
}
|
|
)*)
|
|
}
|
|
|
|
test_digest! { md5 sha1 sha224 sha256 sha384 sha512 }
|