2023-08-24 10:07:48 +00:00
|
|
|
// This file is part of the uutils coreutils package.
|
|
|
|
//
|
|
|
|
// For the full copyright and license information, please view the LICENSE
|
|
|
|
// file that was distributed with this source code.
|
2021-06-03 22:49:06 +00:00
|
|
|
|
|
|
|
// spell-checker:ignore (words) bogusfile emptyfile abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstu
|
2021-05-30 05:10:54 +00:00
|
|
|
|
2023-03-20 13:51:19 +00:00
|
|
|
use crate::common::util::TestScenario;
|
2015-11-16 05:25:01 +00:00
|
|
|
|
2021-05-29 12:32:35 +00:00
|
|
|
static INPUT: &str = "lorem_ipsum.txt";
|
2015-11-16 05:25:01 +00:00
|
|
|
|
2022-09-10 16:38:14 +00:00
|
|
|
#[test]
|
|
|
|
fn test_invalid_arg() {
|
|
|
|
new_ucmd!().arg("--definitely-invalid").fails().code_is(1);
|
|
|
|
}
|
|
|
|
|
2015-11-16 05:25:01 +00:00
|
|
|
#[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
|
|
|
|
|
|
|
#[test]
|
2020-08-09 16:51:04 +00:00
|
|
|
#[ignore]
|
2020-08-04 21:35:35 +00:00
|
|
|
fn test_spams_newline() {
|
2021-03-29 11:08:48 +00:00
|
|
|
//this test is does not mirror what GNU does
|
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]
|
2021-03-29 11:08:48 +00:00
|
|
|
fn test_byte_syntax() {
|
2020-08-04 21:35:35 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-1c"])
|
|
|
|
.pipe_in("abc")
|
2021-03-29 11:08:48 +00:00
|
|
|
.run()
|
|
|
|
.stdout_is("a");
|
2020-08-04 21:35:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2021-03-29 11:08:48 +00:00
|
|
|
fn test_line_syntax() {
|
2020-08-04 21:35:35 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-n", "2048m"])
|
|
|
|
.pipe_in("a\n")
|
2021-03-29 11:08:48 +00:00
|
|
|
.run()
|
|
|
|
.stdout_is("a\n");
|
2020-08-04 21:35:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2021-03-29 11:08:48 +00:00
|
|
|
fn test_zero_terminated_syntax() {
|
2020-08-04 21:35:35 +00:00
|
|
|
new_ucmd!()
|
2021-03-29 11:08:48 +00:00
|
|
|
.args(&["-z", "-n", "1"])
|
2020-08-04 21:35:35 +00:00
|
|
|
.pipe_in("x\0y")
|
2021-03-29 11:08:48 +00:00
|
|
|
.run()
|
|
|
|
.stdout_is("x\0");
|
2020-08-04 21:35:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2021-03-29 11:08:48 +00:00
|
|
|
fn test_zero_terminated_syntax_2() {
|
2020-08-04 21:35:35 +00:00
|
|
|
new_ucmd!()
|
2021-03-29 11:08:48 +00:00
|
|
|
.args(&["-z", "-n", "2"])
|
2020-08-04 21:35:35 +00:00
|
|
|
.pipe_in("x\0y")
|
2021-03-29 11:08:48 +00:00
|
|
|
.run()
|
|
|
|
.stdout_is("x\0y");
|
2020-08-04 21:35:35 +00:00
|
|
|
}
|
|
|
|
|
2021-05-12 03:48:06 +00:00
|
|
|
#[test]
|
|
|
|
fn test_zero_terminated_negative_lines() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-z", "-n", "-1"])
|
|
|
|
.pipe_in("x\0y\0z\0")
|
|
|
|
.run()
|
|
|
|
.stdout_is("x\0y\0");
|
|
|
|
}
|
|
|
|
|
2020-08-04 21:35:35 +00:00
|
|
|
#[test]
|
2021-03-29 11:08:48 +00:00
|
|
|
fn test_negative_byte_syntax() {
|
2020-08-04 21:35:35 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["--bytes=-2"])
|
|
|
|
.pipe_in("a\n")
|
2021-03-29 11:08:48 +00:00
|
|
|
.run()
|
|
|
|
.stdout_is("");
|
2020-08-04 21:35:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2021-03-29 11:08:48 +00:00
|
|
|
fn test_negative_zero_lines() {
|
2020-08-04 21:35:35 +00:00
|
|
|
new_ucmd!()
|
2022-01-30 03:15:23 +00:00
|
|
|
.arg("--lines=-0")
|
2020-08-04 21:35:35 +00:00
|
|
|
.pipe_in("a\nb\n")
|
|
|
|
.succeeds()
|
2021-03-29 11:08:48 +00:00
|
|
|
.stdout_is("a\nb\n");
|
2022-01-30 03:15:23 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.arg("--lines=-0")
|
|
|
|
.pipe_in("a\nb")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("a\nb");
|
2021-03-29 11:08:48 +00:00
|
|
|
}
|
2022-01-30 03:15:23 +00:00
|
|
|
|
2021-03-29 11:08:48 +00:00
|
|
|
#[test]
|
|
|
|
fn test_negative_zero_bytes() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["--bytes=-0"])
|
|
|
|
.pipe_in("qwerty")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("qwerty");
|
2020-08-04 21:35:35 +00:00
|
|
|
}
|
2021-03-21 20:27:44 +00:00
|
|
|
#[test]
|
|
|
|
fn test_no_such_file_or_directory() {
|
2021-04-22 20:37:44 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.arg("no_such_file.toml")
|
|
|
|
.fails()
|
|
|
|
.stderr_contains("cannot open 'no_such_file.toml' for reading: No such file or directory");
|
2021-03-21 20:27:44 +00:00
|
|
|
}
|
2021-03-29 11:08:48 +00:00
|
|
|
|
2023-05-30 18:26:39 +00:00
|
|
|
#[test]
|
|
|
|
fn test_lines_leading_zeros() {
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("--lines=010")
|
|
|
|
.pipe_in("\n\n\n\n\n\n\n\n\n\n\n\n")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("\n\n\n\n\n\n\n\n\n\n");
|
|
|
|
}
|
|
|
|
|
2021-05-17 01:21:20 +00:00
|
|
|
/// Test that each non-existent files gets its own error message printed.
|
|
|
|
#[test]
|
|
|
|
fn test_multiple_nonexistent_files() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["bogusfile1", "bogusfile2"])
|
|
|
|
.fails()
|
|
|
|
.stdout_does_not_contain("==> bogusfile1 <==")
|
|
|
|
.stderr_contains("cannot open 'bogusfile1' for reading: No such file or directory")
|
|
|
|
.stdout_does_not_contain("==> bogusfile2 <==")
|
|
|
|
.stderr_contains("cannot open 'bogusfile2' for reading: No such file or directory");
|
|
|
|
}
|
|
|
|
|
2021-03-29 11:08:48 +00:00
|
|
|
// 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"])
|
2022-02-11 13:02:06 +00:00
|
|
|
.pipe_in("1\x002\x003\x004\x005\x006")
|
2021-03-29 11:08:48 +00:00
|
|
|
.succeeds()
|
2022-02-11 13:02:06 +00:00
|
|
|
.stdout_is("==> standard input <==\n1\x002\x003\x004\x005\0");
|
2021-03-29 11:08:48 +00:00
|
|
|
}
|
2021-05-16 15:30:10 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_multiple_files() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["emptyfile.txt", "emptyfile.txt"])
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("==> emptyfile.txt <==\n\n==> emptyfile.txt <==\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_multiple_files_with_stdin() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["emptyfile.txt", "-", "emptyfile.txt"])
|
|
|
|
.pipe_in("hello\n")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is(
|
|
|
|
"==> emptyfile.txt <==
|
|
|
|
|
|
|
|
==> standard input <==
|
|
|
|
hello
|
|
|
|
|
|
|
|
==> emptyfile.txt <==
|
|
|
|
",
|
|
|
|
);
|
|
|
|
}
|
2021-06-03 21:38:31 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_bad_utf8() {
|
2021-06-03 22:19:44 +00:00
|
|
|
let bytes: &[u8] = b"\xfc\x80\x80\x80\x80\xaf";
|
2021-06-03 21:38:31 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-c", "6"])
|
2021-06-03 22:19:44 +00:00
|
|
|
.pipe_in(bytes)
|
2021-06-03 21:38:31 +00:00
|
|
|
.succeeds()
|
|
|
|
.stdout_is_bytes(bytes);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_bad_utf8_lines() {
|
2021-07-04 11:01:31 +00:00
|
|
|
let input: &[u8] =
|
|
|
|
b"\xfc\x80\x80\x80\x80\xaf\nb\xfc\x80\x80\x80\x80\xaf\nb\xfc\x80\x80\x80\x80\xaf";
|
2021-06-03 21:38:31 +00:00
|
|
|
let output = b"\xfc\x80\x80\x80\x80\xaf\nb\xfc\x80\x80\x80\x80\xaf\n";
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-n", "2"])
|
2021-06-03 22:19:44 +00:00
|
|
|
.pipe_in(input)
|
2021-06-03 21:38:31 +00:00
|
|
|
.succeeds()
|
|
|
|
.stdout_is_bytes(output);
|
2021-06-03 21:39:47 +00:00
|
|
|
}
|
2021-07-04 09:57:59 +00:00
|
|
|
|
2021-06-01 07:30:43 +00:00
|
|
|
#[test]
|
|
|
|
fn test_head_invalid_num() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-c", "1024R", "emptyfile.txt"])
|
|
|
|
.fails()
|
2023-10-05 01:26:29 +00:00
|
|
|
.stderr_is(
|
|
|
|
"head: invalid number of bytes: '1024R': Value too large for defined data type\n",
|
|
|
|
);
|
2021-06-01 07:30:43 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-n", "1024R", "emptyfile.txt"])
|
|
|
|
.fails()
|
2023-10-05 01:26:29 +00:00
|
|
|
.stderr_is(
|
|
|
|
"head: invalid number of lines: '1024R': Value too large for defined data type\n",
|
|
|
|
);
|
2021-06-01 07:30:43 +00:00
|
|
|
#[cfg(not(target_pointer_width = "128"))]
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-c", "1Y", "emptyfile.txt"])
|
|
|
|
.fails()
|
2023-01-05 20:09:15 +00:00
|
|
|
.stderr_is("head: invalid number of bytes: '1Y': Value too large for defined data type\n");
|
2021-06-01 07:30:43 +00:00
|
|
|
#[cfg(not(target_pointer_width = "128"))]
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-n", "1Y", "emptyfile.txt"])
|
|
|
|
.fails()
|
2023-01-05 20:09:15 +00:00
|
|
|
.stderr_is("head: invalid number of lines: '1Y': Value too large for defined data type\n");
|
2021-06-03 18:37:29 +00:00
|
|
|
#[cfg(target_pointer_width = "32")]
|
|
|
|
{
|
|
|
|
let sizes = ["1000G", "10T"];
|
|
|
|
for size in &sizes {
|
2022-02-22 10:09:22 +00:00
|
|
|
new_ucmd!().args(&["-c", size]).succeeds();
|
2021-06-03 18:37:29 +00:00
|
|
|
}
|
|
|
|
}
|
2022-02-22 19:58:41 +00:00
|
|
|
#[cfg(target_pointer_width = "32")]
|
|
|
|
{
|
|
|
|
let sizes = ["-1000G", "-10T"];
|
|
|
|
for size in &sizes {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-c", size])
|
|
|
|
.fails()
|
2024-01-04 23:25:59 +00:00
|
|
|
.stderr_is("head: out of range integral type conversion attempted: number of -bytes or -lines is too large\n");
|
2022-02-22 19:58:41 +00:00
|
|
|
}
|
|
|
|
}
|
2022-02-03 05:22:28 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-c", "-³"])
|
|
|
|
.fails()
|
2023-01-05 20:09:15 +00:00
|
|
|
.stderr_is("head: invalid number of bytes: '³'\n");
|
2021-06-01 07:30:43 +00:00
|
|
|
}
|
2021-06-01 10:17:11 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_head_num_with_undocumented_sign_bytes() {
|
|
|
|
// tail: '-' is not documented (8.32 man pages)
|
|
|
|
// head: '+' is not documented (8.32 man pages)
|
|
|
|
const ALPHABET: &str = "abcdefghijklmnopqrstuvwxyz";
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-c", "5"])
|
|
|
|
.pipe_in(ALPHABET)
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("abcde");
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-c", "-5"])
|
|
|
|
.pipe_in(ALPHABET)
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("abcdefghijklmnopqrstu");
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-c", "+5"])
|
|
|
|
.pipe_in(ALPHABET)
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("abcde");
|
|
|
|
}
|
2022-03-31 15:16:55 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_presume_input_pipe_default() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["---presume-input-pipe"])
|
|
|
|
.pipe_in_fixture(INPUT)
|
|
|
|
.run()
|
|
|
|
.stdout_is_fixture("lorem_ipsum_default.expected");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_presume_input_pipe_5_chars() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-c", "5", "---presume-input-pipe"])
|
|
|
|
.pipe_in_fixture(INPUT)
|
|
|
|
.run()
|
|
|
|
.stdout_is_fixture("lorem_ipsum_5_chars.expected");
|
|
|
|
}
|
2024-01-04 23:25:59 +00:00
|
|
|
|
|
|
|
#[cfg(all(
|
|
|
|
not(target_os = "windows"),
|
|
|
|
not(target_os = "macos"),
|
2024-01-08 16:29:34 +00:00
|
|
|
not(target_os = "android"),
|
2024-01-04 23:25:59 +00:00
|
|
|
not(target_os = "freebsd")
|
|
|
|
))]
|
|
|
|
#[test]
|
|
|
|
fn test_read_backwards_bytes_proc_fs_version() {
|
|
|
|
let ts = TestScenario::new(util_name!());
|
|
|
|
|
|
|
|
let args = ["-c", "-1", "/proc/version"];
|
|
|
|
let result = ts.ucmd().args(&args).succeeds();
|
2024-01-14 14:23:24 +00:00
|
|
|
assert!(!result.stdout().is_empty());
|
2024-01-04 23:25:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(all(
|
|
|
|
not(target_os = "windows"),
|
|
|
|
not(target_os = "macos"),
|
2024-01-08 16:29:34 +00:00
|
|
|
not(target_os = "android"),
|
2024-01-04 23:25:59 +00:00
|
|
|
not(target_os = "freebsd")
|
|
|
|
))]
|
|
|
|
#[test]
|
|
|
|
fn test_read_backwards_bytes_proc_fs_modules() {
|
|
|
|
let ts = TestScenario::new(util_name!());
|
|
|
|
|
|
|
|
let args = ["-c", "-1", "/proc/modules"];
|
|
|
|
let result = ts.ucmd().args(&args).succeeds();
|
2024-01-14 14:23:24 +00:00
|
|
|
assert!(!result.stdout().is_empty());
|
2024-01-04 23:25:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(all(
|
|
|
|
not(target_os = "windows"),
|
|
|
|
not(target_os = "macos"),
|
2024-01-08 16:29:34 +00:00
|
|
|
not(target_os = "android"),
|
2024-01-04 23:25:59 +00:00
|
|
|
not(target_os = "freebsd")
|
|
|
|
))]
|
|
|
|
#[test]
|
|
|
|
fn test_read_backwards_lines_proc_fs_modules() {
|
|
|
|
let ts = TestScenario::new(util_name!());
|
|
|
|
|
|
|
|
let args = ["--lines", "-1", "/proc/modules"];
|
|
|
|
let result = ts.ucmd().args(&args).succeeds();
|
2024-01-14 14:23:24 +00:00
|
|
|
assert!(!result.stdout().is_empty());
|
2024-01-04 23:25:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(all(
|
|
|
|
not(target_os = "windows"),
|
|
|
|
not(target_os = "macos"),
|
2024-01-08 16:29:34 +00:00
|
|
|
not(target_os = "android"),
|
2024-01-04 23:25:59 +00:00
|
|
|
not(target_os = "freebsd")
|
|
|
|
))]
|
|
|
|
#[test]
|
|
|
|
fn test_read_backwards_bytes_sys_kernel_profiling() {
|
|
|
|
let ts = TestScenario::new(util_name!());
|
|
|
|
|
|
|
|
let args = ["-c", "-1", "/sys/kernel/profiling"];
|
|
|
|
let result = ts.ucmd().args(&args).succeeds();
|
|
|
|
let stdout_str = result.stdout_str();
|
|
|
|
assert_eq!(stdout_str.len(), 1);
|
|
|
|
assert!(stdout_str == "0" || stdout_str == "1");
|
|
|
|
}
|