mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 12:07:46 +00:00
Rewrote head (#1911)
See https://github.com/uutils/coreutils/pull/1911 for the details
This commit is contained in:
parent
da5f2f3a6c
commit
8320b1ec5f
8 changed files with 1235 additions and 256 deletions
105
tests/by-util/test_head.rs
Normal file → Executable file
105
tests/by-util/test_head.rs
Normal file → Executable file
|
@ -86,88 +86,74 @@ fn test_verbose() {
|
|||
.stdout_is_fixture("lorem_ipsum_verbose.expected");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_zero_terminated() {
|
||||
new_ucmd!()
|
||||
.args(&["-z", "zero_terminated.txt"])
|
||||
.run()
|
||||
.stdout_is_fixture("zero_terminated.expected");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn test_spams_newline() {
|
||||
//this test is does not mirror what GNU does
|
||||
new_ucmd!().pipe_in("a").succeeds().stdout_is("a\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn test_unsupported_byte_syntax() {
|
||||
fn test_byte_syntax() {
|
||||
new_ucmd!()
|
||||
.args(&["-1c"])
|
||||
.pipe_in("abc")
|
||||
.fails()
|
||||
//GNU head returns "a"
|
||||
.stdout_is("")
|
||||
.stderr_is("head: error: Unrecognized option: \'1\'");
|
||||
.run()
|
||||
.stdout_is("a");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn test_unsupported_line_syntax() {
|
||||
fn test_line_syntax() {
|
||||
new_ucmd!()
|
||||
.args(&["-n", "2048m"])
|
||||
.pipe_in("a\n")
|
||||
.fails()
|
||||
//.stdout_is("a\n"); What GNU head returns.
|
||||
.stdout_is("")
|
||||
.stderr_is("head: error: invalid line count \'2048m\': invalid digit found in string");
|
||||
.run()
|
||||
.stdout_is("a\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn test_unsupported_zero_terminated_syntax() {
|
||||
fn test_zero_terminated_syntax() {
|
||||
new_ucmd!()
|
||||
.args(&["-z -n 1"])
|
||||
.args(&["-z", "-n", "1"])
|
||||
.pipe_in("x\0y")
|
||||
.fails()
|
||||
//GNU Head returns "x\0"
|
||||
.stderr_is("head: error: Unrecognized option: \'z\'");
|
||||
.run()
|
||||
.stdout_is("x\0");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn test_unsupported_zero_terminated_syntax_2() {
|
||||
fn test_zero_terminated_syntax_2() {
|
||||
new_ucmd!()
|
||||
.args(&["-z -n 2"])
|
||||
.args(&["-z", "-n", "2"])
|
||||
.pipe_in("x\0y")
|
||||
.fails()
|
||||
//GNU Head returns "x\0y"
|
||||
.stderr_is("head: error: Unrecognized option: \'z\'");
|
||||
.run()
|
||||
.stdout_is("x\0y");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn test_unsupported_negative_byte_syntax() {
|
||||
fn test_negative_byte_syntax() {
|
||||
new_ucmd!()
|
||||
.args(&["--bytes=-2"])
|
||||
.pipe_in("a\n")
|
||||
.fails()
|
||||
//GNU Head returns ""
|
||||
.stderr_is("head: error: invalid byte count \'-2\': invalid digit found in string");
|
||||
.run()
|
||||
.stdout_is("");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn test_bug_in_negative_zero_lines() {
|
||||
fn test_negative_zero_lines() {
|
||||
new_ucmd!()
|
||||
.args(&["--lines=-0"])
|
||||
.pipe_in("a\nb\n")
|
||||
.succeeds()
|
||||
//GNU Head returns "a\nb\n"
|
||||
.stdout_is("");
|
||||
.stdout_is("a\nb\n");
|
||||
}
|
||||
#[test]
|
||||
fn test_negative_zero_bytes() {
|
||||
new_ucmd!()
|
||||
.args(&["--bytes=-0"])
|
||||
.pipe_in("qwerty")
|
||||
.succeeds()
|
||||
.stdout_is("qwerty");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_no_such_file_or_directory() {
|
||||
let result = new_ucmd!().arg("no_such_file.toml").run();
|
||||
|
@ -179,3 +165,38 @@ fn test_no_such_file_or_directory() {
|
|||
.contains("cannot open 'no_such_file.toml' for reading: No such file or directory")
|
||||
)
|
||||
}
|
||||
|
||||
// there was a bug not caught by previous tests
|
||||
// where for negative n > 3, the total amount of lines
|
||||
// was correct, but it would eat from the second line
|
||||
#[test]
|
||||
fn test_sequence_fixture() {
|
||||
new_ucmd!()
|
||||
.args(&["-n", "-10", "sequence"])
|
||||
.run()
|
||||
.stdout_is_fixture("sequence.expected");
|
||||
}
|
||||
#[test]
|
||||
fn test_file_backwards() {
|
||||
new_ucmd!()
|
||||
.args(&["-c", "-10", "lorem_ipsum.txt"])
|
||||
.run()
|
||||
.stdout_is_fixture("lorem_ipsum_backwards_file.expected");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_zero_terminated() {
|
||||
new_ucmd!()
|
||||
.args(&["-z", "zero_terminated.txt"])
|
||||
.run()
|
||||
.stdout_is_fixture("zero_terminated.expected");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_obsolete_extras() {
|
||||
new_ucmd!()
|
||||
.args(&["-5zv"])
|
||||
.pipe_in("1\02\03\04\05\06")
|
||||
.succeeds()
|
||||
.stdout_is("==> standard input <==\n1\02\03\04\05\0");
|
||||
}
|
||||
|
|
24
tests/fixtures/head/lorem_ipsum_backwards_file.expected
vendored
Normal file
24
tests/fixtures/head/lorem_ipsum_backwards_file.expected
vendored
Normal file
|
@ -0,0 +1,24 @@
|
|||
Lorem ipsum dolor sit amet,
|
||||
consectetur adipiscing elit.
|
||||
Nunc interdum suscipit sem vel ornare.
|
||||
Proin euismod,
|
||||
justo sed mollis dictum,
|
||||
eros urna ultricies augue,
|
||||
eu pharetra mi ex id ante.
|
||||
Duis convallis porttitor aliquam.
|
||||
Nunc vitae tincidunt ex.
|
||||
Suspendisse iaculis ligula ac diam consectetur lacinia.
|
||||
Donec vel velit dui.
|
||||
Etiam fringilla,
|
||||
dolor quis tempor vehicula,
|
||||
lacus turpis bibendum velit,
|
||||
et pellentesque elit odio a magna.
|
||||
Cras vulputate tortor non libero vehicula euismod.
|
||||
Aliquam tincidunt nisl eget enim cursus,
|
||||
viverra sagittis magna commodo.
|
||||
Cras rhoncus egestas leo nec blandit.
|
||||
Suspendisse potenti.
|
||||
Etiam ullamcorper leo vel lacus vestibulum,
|
||||
cursus semper eros efficitur.
|
||||
In hac habitasse platea dictumst.
|
||||
Phasellus scelerisque vehicula f
|
100
tests/fixtures/head/sequence
vendored
Normal file
100
tests/fixtures/head/sequence
vendored
Normal file
|
@ -0,0 +1,100 @@
|
|||
1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24
|
||||
25
|
||||
26
|
||||
27
|
||||
28
|
||||
29
|
||||
30
|
||||
31
|
||||
32
|
||||
33
|
||||
34
|
||||
35
|
||||
36
|
||||
37
|
||||
38
|
||||
39
|
||||
40
|
||||
41
|
||||
42
|
||||
43
|
||||
44
|
||||
45
|
||||
46
|
||||
47
|
||||
48
|
||||
49
|
||||
50
|
||||
51
|
||||
52
|
||||
53
|
||||
54
|
||||
55
|
||||
56
|
||||
57
|
||||
58
|
||||
59
|
||||
60
|
||||
61
|
||||
62
|
||||
63
|
||||
64
|
||||
65
|
||||
66
|
||||
67
|
||||
68
|
||||
69
|
||||
70
|
||||
71
|
||||
72
|
||||
73
|
||||
74
|
||||
75
|
||||
76
|
||||
77
|
||||
78
|
||||
79
|
||||
80
|
||||
81
|
||||
82
|
||||
83
|
||||
84
|
||||
85
|
||||
86
|
||||
87
|
||||
88
|
||||
89
|
||||
90
|
||||
91
|
||||
92
|
||||
93
|
||||
94
|
||||
95
|
||||
96
|
||||
97
|
||||
98
|
||||
99
|
||||
100
|
90
tests/fixtures/head/sequence.expected
vendored
Normal file
90
tests/fixtures/head/sequence.expected
vendored
Normal file
|
@ -0,0 +1,90 @@
|
|||
1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24
|
||||
25
|
||||
26
|
||||
27
|
||||
28
|
||||
29
|
||||
30
|
||||
31
|
||||
32
|
||||
33
|
||||
34
|
||||
35
|
||||
36
|
||||
37
|
||||
38
|
||||
39
|
||||
40
|
||||
41
|
||||
42
|
||||
43
|
||||
44
|
||||
45
|
||||
46
|
||||
47
|
||||
48
|
||||
49
|
||||
50
|
||||
51
|
||||
52
|
||||
53
|
||||
54
|
||||
55
|
||||
56
|
||||
57
|
||||
58
|
||||
59
|
||||
60
|
||||
61
|
||||
62
|
||||
63
|
||||
64
|
||||
65
|
||||
66
|
||||
67
|
||||
68
|
||||
69
|
||||
70
|
||||
71
|
||||
72
|
||||
73
|
||||
74
|
||||
75
|
||||
76
|
||||
77
|
||||
78
|
||||
79
|
||||
80
|
||||
81
|
||||
82
|
||||
83
|
||||
84
|
||||
85
|
||||
86
|
||||
87
|
||||
88
|
||||
89
|
||||
90
|
Loading…
Add table
Add a link
Reference in a new issue