mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
head: print headings when reading multiple files
Fix a bug in which `head` failed to print headings for `stdin` inputs when reading from multiple files, and fix another bug in which `head` failed to print a blank line between the contents of a file and the heading for the next file when reading multiple files. The output now matches that of GNU `head`.
This commit is contained in:
parent
7d2b6409e2
commit
659bf58a4c
3 changed files with 29 additions and 1 deletions
|
@ -405,7 +405,7 @@ fn uu_head(options: &HeadOptions) {
|
||||||
for fname in &options.files {
|
for fname in &options.files {
|
||||||
let res = match fname.as_str() {
|
let res = match fname.as_str() {
|
||||||
"-" => {
|
"-" => {
|
||||||
if options.verbose {
|
if (options.files.len() > 1 && !options.quiet) || options.verbose {
|
||||||
if !first {
|
if !first {
|
||||||
println!();
|
println!();
|
||||||
}
|
}
|
||||||
|
@ -459,6 +459,9 @@ fn uu_head(options: &HeadOptions) {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
if (options.files.len() > 1 && !options.quiet) || options.verbose {
|
if (options.files.len() > 1 && !options.quiet) || options.verbose {
|
||||||
|
if !first {
|
||||||
|
println!();
|
||||||
|
}
|
||||||
println!("==> {} <==", name)
|
println!("==> {} <==", name)
|
||||||
}
|
}
|
||||||
head_file(&mut file, options)
|
head_file(&mut file, options)
|
||||||
|
|
|
@ -196,3 +196,28 @@ fn test_obsolete_extras() {
|
||||||
.succeeds()
|
.succeeds()
|
||||||
.stdout_is("==> standard input <==\n1\02\03\04\05\0");
|
.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
0
tests/fixtures/head/emptyfile.txt
vendored
Normal file
Loading…
Add table
Add a link
Reference in a new issue