mirror of
https://github.com/uutils/coreutils
synced 2024-10-06 16:09:08 +00:00
parent
6d4f70ccb2
commit
88d0bb01c0
4
.github/workflows/GNU.yml
vendored
4
.github/workflows/GNU.yml
vendored
|
@ -84,8 +84,8 @@ jobs:
|
|||
sed -i 's|stat|/usr/bin/stat|' tests/chgrp/basic.sh tests/cp/existing-perm-dir.sh tests/touch/60-seconds.sh tests/misc/sort-compress-proc.sh
|
||||
sed -i 's|ls -|/usr/bin/ls -|' tests/chgrp/posix-H.sh tests/chown/deref.sh tests/cp/same-file.sh tests/misc/mknod.sh tests/mv/part-symlink.sh tests/du/8gb.sh
|
||||
sed -i 's|mkdir |/usr/bin/mkdir |' tests/cp/existing-perm-dir.sh tests/rm/empty-inacc.sh
|
||||
sed -i 's|timeout \([[:digit:]]\)| /usr/bin/timeout \1|' tests/tail-2/inotify-rotate.sh tests/tail-2/inotify-dir-recreate.sh tests/tail-2/inotify-rotate-resources.sh tests/cp/parent-perm-race.sh tests/ls/infloop.sh tests/misc/sort-exit-early.sh tests/misc/sort-NaN-infloop.sh tests/misc/uniq-perf.sh tests/tail-2/inotify-only-regular.sh tests/tail-2/pipe-f2.sh tests/tail-2/retry.sh tests/tail-2/symlink.sh tests/tail-2/wait.sh tests/tail-2/pid.sh tests/dd/stats.sh tests/tail-2/follow-name.sh # Don't break the function called 'grep_timeout'
|
||||
sed -i 's|chmod |/usr/bin/chmod |' tests/du/inacc-dir.sh tests/mkdir/p-3.sh tests/tail-2/tail-n0f.sh tests/cp/fail-perm.sh tests/du/inaccessible-cwd.sh tests/mv/i-2.sh tests/chgrp/basic.sh
|
||||
sed -i 's|timeout \([[:digit:]]\)| /usr/bin/timeout \1|' tests/tail-2/inotify-rotate.sh tests/tail-2/inotify-dir-recreate.sh tests/tail-2/inotify-rotate-resources.sh tests/cp/parent-perm-race.sh tests/ls/infloop.sh tests/misc/sort-exit-early.sh tests/misc/sort-NaN-infloop.sh tests/misc/uniq-perf.sh tests/tail-2/inotify-only-regular.sh tests/tail-2/pipe-f2.sh tests/tail-2/retry.sh tests/tail-2/symlink.sh tests/tail-2/wait.sh tests/tail-2/pid.sh tests/dd/stats.sh tests/tail-2/follow-name.sh tests/misc/shuf.sh # Don't break the function called 'grep_timeout'
|
||||
sed -i 's|chmod |/usr/bin/chmod |' tests/du/inacc-dir.sh tests/mkdir/p-3.sh tests/tail-2/tail-n0f.sh tests/cp/fail-perm.sh tests/du/inaccessible-cwd.sh tests/mv/i-2.sh tests/chgrp/basic.sh tests/misc/shuf.sh
|
||||
sed -i 's|sort |/usr/bin/sort |' tests/ls/hyperlink.sh tests/misc/test-N.sh
|
||||
sed -i 's|split |/usr/bin/split |' tests/misc/factor-parallel.sh
|
||||
sed -i 's|truncate |/usr/bin/truncate |' tests/split/fail.sh
|
||||
|
|
|
@ -1,7 +1,168 @@
|
|||
// ToDO: add more tests
|
||||
|
||||
use crate::common::util::*;
|
||||
|
||||
#[test]
|
||||
fn test_output_is_random_permutation() {
|
||||
let input_seq = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
||||
let input = input_seq
|
||||
.iter()
|
||||
.map(|x| x.to_string())
|
||||
.collect::<Vec<String>>()
|
||||
.join("\n");
|
||||
|
||||
let result = new_ucmd!()
|
||||
.pipe_in(input.as_bytes())
|
||||
.succeeds()
|
||||
.no_stderr()
|
||||
.stdout
|
||||
.clone();
|
||||
|
||||
let mut result_seq: Vec<i32> = result
|
||||
.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_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 mut result_seq: Vec<i32> = result
|
||||
.split("\0")
|
||||
.filter(|x| !x.is_empty())
|
||||
.map(|x| x.parse().unwrap())
|
||||
.collect();
|
||||
result_seq.sort();
|
||||
assert_eq!(result_seq, input_seq, "Output is not a permutation");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_echo() {
|
||||
let input_seq = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
||||
let result = new_ucmd!()
|
||||
.arg("-e")
|
||||
.args(
|
||||
&input_seq
|
||||
.iter()
|
||||
.map(|x| x.to_string())
|
||||
.collect::<Vec<String>>(),
|
||||
)
|
||||
.succeeds()
|
||||
.no_stderr()
|
||||
.stdout
|
||||
.clone();
|
||||
|
||||
let mut result_seq: Vec<i32> = result
|
||||
.split("\n")
|
||||
.filter(|x| !x.is_empty())
|
||||
.map(|x| x.parse().unwrap())
|
||||
.collect();
|
||||
result_seq.sort();
|
||||
assert_eq!(result_seq, input_seq, "Output is not a permutation");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_head_count() {
|
||||
let repeat_limit = 5;
|
||||
let input_seq = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
||||
let input = input_seq
|
||||
.iter()
|
||||
.map(|x| x.to_string())
|
||||
.collect::<Vec<String>>()
|
||||
.join("\n");
|
||||
|
||||
let result = new_ucmd!()
|
||||
.args(&["-n", &repeat_limit.to_string()])
|
||||
.pipe_in(input.as_bytes())
|
||||
.succeeds()
|
||||
.no_stderr()
|
||||
.stdout
|
||||
.clone();
|
||||
|
||||
let mut result_seq: Vec<i32> = result
|
||||
.split("\n")
|
||||
.filter(|x| !x.is_empty())
|
||||
.map(|x| x.parse().unwrap())
|
||||
.collect();
|
||||
result_seq.sort();
|
||||
assert_eq!(result_seq.len(), repeat_limit, "Output is not limited");
|
||||
assert!(
|
||||
result_seq.iter().all(|x| input_seq.contains(x)),
|
||||
format!("Output includes element not from input: {}", result)
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_repeat() {
|
||||
let repeat_limit = 15000;
|
||||
let input_seq = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
||||
let input = input_seq
|
||||
.iter()
|
||||
.map(|x| x.to_string())
|
||||
.collect::<Vec<String>>()
|
||||
.join("\n");
|
||||
|
||||
let result = new_ucmd!()
|
||||
.arg("-r")
|
||||
.args(&["-n", &repeat_limit.to_string()])
|
||||
.pipe_in(input.as_bytes())
|
||||
.succeeds()
|
||||
.no_stderr()
|
||||
.stdout
|
||||
.clone();
|
||||
|
||||
let result_seq: Vec<i32> = result
|
||||
.split("\n")
|
||||
.filter(|x| !x.is_empty())
|
||||
.map(|x| x.parse().unwrap())
|
||||
.collect();
|
||||
assert_eq!(
|
||||
result_seq.len(),
|
||||
repeat_limit,
|
||||
"Output is not repeating forever"
|
||||
);
|
||||
assert!(
|
||||
result_seq.iter().all(|x| input_seq.contains(x)),
|
||||
format!(
|
||||
"Output includes element not from input: {:?}",
|
||||
result_seq
|
||||
.iter()
|
||||
.filter(|x| !input_seq.contains(x))
|
||||
.collect::<Vec<&i32>>()
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
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 mut result_seq: Vec<i32> = result
|
||||
.split("\n")
|
||||
.filter(|x| !x.is_empty())
|
||||
.map(|x| x.parse().unwrap())
|
||||
.collect();
|
||||
result_seq.sort();
|
||||
assert_eq!(result_seq, expected_seq, "Output is not a permutation");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_shuf_echo_and_input_range_not_allowed() {
|
||||
let result = new_ucmd!().args(&["-e", "0", "-i", "0-2"]).run();
|
||||
|
|
10
tests/fixtures/shuf/file_input.txt
vendored
Normal file
10
tests/fixtures/shuf/file_input.txt
vendored
Normal file
|
@ -0,0 +1,10 @@
|
|||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
Loading…
Reference in a new issue