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