Skip to content

Commit 8c382f1

Browse files
author
biplab5464
committed
formatting the test cases cksum: stops when one of given files doesn't exist #5809
1 parent 2ff4920 commit 8c382f1

File tree

1 file changed

+31
-81
lines changed

1 file changed

+31
-81
lines changed

tests/by-util/test_cksum.rs

Lines changed: 31 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,34 @@ fn test_nonexisting_file() {
8080
.stderr_contains(format!("cksum: {file_name}: No such file or directory"));
8181
}
8282

83+
#[test]
84+
fn test_one_nonexisting_file() {
85+
let (at, mut ucmd) = at_and_ucmd!();
86+
87+
at.touch("abc.txt");
88+
at.touch("xyz.txt");
89+
90+
ucmd.arg("abc.txt")
91+
.arg("asdf.txt")
92+
.arg("xyz.txt")
93+
.fails()
94+
.stdout_contains_line("4294967295 0 xyz.txt")
95+
.stderr_contains("asdf.txt: No such file or directory")
96+
.stdout_contains_line("4294967295 0 abc.txt");
97+
}
98+
99+
#[test]
100+
fn test_folder() {
101+
let (at, mut ucmd) = at_and_ucmd!();
102+
103+
let folder_name = "a_folder";
104+
at.mkdir(folder_name);
105+
106+
ucmd.arg(folder_name)
107+
.succeeds()
108+
.stdout_only(format!("4294967295 0 {folder_name}\n"));
109+
}
110+
83111
// Make sure crc is correct for files larger than 32 bytes
84112
// but <128 bytes (1 fold pclmul) // spell-checker:disable-line
85113
#[test]
@@ -276,93 +304,15 @@ fn test_length_is_zero() {
276304
}
277305

278306
#[test]
279-
fn test_raw_single_file() {
280-
for algo in ALGOS {
281-
new_ucmd!()
282-
.arg("--raw")
283-
.arg("lorem_ipsum.txt")
284-
.arg(format!("--algorithm={algo}"))
285-
.succeeds()
286-
.no_stderr()
287-
.stdout_is_fixture_bytes(format!("raw/{algo}_single_file.expected"));
288-
}
289-
}
290-
#[test]
291-
fn test_raw_multiple_files() {
292-
new_ucmd!()
293-
.arg("--raw")
294-
.arg("lorem_ipsum.txt")
295-
.arg("alice_in_wonderland.txt")
296-
.fails()
297-
.no_stdout()
298-
.stderr_contains("cksum: the --raw option is not supported with multiple files")
299-
.code_is(1);
300-
}
301-
302-
#[test]
303-
fn test_fail_on_folder() {
307+
fn test_blake2b_fail_on_directory() {
304308
let (at, mut ucmd) = at_and_ucmd!();
305309

306310
let folder_name = "a_folder";
307311
at.mkdir(folder_name);
308312

309-
ucmd.arg(folder_name)
313+
ucmd.arg("--algorithm=blake2b")
314+
.arg(folder_name)
310315
.fails()
311316
.no_stdout()
312317
.stderr_contains(format!("cksum: {folder_name}: Is a directory"));
313318
}
314-
315-
#[test]
316-
fn test_all_algorithms_fail_on_folder() {
317-
let scene = TestScenario::new(util_name!());
318-
319-
let at = &scene.fixtures;
320-
321-
let folder_name = "a_folder";
322-
at.mkdir(folder_name);
323-
324-
for algo in ALGOS {
325-
scene
326-
.ucmd()
327-
.arg(format!("--algorithm={algo}"))
328-
.arg(folder_name)
329-
.fails()
330-
.no_stdout()
331-
.stderr_contains(format!("cksum: {folder_name}: Is a directory"));
332-
}
333-
}
334-
335-
#[test]
336-
fn test_folder_and_file() {
337-
let scene = TestScenario::new(util_name!());
338-
339-
let at = &scene.fixtures;
340-
341-
let folder_name = "a_folder";
342-
at.mkdir(folder_name);
343-
344-
scene
345-
.ucmd()
346-
.arg(folder_name)
347-
.arg("lorem_ipsum.txt")
348-
.fails()
349-
.stderr_contains(format!("cksum: {folder_name}: Is a directory"))
350-
.stdout_is_fixture("crc_single_file.expected");
351-
}
352-
353-
#[test]
354-
fn test_one_nonexisting_file(){
355-
let (at, mut ucmd) = at_and_ucmd!();
356-
357-
at.touch("abc.txt");
358-
at.touch("xyz.txt");
359-
360-
ucmd
361-
.arg("abc.txt")
362-
.arg("asdf.txt")
363-
.arg("xyz.txt")
364-
.fails()
365-
.stdout_contains_line("4294967295 0 xyz.txt")
366-
.stderr_contains("asdf.txt: No such file or directory")
367-
.stdout_contains_line("4294967295 0 abc.txt");
368-
}

0 commit comments

Comments
 (0)