Skip to content

Commit

Permalink
formatting the test cases cksum: stops when one of given files doesn'…
Browse files Browse the repository at this point in the history
…t exist uutils#5809
  • Loading branch information
biplab5464 committed Jan 14, 2024
1 parent 2ff4920 commit 8c382f1
Showing 1 changed file with 31 additions and 81 deletions.
112 changes: 31 additions & 81 deletions tests/by-util/test_cksum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,34 @@ fn test_nonexisting_file() {
.stderr_contains(format!("cksum: {file_name}: No such file or directory"));
}

#[test]
fn test_one_nonexisting_file() {
let (at, mut ucmd) = at_and_ucmd!();

at.touch("abc.txt");
at.touch("xyz.txt");

ucmd.arg("abc.txt")
.arg("asdf.txt")
.arg("xyz.txt")
.fails()
.stdout_contains_line("4294967295 0 xyz.txt")
.stderr_contains("asdf.txt: No such file or directory")
.stdout_contains_line("4294967295 0 abc.txt");
}

#[test]
fn test_folder() {
let (at, mut ucmd) = at_and_ucmd!();

let folder_name = "a_folder";
at.mkdir(folder_name);

ucmd.arg(folder_name)
.succeeds()
.stdout_only(format!("4294967295 0 {folder_name}\n"));
}

// Make sure crc is correct for files larger than 32 bytes
// but <128 bytes (1 fold pclmul) // spell-checker:disable-line
#[test]
Expand Down Expand Up @@ -276,93 +304,15 @@ fn test_length_is_zero() {
}

#[test]
fn test_raw_single_file() {
for algo in ALGOS {
new_ucmd!()
.arg("--raw")
.arg("lorem_ipsum.txt")
.arg(format!("--algorithm={algo}"))
.succeeds()
.no_stderr()
.stdout_is_fixture_bytes(format!("raw/{algo}_single_file.expected"));
}
}
#[test]
fn test_raw_multiple_files() {
new_ucmd!()
.arg("--raw")
.arg("lorem_ipsum.txt")
.arg("alice_in_wonderland.txt")
.fails()
.no_stdout()
.stderr_contains("cksum: the --raw option is not supported with multiple files")
.code_is(1);
}

#[test]
fn test_fail_on_folder() {
fn test_blake2b_fail_on_directory() {
let (at, mut ucmd) = at_and_ucmd!();

let folder_name = "a_folder";
at.mkdir(folder_name);

ucmd.arg(folder_name)
ucmd.arg("--algorithm=blake2b")
.arg(folder_name)
.fails()
.no_stdout()
.stderr_contains(format!("cksum: {folder_name}: Is a directory"));
}

#[test]
fn test_all_algorithms_fail_on_folder() {
let scene = TestScenario::new(util_name!());

let at = &scene.fixtures;

let folder_name = "a_folder";
at.mkdir(folder_name);

for algo in ALGOS {
scene
.ucmd()
.arg(format!("--algorithm={algo}"))
.arg(folder_name)
.fails()
.no_stdout()
.stderr_contains(format!("cksum: {folder_name}: Is a directory"));
}
}

#[test]
fn test_folder_and_file() {
let scene = TestScenario::new(util_name!());

let at = &scene.fixtures;

let folder_name = "a_folder";
at.mkdir(folder_name);

scene
.ucmd()
.arg(folder_name)
.arg("lorem_ipsum.txt")
.fails()
.stderr_contains(format!("cksum: {folder_name}: Is a directory"))
.stdout_is_fixture("crc_single_file.expected");
}

#[test]
fn test_one_nonexisting_file(){
let (at, mut ucmd) = at_and_ucmd!();

at.touch("abc.txt");
at.touch("xyz.txt");

ucmd
.arg("abc.txt")
.arg("asdf.txt")
.arg("xyz.txt")
.fails()
.stdout_contains_line("4294967295 0 xyz.txt")
.stderr_contains("asdf.txt: No such file or directory")
.stdout_contains_line("4294967295 0 abc.txt");
}

0 comments on commit 8c382f1

Please sign in to comment.