1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

head: head_backwards for non-seekable files like /proc/* or fifos (named pipes) (#5732)

* implement head_backwards for non-seekable files like /proc/* or pipes

Signed-off-by: Ulrich Hornung <hornunguli@gmx.de>
This commit is contained in:
cre4ture 2024-01-05 00:25:59 +01:00 committed by GitHub
parent be816027ae
commit 9b3cc5437c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 170 additions and 55 deletions

View file

@ -330,7 +330,7 @@ fn test_head_invalid_num() {
new_ucmd!()
.args(&["-c", size])
.fails()
.stderr_is("head: out of range integral type conversion attempted: number of bytes is too large\n");
.stderr_is("head: out of range integral type conversion attempted: number of -bytes or -lines is too large\n");
}
}
new_ucmd!()
@ -378,3 +378,61 @@ fn test_presume_input_pipe_5_chars() {
.run()
.stdout_is_fixture("lorem_ipsum_5_chars.expected");
}
#[cfg(all(
not(target_os = "windows"),
not(target_os = "macos"),
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();
assert!(result.stdout().len() > 0);
}
#[cfg(all(
not(target_os = "windows"),
not(target_os = "macos"),
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();
assert!(result.stdout().len() > 0);
}
#[cfg(all(
not(target_os = "windows"),
not(target_os = "macos"),
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();
assert!(result.stdout().len() > 0);
}
#[cfg(all(
not(target_os = "windows"),
not(target_os = "macos"),
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");
}