mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
refactor tests (#1982)
This commit is contained in:
parent
0ea35f3fbc
commit
646c6cacbc
25 changed files with 373 additions and 521 deletions
|
@ -9,35 +9,28 @@ fn test_output_is_random_permutation() {
|
|||
.collect::<Vec<String>>()
|
||||
.join("\n");
|
||||
|
||||
let result = new_ucmd!()
|
||||
.pipe_in(input.as_bytes())
|
||||
.succeeds()
|
||||
.no_stderr()
|
||||
.stdout
|
||||
.clone();
|
||||
let result = new_ucmd!().pipe_in(input.as_bytes()).succeeds();
|
||||
result.no_stderr();
|
||||
|
||||
let mut result_seq: Vec<i32> = result
|
||||
.stdout_str()
|
||||
.split("\n")
|
||||
.filter(|x| !x.is_empty())
|
||||
.map(|x| x.parse().unwrap())
|
||||
.collect();
|
||||
result_seq.sort();
|
||||
assert_ne!(result, input, "Output is not randomised");
|
||||
assert_ne!(result.stdout_str(), input, "Output is not randomised");
|
||||
assert_eq!(result_seq, input_seq, "Output is not a permutation");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_zero_termination() {
|
||||
let input_seq = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
||||
let result = new_ucmd!()
|
||||
.arg("-z")
|
||||
.arg("-i1-10")
|
||||
.succeeds()
|
||||
.no_stderr()
|
||||
.stdout
|
||||
.clone();
|
||||
let result = new_ucmd!().arg("-z").arg("-i1-10").succeeds();
|
||||
result.no_stderr();
|
||||
|
||||
let mut result_seq: Vec<i32> = result
|
||||
.stdout_str()
|
||||
.split("\0")
|
||||
.filter(|x| !x.is_empty())
|
||||
.map(|x| x.parse().unwrap())
|
||||
|
@ -57,12 +50,11 @@ fn test_echo() {
|
|||
.map(|x| x.to_string())
|
||||
.collect::<Vec<String>>(),
|
||||
)
|
||||
.succeeds()
|
||||
.no_stderr()
|
||||
.stdout
|
||||
.clone();
|
||||
.succeeds();
|
||||
result.no_stderr();
|
||||
|
||||
let mut result_seq: Vec<i32> = result
|
||||
.stdout_str()
|
||||
.split("\n")
|
||||
.filter(|x| !x.is_empty())
|
||||
.map(|x| x.parse().unwrap())
|
||||
|
@ -84,12 +76,11 @@ fn test_head_count() {
|
|||
let result = new_ucmd!()
|
||||
.args(&["-n", &repeat_limit.to_string()])
|
||||
.pipe_in(input.as_bytes())
|
||||
.succeeds()
|
||||
.no_stderr()
|
||||
.stdout
|
||||
.clone();
|
||||
.succeeds();
|
||||
result.no_stderr();
|
||||
|
||||
let mut result_seq: Vec<i32> = result
|
||||
.stdout_str()
|
||||
.split("\n")
|
||||
.filter(|x| !x.is_empty())
|
||||
.map(|x| x.parse().unwrap())
|
||||
|
@ -99,7 +90,7 @@ fn test_head_count() {
|
|||
assert!(
|
||||
result_seq.iter().all(|x| input_seq.contains(x)),
|
||||
"Output includes element not from input: {}",
|
||||
result
|
||||
result.stdout_str()
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -117,12 +108,11 @@ fn test_repeat() {
|
|||
.arg("-r")
|
||||
.args(&["-n", &repeat_limit.to_string()])
|
||||
.pipe_in(input.as_bytes())
|
||||
.succeeds()
|
||||
.no_stderr()
|
||||
.stdout
|
||||
.clone();
|
||||
.succeeds();
|
||||
result.no_stderr();
|
||||
|
||||
let result_seq: Vec<i32> = result
|
||||
.stdout_str()
|
||||
.split("\n")
|
||||
.filter(|x| !x.is_empty())
|
||||
.map(|x| x.parse().unwrap())
|
||||
|
@ -146,14 +136,11 @@ fn test_repeat() {
|
|||
fn test_file_input() {
|
||||
let expected_seq = vec![11, 12, 13, 14, 15, 16, 17, 18, 19, 20];
|
||||
|
||||
let result = new_ucmd!()
|
||||
.arg("file_input.txt")
|
||||
.succeeds()
|
||||
.no_stderr()
|
||||
.stdout
|
||||
.clone();
|
||||
let result = new_ucmd!().arg("file_input.txt").succeeds();
|
||||
result.no_stderr();
|
||||
|
||||
let mut result_seq: Vec<i32> = result
|
||||
.stdout_str()
|
||||
.split("\n")
|
||||
.filter(|x| !x.is_empty())
|
||||
.map(|x| x.parse().unwrap())
|
||||
|
@ -164,52 +151,50 @@ fn test_file_input() {
|
|||
|
||||
#[test]
|
||||
fn test_shuf_echo_and_input_range_not_allowed() {
|
||||
let result = new_ucmd!().args(&["-e", "0", "-i", "0-2"]).run();
|
||||
|
||||
assert!(!result.success);
|
||||
assert!(result
|
||||
.stderr
|
||||
.contains("The argument '--input-range <LO-HI>' cannot be used with '--echo <ARG>...'"));
|
||||
new_ucmd!()
|
||||
.args(&["-e", "0", "-i", "0-2"])
|
||||
.fails()
|
||||
.stderr_contains(
|
||||
"The argument '--input-range <LO-HI>' cannot be used with '--echo <ARG>...'",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_shuf_input_range_and_file_not_allowed() {
|
||||
let result = new_ucmd!().args(&["-i", "0-9", "file"]).run();
|
||||
|
||||
assert!(!result.success);
|
||||
assert!(result
|
||||
.stderr
|
||||
.contains("The argument '<file>' cannot be used with '--input-range <LO-HI>'"));
|
||||
new_ucmd!()
|
||||
.args(&["-i", "0-9", "file"])
|
||||
.fails()
|
||||
.stderr_contains("The argument '<file>' cannot be used with '--input-range <LO-HI>'");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_shuf_invalid_input_range_one() {
|
||||
let result = new_ucmd!().args(&["-i", "0"]).run();
|
||||
|
||||
assert!(!result.success);
|
||||
assert!(result.stderr.contains("invalid input range"));
|
||||
new_ucmd!()
|
||||
.args(&["-i", "0"])
|
||||
.fails()
|
||||
.stderr_contains("invalid input range");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_shuf_invalid_input_range_two() {
|
||||
let result = new_ucmd!().args(&["-i", "a-9"]).run();
|
||||
|
||||
assert!(!result.success);
|
||||
assert!(result.stderr.contains("invalid input range: 'a'"));
|
||||
new_ucmd!()
|
||||
.args(&["-i", "a-9"])
|
||||
.fails()
|
||||
.stderr_contains("invalid input range: 'a'");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_shuf_invalid_input_range_three() {
|
||||
let result = new_ucmd!().args(&["-i", "0-b"]).run();
|
||||
|
||||
assert!(!result.success);
|
||||
assert!(result.stderr.contains("invalid input range: 'b'"));
|
||||
new_ucmd!()
|
||||
.args(&["-i", "0-b"])
|
||||
.fails()
|
||||
.stderr_contains("invalid input range: 'b'");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_shuf_invalid_input_line_count() {
|
||||
let result = new_ucmd!().args(&["-n", "a"]).run();
|
||||
|
||||
assert!(!result.success);
|
||||
assert!(result.stderr.contains("invalid line count: 'a'"));
|
||||
new_ucmd!()
|
||||
.args(&["-n", "a"])
|
||||
.fails()
|
||||
.stderr_contains("invalid line count: 'a'");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue