mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
cksum: add tests and fixtures (#1923)
This commit is contained in:
parent
9581fcf688
commit
cbe07c93c6
3 changed files with 78 additions and 0 deletions
|
@ -24,3 +24,79 @@ fn test_stdin() {
|
|||
.succeeds()
|
||||
.stdout_is_fixture("stdin.expected");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_empty() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
|
||||
at.touch("a");
|
||||
|
||||
ucmd.arg("a").succeeds().stdout.ends_with("0 a");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_arg_overrides_stdin() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
let input = "foobarfoobar";
|
||||
|
||||
at.touch("a");
|
||||
|
||||
let result = ucmd.arg("a").pipe_in(input.as_bytes()).run();
|
||||
|
||||
println!("{}, {}", result.stdout, result.stderr);
|
||||
|
||||
assert!(result.stdout.ends_with("0 a\n"))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_invalid_file() {
|
||||
let (_, mut ucmd) = at_and_ucmd!();
|
||||
|
||||
let ls = TestScenario::new("ls");
|
||||
let files = ls.cmd("ls").arg("-l").run();
|
||||
println!("{:?}", files.stdout);
|
||||
println!("{:?}", files.stderr);
|
||||
|
||||
let folder_name = "asdf".to_string();
|
||||
|
||||
let result = ucmd.arg(&folder_name).run();
|
||||
|
||||
println!("stdout: {:?}", result.stdout);
|
||||
println!("stderr: {:?}", result.stderr);
|
||||
assert!(result.stderr.contains("cksum: error: 'asdf'"));
|
||||
assert!(!result.success);
|
||||
}
|
||||
|
||||
// Make sure crc is correct for files larger than 32 bytes
|
||||
// but <128 bytes (1 fold pclmul)
|
||||
#[test]
|
||||
fn test_crc_for_bigger_than_32_bytes() {
|
||||
let (_, mut ucmd) = at_and_ucmd!();
|
||||
|
||||
let result = ucmd.arg("chars.txt").run();
|
||||
|
||||
let mut stdout_splitted = result.stdout.split(" ");
|
||||
|
||||
let cksum: i64 = stdout_splitted.next().unwrap().parse().unwrap();
|
||||
let bytes_cnt: i64 = stdout_splitted.next().unwrap().parse().unwrap();
|
||||
|
||||
assert!(result.success);
|
||||
assert_eq!(cksum, 586047089);
|
||||
assert_eq!(bytes_cnt, 16);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_stdin_larger_than_128_bytes() {
|
||||
let (_, mut ucmd) = at_and_ucmd!();
|
||||
|
||||
let result = ucmd.arg("larger_than_2056_bytes.txt").run();
|
||||
|
||||
let mut stdout_splitted = result.stdout.split(" ");
|
||||
|
||||
let cksum: i64 = stdout_splitted.next().unwrap().parse().unwrap();
|
||||
let bytes_cnt: i64 = stdout_splitted.next().unwrap().parse().unwrap();
|
||||
|
||||
assert!(result.success);
|
||||
assert_eq!(cksum, 945881979);
|
||||
assert_eq!(bytes_cnt, 2058);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue