| 1 |
// This file is part of the uutils coreutils package. |
| 2 |
// |
| 3 |
// For the full copyright and license information, please view the LICENSE |
| 4 |
// file that was distributed with this source code. |
| 5 |
|
| 6 |
use uutests::new_ucmd; |
| 7 |
// spell-checker:ignore checkfile, testf, ntestf |
| 8 |
macro_rules! get_hash( |
| 9 |
($str:expr) => ( |
| 10 |
$str.split(' ').collect::<Vec<&str>>()[0] |
| 11 |
); |
| 12 |
); |
| 13 |
|
| 14 |
macro_rules! test_digest { |
| 15 |
($id:ident) => { |
| 16 |
mod $id { |
| 17 |
use uutests::util::*; |
| 18 |
use uutests::util_name; |
| 19 |
static EXPECTED_FILE: &'static str = concat!(stringify!($id), ".expected"); |
| 20 |
static CHECK_FILE: &'static str = concat!(stringify!($id), ".checkfile"); |
| 21 |
static INPUT_FILE: &'static str = "input.txt"; |
| 22 |
|
| 23 |
#[test] |
| 24 |
fn test_single_file() { |
| 25 |
let ts = TestScenario::new(util_name!()); |
| 26 |
assert_eq!( |
| 27 |
ts.fixtures.read(EXPECTED_FILE), |
| 28 |
get_hash!( |
| 29 |
ts.ucmd() |
| 30 |
.arg(INPUT_FILE) |
| 31 |
.succeeds() |
| 32 |
.no_stderr() |
| 33 |
.stdout_str() |
| 34 |
) |
| 35 |
); |
| 36 |
} |
| 37 |
|
| 38 |
#[test] |
| 39 |
fn test_stdin() { |
| 40 |
let ts = TestScenario::new(util_name!()); |
| 41 |
assert_eq!( |
| 42 |
ts.fixtures.read(EXPECTED_FILE), |
| 43 |
get_hash!( |
| 44 |
ts.ucmd() |
| 45 |
.pipe_in_fixture(INPUT_FILE) |
| 46 |
.succeeds() |
| 47 |
.no_stderr() |
| 48 |
.stdout_str() |
| 49 |
) |
| 50 |
); |
| 51 |
} |
| 52 |
|
| 53 |
#[test] |
| 54 |
fn test_stdin_with_dash_directory() { |
| 55 |
let ts = TestScenario::new(util_name!()); |
| 56 |
ts.fixtures.mkdir("-"); |
| 57 |
assert_eq!( |
| 58 |
ts.fixtures.read(EXPECTED_FILE), |
| 59 |
get_hash!( |
| 60 |
ts.ucmd() |
| 61 |
.pipe_in_fixture(INPUT_FILE) |
| 62 |
.succeeds() |
| 63 |
.no_stderr() |
| 64 |
.stdout_str() |
| 65 |
) |
| 66 |
); |
| 67 |
} |
| 68 |
|
| 69 |
#[test] |
| 70 |
fn test_check() { |
| 71 |
let ts = TestScenario::new(util_name!()); |
| 72 |
println!("File content='{}'", ts.fixtures.read(INPUT_FILE)); |
| 73 |
println!("Check file='{}'", ts.fixtures.read(CHECK_FILE)); |
| 74 |
|
| 75 |
ts.ucmd() |
| 76 |
.args(&["--check", CHECK_FILE]) |
| 77 |
.succeeds() |
| 78 |
.no_stderr() |
| 79 |
.stdout_is("input.txt: OK\n"); |
| 80 |
} |
| 81 |
|
| 82 |
#[test] |
| 83 |
fn test_zero() { |
| 84 |
let ts = TestScenario::new(util_name!()); |
| 85 |
assert_eq!( |
| 86 |
ts.fixtures.read(EXPECTED_FILE), |
| 87 |
get_hash!( |
| 88 |
ts.ucmd() |
| 89 |
.arg("--zero") |
| 90 |
.arg(INPUT_FILE) |
| 91 |
.succeeds() |
| 92 |
.no_stderr() |
| 93 |
.stdout_str() |
| 94 |
) |
| 95 |
); |
| 96 |
} |
| 97 |
|
| 98 |
#[test] |
| 99 |
fn test_missing_file() { |
| 100 |
let ts = TestScenario::new(util_name!()); |
| 101 |
let at = &ts.fixtures; |
| 102 |
|
| 103 |
at.write("a", "file1\n"); |
| 104 |
at.write("c", "file3\n"); |
| 105 |
|
| 106 |
ts.ucmd() |
| 107 |
.args(&["a", "b", "c"]) |
| 108 |
.fails() |
| 109 |
.stdout_contains("a\n") |
| 110 |
.stdout_contains("c\n") |
| 111 |
.stderr_contains("b: No such file or directory"); |
| 112 |
} |
| 113 |
} |
| 114 |
}; |
| 115 |
} |
| 116 |
|
| 117 |
test_digest! {sha384} |
| 118 |
|
| 119 |
#[test] |
| 120 |
fn test_invalid_arg() { |
| 121 |
new_ucmd!().arg("--definitely-invalid").fails_with_code(1); |
| 122 |
} |
| 123 |
|
| 124 |
#[test] |
| 125 |
fn test_conflicting_arg() { |
| 126 |
new_ucmd!().arg("--tag").arg("--check").fails_with_code(1); |
| 127 |
new_ucmd!().arg("--tag").arg("--text").fails_with_code(1); |
| 128 |
} |