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

Merge pull request #2217 from jfinkels/head-multiple-files

head: print headings when reading multiple files
This commit is contained in:
Sylvestre Ledru 2021-05-16 18:28:31 +02:00 committed by GitHub
commit 9e2c82d8e7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 1 deletions

View file

@ -405,7 +405,7 @@ fn uu_head(options: &HeadOptions) {
for fname in &options.files {
let res = match fname.as_str() {
"-" => {
if options.verbose {
if (options.files.len() > 1 && !options.quiet) || options.verbose {
if !first {
println!();
}
@ -459,6 +459,9 @@ fn uu_head(options: &HeadOptions) {
},
};
if (options.files.len() > 1 && !options.quiet) || options.verbose {
if !first {
println!();
}
println!("==> {} <==", name)
}
head_file(&mut file, options)

View file

@ -196,3 +196,28 @@ fn test_obsolete_extras() {
.succeeds()
.stdout_is("==> standard input <==\n1\02\03\04\05\0");
}
#[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 <==
",
);
}

0
tests/fixtures/head/emptyfile.txt vendored Normal file
View file