2020-05-25 17:05:26 +00:00
|
|
|
use crate::common::util::*;
|
2015-11-16 05:25:01 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_single_file() {
|
2020-04-13 18:36:03 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.arg("lorem_ipsum.txt")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is_fixture("single_file.expected");
|
2015-11-16 05:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_multiple_files() {
|
2016-08-23 11:52:43 +00:00
|
|
|
new_ucmd!()
|
2016-07-29 21:26:32 +00:00
|
|
|
.arg("lorem_ipsum.txt")
|
|
|
|
.arg("alice_in_wonderland.txt")
|
2020-04-13 18:36:03 +00:00
|
|
|
.succeeds()
|
|
|
|
.stdout_is_fixture("multiple_files.expected");
|
2015-11-16 05:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_stdin() {
|
2016-08-23 11:52:43 +00:00
|
|
|
new_ucmd!()
|
2016-07-29 21:26:32 +00:00
|
|
|
.pipe_in_fixture("lorem_ipsum.txt")
|
2020-04-13 18:36:03 +00:00
|
|
|
.succeeds()
|
|
|
|
.stdout_is_fixture("stdin.expected");
|
2015-11-16 05:25:01 +00:00
|
|
|
}
|
2021-04-05 20:21:21 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_empty() {
|
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
|
|
|
|
|
|
|
at.touch("a");
|
|
|
|
|
2021-04-17 12:01:52 +00:00
|
|
|
ucmd.arg("a")
|
|
|
|
.succeeds()
|
|
|
|
.no_stderr()
|
|
|
|
.normalized_newlines_stdout_is("4294967295 0 a\n");
|
2021-04-05 20:21:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_arg_overrides_stdin() {
|
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
|
|
|
let input = "foobarfoobar";
|
|
|
|
|
|
|
|
at.touch("a");
|
|
|
|
|
2021-04-17 12:01:52 +00:00
|
|
|
ucmd.arg("a")
|
2021-04-09 09:08:31 +00:00
|
|
|
.pipe_in(input.as_bytes())
|
|
|
|
// the command might have exited before all bytes have been pipe in.
|
|
|
|
// in that case, we don't care about the error (broken pipe)
|
|
|
|
.ignore_stdin_write_error()
|
2021-04-17 12:01:52 +00:00
|
|
|
.succeeds()
|
|
|
|
.no_stderr()
|
|
|
|
.normalized_newlines_stdout_is("4294967295 0 a\n");
|
2021-04-05 20:21:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_invalid_file() {
|
2021-04-17 12:01:52 +00:00
|
|
|
let ts = TestScenario::new(util_name!());
|
|
|
|
let at = ts.fixtures.clone();
|
|
|
|
|
|
|
|
let folder_name = "asdf";
|
|
|
|
|
|
|
|
// First check when file doesn't exist
|
2021-04-17 23:33:52 +00:00
|
|
|
ts.ucmd()
|
|
|
|
.arg(folder_name)
|
2021-04-17 12:01:52 +00:00
|
|
|
.fails()
|
|
|
|
.no_stdout()
|
|
|
|
.stderr_contains("cksum: error: 'asdf' No such file or directory");
|
2021-04-17 23:33:52 +00:00
|
|
|
|
2021-04-17 12:01:52 +00:00
|
|
|
// Then check when the file is of an invalid type
|
|
|
|
at.mkdir(folder_name);
|
2021-04-17 23:33:52 +00:00
|
|
|
ts.ucmd()
|
|
|
|
.arg(folder_name)
|
2021-04-17 12:01:52 +00:00
|
|
|
.fails()
|
|
|
|
.no_stdout()
|
|
|
|
.stderr_contains("cksum: error: 'asdf' Is a directory");
|
2021-04-05 20:21:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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!();
|
|
|
|
|
2021-04-17 12:01:52 +00:00
|
|
|
let result = ucmd.arg("chars.txt").succeeds();
|
2021-04-05 20:21:21 +00:00
|
|
|
|
2021-04-17 12:01:52 +00:00
|
|
|
let mut stdout_splitted = result.stdout_str().split(" ");
|
2021-04-05 20:21:21 +00:00
|
|
|
|
|
|
|
let cksum: i64 = stdout_splitted.next().unwrap().parse().unwrap();
|
|
|
|
let bytes_cnt: i64 = stdout_splitted.next().unwrap().parse().unwrap();
|
|
|
|
|
|
|
|
assert_eq!(cksum, 586047089);
|
|
|
|
assert_eq!(bytes_cnt, 16);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_stdin_larger_than_128_bytes() {
|
|
|
|
let (_, mut ucmd) = at_and_ucmd!();
|
|
|
|
|
2021-04-17 12:01:52 +00:00
|
|
|
let result = ucmd.arg("larger_than_2056_bytes.txt").succeeds();
|
2021-04-05 20:21:21 +00:00
|
|
|
|
2021-04-17 12:01:52 +00:00
|
|
|
let mut stdout_splitted = result.stdout_str().split(" ");
|
2021-04-05 20:21:21 +00:00
|
|
|
|
|
|
|
let cksum: i64 = stdout_splitted.next().unwrap().parse().unwrap();
|
|
|
|
let bytes_cnt: i64 = stdout_splitted.next().unwrap().parse().unwrap();
|
|
|
|
|
|
|
|
assert_eq!(cksum, 945881979);
|
|
|
|
assert_eq!(bytes_cnt, 2058);
|
|
|
|
}
|