diff options
author | Jim Meyering <meyering@redhat.com> | 2012-06-05 12:24:49 +0200 |
---|---|---|
committer | Jim Meyering <meyering@redhat.com> | 2012-06-05 19:55:26 +0200 |
commit | 295ee521bc1a4f473ee8b7b5a4be32c5b5c7386f (patch) | |
tree | b118600100717eb2b4d653d02f397acf96bc7971 /tests | |
parent | 5fdd5c6310098c5ce3cbc608450d5c4104f18c2f (diff) | |
download | coreutils-295ee521bc1a4f473ee8b7b5a4be32c5b5c7386f.tar.xz |
head: with --lines=-N (-n-N) reset file pointer on seekable input
* src/head.c (elide_tail_lines_seekable): Reset file pointer
after printing up to an end-relative line-counted offset.
Anoop Sharma reported the problem and suggested the fix.
* tests/misc/head-pos: Add coverage via a very similar, existing test.
Also add coverage for a previously untested block of code.
* tests/misc/head-elide-tail ($READ_BUFSIZE): Update to 8192, to
match the value of BUFSIZ I see today on Fedora 17/x86_64 (unrelated
to this fix).
* NEWS (Bug fixes): Mention it.
Improved-by: Pádraig Brady
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/misc/head-elide-tail | 2 | ||||
-rwxr-xr-x | tests/misc/head-pos | 26 |
2 files changed, 20 insertions, 8 deletions
diff --git a/tests/misc/head-elide-tail b/tests/misc/head-elide-tail index de4896bc5..85f509d26 100755 --- a/tests/misc/head-elide-tail +++ b/tests/misc/head-elide-tail @@ -26,7 +26,7 @@ $ENV{PROG} = 'head'; @ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; # This should match the definition in head.c. -my $READ_BUFSIZE = 4096; +my $READ_BUFSIZE = 8192; my @Tests = ( diff --git a/tests/misc/head-pos b/tests/misc/head-pos index 3d96261f9..fa3284e90 100755 --- a/tests/misc/head-pos +++ b/tests/misc/head-pos @@ -21,12 +21,24 @@ print_ver_ head (echo a; echo b) > in || framework_failure_ - -(head -n 1 >/dev/null; cat) < in > out || fail=1 -cat <<EOF > exp -b -EOF - -compare exp out || fail=1 +echo b > exp || framework_failure_ + +for i in -1 1; do + (head -n $i >/dev/null; cat) < in > out || fail=1 + compare exp out || fail=1 +done + +# Exercise the (start_pos < pos) block in elide_tail_lines_seekable. +# So far, this is the only test to do that. +# Do that by creating a file larger than BUFSIZ (I've seen 128K) and +# elide a suffix of it (by line count) that is also larger than BUFSIZ. +# 50000 lines times 6 bytes per line gives us enough leeway even on a +# system with a BUFSIZ of 256K. +n_lines=50000 +seq 70000 > in2 || framework_failure_ +echo $n_lines > exp-n || framework_failure_ + +(head -n-$n_lines>/dev/null; wc -l) < in2 > n +compare exp-n n || fail=1 Exit $fail |