2020-05-25 17:05:26 +00:00
|
|
|
use crate::common::util::*;
|
2015-11-16 05:25:01 +00:00
|
|
|
|
|
|
|
static INPUT: &'static str = "lorem_ipsum.txt";
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_stdin_default() {
|
2016-08-23 11:52:43 +00:00
|
|
|
new_ucmd!()
|
2016-07-29 21:26:32 +00:00
|
|
|
.pipe_in_fixture(INPUT)
|
2020-04-13 18:36:03 +00:00
|
|
|
.run()
|
|
|
|
.stdout_is_fixture("lorem_ipsum_default.expected");
|
2015-11-16 05:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_stdin_1_line_obsolete() {
|
2016-08-23 11:52:43 +00:00
|
|
|
new_ucmd!()
|
2016-07-29 21:26:32 +00:00
|
|
|
.args(&["-1"])
|
|
|
|
.pipe_in_fixture(INPUT)
|
2020-04-13 18:36:03 +00:00
|
|
|
.run()
|
|
|
|
.stdout_is_fixture("lorem_ipsum_1_line.expected");
|
2015-11-16 05:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_stdin_1_line() {
|
2016-08-23 11:52:43 +00:00
|
|
|
new_ucmd!()
|
2016-07-29 21:26:32 +00:00
|
|
|
.args(&["-n", "1"])
|
|
|
|
.pipe_in_fixture(INPUT)
|
2020-04-13 18:36:03 +00:00
|
|
|
.run()
|
|
|
|
.stdout_is_fixture("lorem_ipsum_1_line.expected");
|
2020-05-10 19:31:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_stdin_negative_23_line() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-n", "-23"])
|
|
|
|
.pipe_in_fixture(INPUT)
|
|
|
|
.run()
|
|
|
|
.stdout_is_fixture("lorem_ipsum_1_line.expected");
|
2015-11-16 05:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_stdin_5_chars() {
|
2016-08-23 11:52:43 +00:00
|
|
|
new_ucmd!()
|
2016-07-29 21:26:32 +00:00
|
|
|
.args(&["-c", "5"])
|
|
|
|
.pipe_in_fixture(INPUT)
|
2020-04-13 18:36:03 +00:00
|
|
|
.run()
|
|
|
|
.stdout_is_fixture("lorem_ipsum_5_chars.expected");
|
2015-11-16 05:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_single_default() {
|
2016-08-23 11:52:43 +00:00
|
|
|
new_ucmd!()
|
2016-07-29 21:26:32 +00:00
|
|
|
.arg(INPUT)
|
2020-04-13 18:36:03 +00:00
|
|
|
.run()
|
|
|
|
.stdout_is_fixture("lorem_ipsum_default.expected");
|
2015-11-16 05:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_single_1_line_obsolete() {
|
2016-08-23 11:52:43 +00:00
|
|
|
new_ucmd!()
|
2016-07-29 21:26:32 +00:00
|
|
|
.args(&["-1", INPUT])
|
2020-04-13 18:36:03 +00:00
|
|
|
.run()
|
|
|
|
.stdout_is_fixture("lorem_ipsum_1_line.expected");
|
2015-11-16 05:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_single_1_line() {
|
2016-08-23 11:52:43 +00:00
|
|
|
new_ucmd!()
|
2016-07-29 21:26:32 +00:00
|
|
|
.args(&["-n", "1", INPUT])
|
2020-04-13 18:36:03 +00:00
|
|
|
.run()
|
|
|
|
.stdout_is_fixture("lorem_ipsum_1_line.expected");
|
2015-11-16 05:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_single_5_chars() {
|
2016-08-23 11:52:43 +00:00
|
|
|
new_ucmd!()
|
2016-07-29 21:26:32 +00:00
|
|
|
.args(&["-c", "5", INPUT])
|
2020-04-13 18:36:03 +00:00
|
|
|
.run()
|
|
|
|
.stdout_is_fixture("lorem_ipsum_5_chars.expected");
|
2015-11-16 05:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_verbose() {
|
2016-08-23 11:52:43 +00:00
|
|
|
new_ucmd!()
|
2016-07-29 21:26:32 +00:00
|
|
|
.args(&["-v", INPUT])
|
2020-04-13 18:36:03 +00:00
|
|
|
.run()
|
|
|
|
.stdout_is_fixture("lorem_ipsum_verbose.expected");
|
2015-11-16 05:25:01 +00:00
|
|
|
}
|
2020-08-04 21:35:35 +00:00
|
|
|
|
2021-03-15 15:56:11 +00:00
|
|
|
#[test]
|
|
|
|
fn test_zero_terminated() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-z", "zero_terminated.txt"])
|
|
|
|
.run()
|
|
|
|
.stdout_is_fixture("zero_terminated.expected");
|
|
|
|
}
|
|
|
|
|
2020-08-04 21:35:35 +00:00
|
|
|
#[test]
|
2020-08-09 16:51:04 +00:00
|
|
|
#[ignore]
|
2020-08-04 21:35:35 +00:00
|
|
|
fn test_spams_newline() {
|
2020-08-09 04:04:29 +00:00
|
|
|
new_ucmd!().pipe_in("a").succeeds().stdout_is("a\n");
|
2020-08-04 21:35:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2020-08-09 16:51:04 +00:00
|
|
|
#[ignore]
|
2020-08-04 21:35:35 +00:00
|
|
|
fn test_unsupported_byte_syntax() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-1c"])
|
|
|
|
.pipe_in("abc")
|
|
|
|
.fails()
|
|
|
|
//GNU head returns "a"
|
|
|
|
.stdout_is("")
|
2020-08-09 04:04:29 +00:00
|
|
|
.stderr_is("head: error: Unrecognized option: \'1\'");
|
2020-08-04 21:35:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2020-08-09 16:51:04 +00:00
|
|
|
#[ignore]
|
2020-08-04 21:35:35 +00:00
|
|
|
fn test_unsupported_line_syntax() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-n", "2048m"])
|
|
|
|
.pipe_in("a\n")
|
|
|
|
.fails()
|
|
|
|
//.stdout_is("a\n"); What GNU head returns.
|
|
|
|
.stdout_is("")
|
2020-08-09 04:04:29 +00:00
|
|
|
.stderr_is("head: error: invalid line count \'2048m\': invalid digit found in string");
|
2020-08-04 21:35:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2020-08-09 16:51:04 +00:00
|
|
|
#[ignore]
|
2020-08-04 21:35:35 +00:00
|
|
|
fn test_unsupported_zero_terminated_syntax() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-z -n 1"])
|
|
|
|
.pipe_in("x\0y")
|
|
|
|
.fails()
|
|
|
|
//GNU Head returns "x\0"
|
2020-08-09 04:04:29 +00:00
|
|
|
.stderr_is("head: error: Unrecognized option: \'z\'");
|
2020-08-04 21:35:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2020-08-09 16:51:04 +00:00
|
|
|
#[ignore]
|
2020-08-04 21:35:35 +00:00
|
|
|
fn test_unsupported_zero_terminated_syntax_2() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-z -n 2"])
|
|
|
|
.pipe_in("x\0y")
|
|
|
|
.fails()
|
|
|
|
//GNU Head returns "x\0y"
|
2020-08-09 04:04:29 +00:00
|
|
|
.stderr_is("head: error: Unrecognized option: \'z\'");
|
2020-08-04 21:35:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2020-08-09 16:51:04 +00:00
|
|
|
#[ignore]
|
2020-08-04 21:35:35 +00:00
|
|
|
fn test_unsupported_negative_byte_syntax() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["--bytes=-2"])
|
|
|
|
.pipe_in("a\n")
|
|
|
|
.fails()
|
|
|
|
//GNU Head returns ""
|
2020-08-09 04:04:29 +00:00
|
|
|
.stderr_is("head: error: invalid byte count \'-2\': invalid digit found in string");
|
2020-08-04 21:35:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2020-08-09 16:51:04 +00:00
|
|
|
#[ignore]
|
2020-08-04 21:35:35 +00:00
|
|
|
fn test_bug_in_negative_zero_lines() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["--lines=-0"])
|
|
|
|
.pipe_in("a\nb\n")
|
|
|
|
.succeeds()
|
|
|
|
//GNU Head returns "a\nb\n"
|
2020-08-09 04:04:29 +00:00
|
|
|
.stdout_is("");
|
2020-08-04 21:35:35 +00:00
|
|
|
}
|