diff options
Diffstat (limited to 'tests/misc')
164 files changed, 1153 insertions, 380 deletions
diff --git a/tests/misc/arch.sh b/tests/misc/arch.sh index db2b784f..95369067 100755 --- a/tests/misc/arch.sh +++ b/tests/misc/arch.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure that arch output is equal to uname -m -# Copyright (C) 2007-2013 Free Software Foundation, Inc. +# Copyright (C) 2007-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/base64.pl b/tests/misc/base64.pl index 5d1d2621..54e2cc21 100755 --- a/tests/misc/base64.pl +++ b/tests/misc/base64.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Exercise base64. -# Copyright (C) 2006-2013 Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/basename.pl b/tests/misc/basename.pl index b84412bb..3aace6f8 100755 --- a/tests/misc/basename.pl +++ b/tests/misc/basename.pl @@ -1,6 +1,6 @@ #!/usr/bin/perl # Test basename. -# Copyright (C) 2006-2013 Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/cat-buf.sh b/tests/misc/cat-buf.sh index 17fd936f..592b5a1d 100755 --- a/tests/misc/cat-buf.sh +++ b/tests/misc/cat-buf.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure that cat outputs processed data immediately. -# Copyright (C) 2009-2013 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/cat-proc.sh b/tests/misc/cat-proc.sh index 77f548e4..7b826ef3 100755 --- a/tests/misc/cat-proc.sh +++ b/tests/misc/cat-proc.sh @@ -2,7 +2,7 @@ # Ensure that cat -E produces same output as cat, module '$'s, # even when applied to a file in /proc. -# Copyright (C) 2006-2013 Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/chcon-fail.sh b/tests/misc/chcon-fail.sh index c9b651b7..77b91d3b 100755 --- a/tests/misc/chcon-fail.sh +++ b/tests/misc/chcon-fail.sh @@ -2,7 +2,7 @@ # Ensure that chcon fails when it should. # These tests don't use any actual SE Linux syscalls. -# Copyright (C) 2007-2013 Free Software Foundation, Inc. +# Copyright (C) 2007-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/chcon.sh b/tests/misc/chcon.sh index aace5389..ec573967 100755 --- a/tests/misc/chcon.sh +++ b/tests/misc/chcon.sh @@ -1,7 +1,7 @@ #!/bin/sh # exercise chcon -# Copyright (C) 2007-2013 Free Software Foundation, Inc. +# Copyright (C) 2007-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/chroot-credentials.sh b/tests/misc/chroot-credentials.sh index 8eb658d9..b06e8b7f 100755 --- a/tests/misc/chroot-credentials.sh +++ b/tests/misc/chroot-credentials.sh @@ -1,7 +1,7 @@ #!/bin/sh # Verify that the credentials are changed correctly. -# Copyright (C) 2009-2013 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -22,31 +22,96 @@ print_ver_ chroot require_root_ +grep '^#define HAVE_SETGROUPS 1' "$CONFIG_HEADER" >/dev/null \ + && HAVE_SETGROUPS=1 + +root=$(id -nu 0) || skip_ "Couldn't look up root username" + +# verify numeric IDs looked up similarly to names +NON_ROOT_UID=$(id -u $NON_ROOT_USERNAME) +NON_ROOT_GROUP=$NON_ROOT_GID # Used where we want name lookups to occur + +# "uid:" is supported (unlike chown etc.) since we treat it like "uid" +chroot --userspec=$NON_ROOT_UID: / true || fail=1 + +# verify that invalid groups are diagnosed +for g in ' ' ',' '0trail'; do + test "$(chroot --groups="$g" / id -G)" && fail=1 +done # Verify that root credentials are kept. -test $(chroot / whoami) = root || fail=1 +test $(chroot / whoami) = "$root" || fail=1 test "$(groups)" = "$(chroot / groups)" || fail=1 # Verify that credentials are changed correctly. whoami_after_chroot=$( chroot --userspec=$NON_ROOT_USERNAME:$NON_ROOT_GROUP / whoami ) -test "$whoami_after_chroot" != root || fail=1 +test "$whoami_after_chroot" != "$root" || fail=1 + +# Verify that when specifying only a group we don't change the +# list of supplemental groups +test "$(chroot --userspec=:$NON_ROOT_GROUP / id -G)" = \ + "$NON_ROOT_GID $(id -G)" || fail=1 + +if ! test "$HAVE_SETGROUPS"; then + Exit $fail +fi + # Verify that there are no additional groups. id_G_after_chroot=$( chroot --userspec=$NON_ROOT_USERNAME:$NON_ROOT_GROUP \ --groups=$NON_ROOT_GROUP / id -G ) -test "$id_G_after_chroot" = $NON_ROOT_GROUP || fail=1 +test "$id_G_after_chroot" = $NON_ROOT_GID || fail=1 + +# Verify that when specifying only the user name we get all their groups +test "$(chroot --userspec=$NON_ROOT_USERNAME / id -G)" = \ + "$(id -G $NON_ROOT_USERNAME)" || fail=1 -# Verify that when specifying only the user name we get the current -# primary group ID. -test "$(chroot --userspec=$NON_ROOT_USERNAME / id -g)" = "$(id -g)" \ - || fail=1 +# Ditto with trailing : on the user name. +test "$(chroot --userspec=$NON_ROOT_USERNAME: / id -G)" = \ + "$(id -G $NON_ROOT_USERNAME)" || fail=1 + +# Verify that when specifying only the user and clearing supplemental groups +# that we only get the primary group +test "$(chroot --userspec=$NON_ROOT_USERNAME --groups='' / id -G)" = \ + $NON_ROOT_GID || fail=1 + +# Verify that when specifying only the UID we get all their groups +test "$(chroot --userspec=$NON_ROOT_UID / id -G)" = \ + "$(id -G $NON_ROOT_USERNAME)" || fail=1 + +# Verify that when specifying only the user and clearing supplemental groups +# that we only get the primary group. Note this variant with prepended '+' +# results in no lookups in the name database which could be useful depending +# on your chroot setup. +test "$(chroot --userspec=+$NON_ROOT_UID:+$NON_ROOT_GID --groups='' / id -G)" =\ + $NON_ROOT_GID || fail=1 # Verify that when specifying only a group we get the current user ID test "$(chroot --userspec=:$NON_ROOT_GROUP / id -u)" = "$(id -u)" \ - || fail=1 + || fail=1 + +# verify that arbitrary numeric IDs are supported +test "$(chroot --userspec=1234:+5678 --groups=' +8765,4321' / id -G)" \ + || fail=1 + +# demonstrate that extraneous commas are supported +test "$(chroot --userspec=1234:+5678 --groups=',8765,,4321,' / id -G)" \ + || fail=1 + +# demonstrate that --groups is not cumulative +test "$(chroot --groups='invalid ignored' --groups='' / id -G)" \ + || fail=1 + +if ! id -u +12342; then + # Ensure supplemental groups cleared from some arbitrary unknown ID + test "$(chroot --userspec=+12342:+5678 / id -G)" = '5678' || fail=1 + + # Ensure we fail when we don't know what groups to set for an unknown ID + chroot --userspec=+12342 / true && fail=1 +fi Exit $fail diff --git a/tests/misc/chroot-fail.sh b/tests/misc/chroot-fail.sh index 86095f3c..a84826fd 100755 --- a/tests/misc/chroot-fail.sh +++ b/tests/misc/chroot-fail.sh @@ -1,7 +1,7 @@ #!/bin/sh # Verify that internal failure in chroot gives exact status. -# Copyright (C) 2009-2013 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -20,6 +20,7 @@ . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src print_ver_ chroot +require_built_ chroot # These tests verify exact status of internal failure; since none of # them actually run a command, we don't need root privileges @@ -28,16 +29,20 @@ test $? = 125 || fail=1 chroot --- / true # unknown option test $? = 125 || fail=1 -# chroot("/") succeeds for non-root users on some systems, but not all. -if chroot / true ; then - chroot / sh -c 'exit 2' # exit status propagation - test $? = 2 || fail=1 - chroot / . # invalid command - test $? = 126 || fail=1 - chroot / no_such # no such command - test $? = 127 || fail=1 -else - test $? = 125 || fail=1 -fi +# Note chroot("/") succeeds for non-root users on some systems, but not all, +# however we avoid the chroot() with "/" to have common behvavior. +chroot / sh -c 'exit 2' # exit status propagation +test $? = 2 || fail=1 +chroot / . # invalid command +test $? = 126 || fail=1 +chroot / no_such # no such command +test $? = 127 || fail=1 + +# Ensure we don't chdir("/") when not changing root +# to allow only changing user ids for a command. +for dir in '/' '/.' '/../'; do + curdir=$(chroot "$dir" env pwd) || fail=1 + test "$curdir" = '/' && fail=1 +done Exit $fail diff --git a/tests/misc/close-stdout.sh b/tests/misc/close-stdout.sh index 8ea08487..4da696c4 100755 --- a/tests/misc/close-stdout.sh +++ b/tests/misc/close-stdout.sh @@ -2,7 +2,7 @@ # Ensure that several programs work fine, even with stdout initially closed. # This is effectively a test of closeout.c's close_stdout function. -# Copyright (C) 2004-2013 Free Software Foundation, Inc. +# Copyright (C) 2004-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/comm.pl b/tests/misc/comm.pl index 62711bda..c96939b1 100755 --- a/tests/misc/comm.pl +++ b/tests/misc/comm.pl @@ -2,7 +2,7 @@ # -*- perl -*- # Test comm -# Copyright (C) 2008-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/id-setgid.sh b/tests/misc/coreutils.sh index f29eec07..a22bc9f6 100755 --- a/tests/misc/id-setgid.sh +++ b/tests/misc/coreutils.sh @@ -1,7 +1,7 @@ #!/bin/sh -# Verify that id -G prints the right group when run set-GID. +# Verify behavior of separate coreutils multicall binary -# Copyright (C) 2012-2013 Free Software Foundation, Inc. +# Copyright (C) 2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -16,19 +16,21 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. -. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src -print_ver_ id -require_root_ - -g=$(id -u $NON_ROOT_USERNAME) || framework_failure_ -# Construct a different group number. -gp1=$(expr $g + 1) +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ coreutils -echo $gp1 > exp || framework_failure_ +test -s "$abs_top_builddir/src/coreutils.h" \ + || skip_ "multicall binary is disabled" -setuidgid -g $gp1 $NON_ROOT_USERNAME env PATH="$PATH" id -G > out || fail=1 +# Yes outputs all its params so is good to verify argv manipulations +echo 'y' > exp +coreutils --coreutils-prog=yes | head -n10 | uniq > out compare exp out || fail=1 -# With coreutils-8.16 and earlier, id -G would print both: $gp1 $g + +# Ensure if incorrect program passed, we diagnose +echo "coreutils: unknown program 'blah'" > exp +coreutils --coreutils-prog='blah' --help 2>err && fail=1 +compare exp err || fail=1 Exit $fail diff --git a/tests/misc/csplit-1000.sh b/tests/misc/csplit-1000.sh index 26cb8a8c..6757a464 100755 --- a/tests/misc/csplit-1000.sh +++ b/tests/misc/csplit-1000.sh @@ -1,7 +1,7 @@ #!/bin/sh # cause a 1-byte heap buffer overrun -# Copyright (C) 2010-2013 Free Software Foundation, Inc. +# Copyright (C) 2010-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/csplit-heap.sh b/tests/misc/csplit-heap.sh index 82945a78..03fc9a36 100755 --- a/tests/misc/csplit-heap.sh +++ b/tests/misc/csplit-heap.sh @@ -1,7 +1,7 @@ #!/bin/sh # ensure that csplit uses a bounded amount of memory -# Copyright (C) 2010-2013 Free Software Foundation, Inc. +# Copyright (C) 2010-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -19,7 +19,7 @@ . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src print_ver_ csplit -require_ulimit_ +require_ulimit_v_ ( ulimit -v 20000 diff --git a/tests/misc/csplit-suppress-matched.pl b/tests/misc/csplit-suppress-matched.pl new file mode 100755 index 00000000..cea64e4f --- /dev/null +++ b/tests/misc/csplit-suppress-matched.pl @@ -0,0 +1,213 @@ +#!/usr/bin/perl + +# Copyright (C) 2013-2014 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +use strict; +use Data::Dumper; + +my $limits = getlimits (); + +my $prog = 'csplit'; + +# Turn off localization of executable's output. +@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; + +# Input from 'seq 6' +my $IN_SEQ_6 =<<EOF; +1 +2 +3 +4 +5 +6 +EOF + +# Input from a possible run of 'uniq --group' +# (groups separated by empty lines) +my $IN_UNIQ =<<EOF; +a +a +YY + +XX +b +b +YY + +XX +c +YY + +XX +d +d +d +EOF + +# Standard Coreotils::run_tests() structure, except the addition of +# "OUTPUTS" array, containing the expected content of the output files. +# See code below for conversion into PRE/CMP/POST checks. +my @csplit_tests = +( + # without --suppress-matched, + # the newline (matched line) appears in the output files + ["re-base", "-q - '/^\$/' '{*}'", {IN_PIPE => $IN_UNIQ}, + {OUTPUTS => [ "a\na\nYY\n", "\nXX\nb\nb\nYY\n","\nXX\nc\nYY\n", + "\nXX\nd\nd\nd\n" ] }], + + # the newline (matched line) does not appears in the output files + ["re-1", " --suppress-matched -q - '/^\$/' '{*}'", {IN_PIPE => $IN_UNIQ}, + {OUTPUTS => ["a\na\nYY\n", "XX\nb\nb\nYY\n", "XX\nc\nYY\n", + "XX\nd\nd\nd\n"]}], + + # the 'XX' (matched line + offset 1) does not appears in the output files. + # the newline appears in the files (before each split, at the end of the file) + ["re-2", "--suppress-matched -q - '/^\$/1' '{*}'", {IN_PIPE => $IN_UNIQ}, + {OUTPUTS => ["a\na\nYY\n\n","b\nb\nYY\n\n","c\nYY\n\n","d\nd\nd\n"]}], + + # the 'YY' (matched line + offset of -1) does not appears in the output files + # the newline appears in the files (as the first line of the new split) + ["re-3", " --suppress-matched -q - '/^\$/-1' '{*}'", {IN_PIPE => $IN_UNIQ}, + {OUTPUTS => ["a\na\n", "\nXX\nb\nb\n", "\nXX\nc\n", "\nXX\nd\nd\nd\n"]}], + + # Test two consecutive matched lines + # without suppress-matched, the second file should contain a single newline. + ["re-4.1", "-q - '/^\$/' '{*}'", {IN_PIPE => "a\n\n\nb\n"}, + {OUTPUTS => [ "a\n", "\n", "\nb\n" ]}], + # suppress-matched will cause the second file to be empty. + ["re-4.2", "--suppress-match -q - '/^\$/' '{*}'", {IN_PIPE => "a\n\n\nb\n"}, + {OUTPUTS => [ "a\n", "", "b\n" ]}], + # suppress-matched + elide-empty should output just two files. + ["re-4.3", "--suppress-match -zq - '/^\$/' '{*}'", {IN_PIPE => "a\n\n\nb\n"}, + {OUTPUTS => [ "a\n", "b\n" ]}], + + + # Test a matched-line as the last line + # default: last file with newline should be created. + ["re-5.1", "-q - '/^\$/' '{*}'", {IN_PIPE => "a\n\nb\n\n"}, + {OUTPUTS => [ "a\n", "\nb\n", "\n" ]}], + # suppress-matched - last empty files should be created. + ["re-5.2", "--suppress-match -q - '/^\$/' '{*}'", {IN_PIPE => "a\n\nb\n\n"}, + {OUTPUTS => [ "a\n", "b\n", "" ]}], + # suppress-matched + elide-empty: just two files should be created. + ["re-5.3", "--suppress-match -zq - '/^\$/' '{*}'", {IN_PIPE => "a\n\nb\n\n"}, + {OUTPUTS => [ "a\n", "b\n" ]}], + + # without suppress-matched, + # the matched lines (2/4/6) appears in the output files + ["int-base", '-q - 2 4 6', {IN_PIPE => $IN_SEQ_6}, + {OUTPUTS => [ "1\n", "2\n3\n", "4\n5\n", "6\n" ]}], + # suppress matched - the matching lines (2/4/6) should not appear. + ["int-1", '--suppress-matched -q - 2 4 6', {IN_PIPE => $IN_SEQ_6}, + {OUTPUTS => [ "1\n", "3\n", "5\n", "" ]}], + # suppress matched + elide-empty + ["int-2", '--suppress-matched -zq - 2 4 6', {IN_PIPE => $IN_SEQ_6}, + {OUTPUTS => [ "1\n", "3\n", "5\n" ]}], +); + + + +=pod +The following loop translate the above @Tests to a Cureutils::run_tests() +compatible structure. It converts "OUTPUTS" key into "CMP" + "POST" keys: +1. Each element in the OUTPUTS key is expected to be an output file + from csplit (named xx00, xx01, xx02...) + create a "CMP" key for each one, with the output and the filename. +2. Add a "POST" key, ensuring no extra files have been created. + (e.g. if there are 4 expected outputs, xx00 to xx03, + ensure xx04 doesn't exist). +3. Add a "PRE" key, deleting all existing 'xx*' files. + +Example: + +Before conversion: + my @csplit_tests = + ( + ["1", '-z -q - 2 4 6', + {IN_PIPE => "1\n2\n3\n4\n5\n6\n"}, + {OUTPUTS => [ "1\n", "2\n3\n", "4\n5\n", "6\n" ], + ] + ) + +After conversion: + + my @csplit_tests = + ( + ["1", '-z -q - 2 4 6', + {IN_PIPE => "1\n2\n3\n4\n5\n6\n"}, + {PRE => sub { unlink glob './xx??' ; }}, + {CMP => ["1\n", {'xx00'=> undef}]}, + {CMP => ["2\n3\n", {'xx01'=> undef}]}, + {CMP => ["4\n5\n", {'xx02'=> undef}]}, + {CMP => ["6\n", {'xx03'=> undef}]}, + {POST => sub { die "extra file" if -e 'xx04'}}, + ], + ); +=cut +my @Tests; +foreach my $t (@csplit_tests) + { + my ($test_name, $cmdline, @others) = @$t; + my $new_ent = [$test_name, $cmdline]; + + my $out_file_num = 0 ; + + foreach my $e (@others) + { + die "Internal error: expecting a hash (e.g. IN_PIPE/OUTPUTS/ERR)" . + "in test '$test_name', got $e" + unless ref $e && (ref $e eq 'HASH'); + + my ($key, $value) = each %$e; + if ($key eq 'OUTPUTS') + { + # Convert each expected OUTPUT to a 'CMP' key. + foreach my $output (@$value) + { + my $filename = sprintf("xx%02d",$out_file_num++); + my $cmp = {CMP => [ $output, { $filename => undef}]}; + push @$new_ent, $cmp; + } + + # Add a 'POST' check + # Ensure no extra files have been created. + my $filename = sprintf("xx%02d",$out_file_num++); + my $post = { POST => sub { die "Test failed: an extraneous file " . + "'$filename' has been created\n" + if -e $filename; } } ; + push @$new_ent, $post; + + # before running each test, cleanup the 'xx00' files + # from previous runs. + my $pre = { PRE => sub { unlink glob "./xx??"; } }; + push @$new_ent, $pre; + } + else + { + # pass other entities as-is (e.g. OUT, ERR, OUT_SUBST, EXIT) + # run_tests() will know how to handle them. + push @$new_ent, $e; + } + } + + push @Tests, $new_ent; + } + +my $save_temps = $ENV{DEBUG}; +my $verbose = $ENV{VERBOSE}; + +my $fail = run_tests ($prog, $prog, \@Tests, $save_temps, $verbose); +exit $fail; diff --git a/tests/misc/csplit.sh b/tests/misc/csplit.sh index 24c21aaf..da09c1f0 100755 --- a/tests/misc/csplit.sh +++ b/tests/misc/csplit.sh @@ -1,7 +1,7 @@ #!/bin/sh # various csplit tests -# Copyright (C) 2001-2013 Free Software Foundation, Inc. +# Copyright (C) 2001-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/cut-huge-range.sh b/tests/misc/cut-huge-range.sh new file mode 100755 index 00000000..e2c4108c --- /dev/null +++ b/tests/misc/cut-huge-range.sh @@ -0,0 +1,64 @@ +#!/bin/sh +# Ensure that cut does not allocate mem for large ranges + +# Copyright (C) 2012-2014 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ cut +require_ulimit_v_ +getlimits_ + +# sed script to subtract one from the input. +# Each input line should consist of a positive decimal number. +# Each output line's number is one less than the input's. +# There's no limit (other than line length) on the number's magnitude. +subtract_one=' + s/$/@/ + : again + s/0@/@9/ + s/1@/0/ + s/2@/1/ + s/3@/2/ + s/4@/3/ + s/5@/4/ + s/6@/5/ + s/7@/6/ + s/8@/7/ + s/9@/8/ + t again +' + +# Ensure we can cut up to our sentinel value. +# This is currently SIZE_MAX, but could be raised to UINTMAX_MAX +# if we didn't allocate memory for each line as a unit. +# Don't use expr to subtract one, since SIZE_MAX may exceed its maximum value. +CUT_MAX=$(echo $SIZE_MAX | sed "$subtract_one") + +# From coreutils-8.10 through 8.20, this would make cut try to allocate +# a 256MiB bit vector. With a 20MB limit on VM, the following would fail. +(ulimit -v 20000; : | cut -b$CUT_MAX- > err 2>&1) || fail=1 + +# Up to and including coreutils-8.21, cut would allocate possibly needed +# memory upfront. Subsequently extra memory is no longer needed. +(ulimit -v 20000; : | cut -b1-$CUT_MAX >> err 2>&1) || fail=1 + +# Explicitly disallow values above CUT_MAX +(ulimit -v 20000; : | cut -b$SIZE_MAX 2>/dev/null) && fail=1 +(ulimit -v 20000; : | cut -b$SIZE_OFLOW 2>/dev/null) && fail=1 + +compare /dev/null err || fail=1 + +Exit $fail diff --git a/tests/misc/cut-huge-to-eol-range.sh b/tests/misc/cut-huge-to-eol-range.sh deleted file mode 100755 index 42cecfd7..00000000 --- a/tests/misc/cut-huge-to-eol-range.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/sh -# Ensure that cut does not allocate mem for a range like -b9999999999999- - -# Copyright (C) 2012-2013 Free Software Foundation, Inc. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. - -. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src -print_ver_ cut -require_ulimit_ -getlimits_ - -# From coreutils-8.10 through 8.20, this would make cut try to allocate -# a 256MiB bit vector. With a 20MB limit on VM, the following would fail. -(ulimit -v 20000; : | cut -b$INT_MAX- > err 2>&1) || fail=1 - -compare /dev/null err || fail=1 - -Exit $fail diff --git a/tests/misc/cut.pl b/tests/misc/cut.pl index 41e9e209..04188621 100755 --- a/tests/misc/cut.pl +++ b/tests/misc/cut.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Test "cut". -# Copyright (C) 2006-2013 Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -144,15 +144,17 @@ my @Tests = ['newline-12', '-s', '-d:', '-f1', {IN=>"a:1\nb:"}, {OUT=>"a\nb\n"}], ['newline-13', '-d:', '-f1-', {IN=>"a1:\n:"}, {OUT=>"a1:\n:\n"}], # newline processing for fields when -d == '\n' - ['newline-14', "-d'\n'", '-f1', {IN=>"a:1\nb:"}, {OUT=>"a:1\nb:\n"}], + ['newline-14', "-d'\n'", '-f1', {IN=>"a:1\nb:"}, {OUT=>"a:1\n"}], ['newline-15', '-s', "-d'\n'", '-f1', {IN=>"a:1\nb:"}, {OUT=>"a:1\n"}], - ['newline-16', '-s', "-d'\n'", '-f2', {IN=>"\nb"}, {OUT=>""}], + ['newline-16', '-s', "-d'\n'", '-f2', {IN=>"\nb"}, {OUT=>"b\n"}], ['newline-17', '-s', "-d'\n'", '-f1', {IN=>"\nb"}, {OUT=>"\n"}], - ['newline-18', "-d'\n'", '-f2', {IN=>"\nb"}, {OUT=>"\nb\n"}], - ['newline-19', "-d'\n'", '-f1', {IN=>"\nb"}, {OUT=>"\nb\n"}], + ['newline-18', "-d'\n'", '-f2', {IN=>"\nb"}, {OUT=>"b\n"}], + ['newline-19', "-d'\n'", '-f1', {IN=>"\nb"}, {OUT=>"\n"}], ['newline-20', '-s', "-d'\n'", '-f1-', {IN=>"\n"}, {OUT=>"\n"}], - ['newline-21', '-s', "-d'\n'", '-f1-', {IN=>"\nb"}, {OUT=>"\n"}], + ['newline-21', '-s', "-d'\n'", '-f1-', {IN=>"\nb"}, {OUT=>"\nb\n"}], ['newline-22', "-d'\n'", '-f1-', {IN=>"\nb"}, {OUT=>"\nb\n"}], + ['newline-23', "-d'\n'", '-f1-', '--ou=:', {IN=>"a\nb\n"}, {OUT=>"a:b\n"}], + ['newline-24', "-d'\n'", '-f1,2', '--ou=:', {IN=>"a\nb\n"}, {OUT=>"a:b\n"}], # New functionality: ['out-delim1', '-c1-3,5-', '--output-d=:', {IN=>"abcdefg\n"}, @@ -210,6 +212,8 @@ my @Tests = {IN=>"123456\n"}, {OUT=>"23456\n"}], ['EOL-subsumed-3', '--complement -b3,4-4,5,2-', {IN=>"123456\n"}, {OUT=>"1\n"}], + ['EOL-subsumed-4', '--output-d=: -b1-2,2-3,3-', + {IN=>"1234\n"}, {OUT=>"1234\n"}], ); if ($mb_locale ne 'C') diff --git a/tests/misc/date-next-dow.pl b/tests/misc/date-next-dow.pl index 3c79e22a..a1c21127 100755 --- a/tests/misc/date-next-dow.pl +++ b/tests/misc/date-next-dow.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Test "date". -# Copyright (C) 2005-2013 Free Software Foundation, Inc. +# Copyright (C) 2005-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/date-sec.sh b/tests/misc/date-sec.sh index 67048c13..9c001fdc 100755 --- a/tests/misc/date-sec.sh +++ b/tests/misc/date-sec.sh @@ -3,7 +3,7 @@ # date --date="21:04 +0100" +%S' always prints '00'. # Before coreutils-5.2.1, it would print the seconds from the current time. -# Copyright (C) 2004-2013 Free Software Foundation, Inc. +# Copyright (C) 2004-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/date.pl b/tests/misc/date.pl index d0b3517c..40be4cab 100755 --- a/tests/misc/date.pl +++ b/tests/misc/date.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Test "date". -# Copyright (C) 2005-2013 Free Software Foundation, Inc. +# Copyright (C) 2005-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -287,6 +287,13 @@ my @Tests = {ERR => "date: invalid date '\\260'\n"}, {EXIT => 1}, ], + + # From coreutils-5.3.0 to 8.22 inclusive + # this would either infinite loop or crash + ['invalid-TZ-crash', "-d 'TZ=\"\"\"'", + {ERR => "date: invalid date 'TZ=\"\"\"'\n"}, + {EXIT => 1}, + ], ); # Repeat the cross-dst test, using Jan 1, 2005 and every interval from 1..364. diff --git a/tests/misc/dircolors.pl b/tests/misc/dircolors.pl index 061e372f..a70a8c5d 100755 --- a/tests/misc/dircolors.pl +++ b/tests/misc/dircolors.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Simple dircolors tests. -# Copyright (C) 1998-2013 Free Software Foundation, Inc. +# Copyright (C) 1998-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/dirname.pl b/tests/misc/dirname.pl index 43182a8c..34c905d4 100755 --- a/tests/misc/dirname.pl +++ b/tests/misc/dirname.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Test "dirname". -# Copyright (C) 2006-2013 Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/env-null.sh b/tests/misc/env-null.sh index 3cbbcbd5..9b9c95e7 100755 --- a/tests/misc/env-null.sh +++ b/tests/misc/env-null.sh @@ -1,7 +1,7 @@ #!/bin/sh # Verify behavior of env -0 and printenv -0. -# Copyright (C) 2009-2013 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -40,7 +40,7 @@ compare out1 out2 || fail=1 # env -0 does not work if a command is specified. env -0 echo hi > out test $? = 125 || fail=1 -test -s out && fail=1 +compare /dev/null out || fail=1 # Test env -0 on a one-variable environment. printf 'a=b\nc=\0' > exp || framework_failure_ @@ -53,7 +53,7 @@ env "$(printf 'a=b\nc=')" printenv -0 a > out || fail=1 compare exp out || fail=1 env -u a printenv -0 a > out test $? = 1 || fail=1 -test -s out && fail=1 +compare /dev/null out || fail=1 env -u b "$(printf 'a=b\nc=')" printenv -0 b a > out test $? = 1 || fail=1 compare exp out || fail=1 diff --git a/tests/misc/env.sh b/tests/misc/env.sh index 7c9e8fdc..d06a1fb0 100755 --- a/tests/misc/env.sh +++ b/tests/misc/env.sh @@ -1,7 +1,7 @@ #!/bin/sh # Verify behavior of env. -# Copyright (C) 2009-2013 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -20,16 +20,24 @@ . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src print_ver_ env +# A simple shebang program to call "echo" from symlinks like "./-u" or "./--". +echo "#!$abs_top_builddir/src/echo simple_echo" > simple_echo \ + || framework_failure_ +chmod a+x simple_echo || framework_failure_ + +# Verify we can run the shebang which is not the case if +# there are spaces in $abs_top_builddir. +./simple_echo || skip_ "Error running simple_echo script" # Verify clearing the environment a=1 export a env - > out || fail=1 -test -s out && fail=1 +compare /dev/null out || fail=1 env -i > out || fail=1 -test -s out && fail=1 +compare /dev/null out || fail=1 env -u a -i -u a -- > out || fail=1 -test -s out && fail=1 +compare /dev/null out || fail=1 env -i -- a=b > out || fail=1 echo a=b > exp || framework_failure_ compare exp out || fail=1 @@ -62,7 +70,7 @@ fi ENV_TEST1=a export ENV_TEST1 -: >out || framework_failure_ +>out || framework_failure_ env ENV_TEST2= > all || fail=1 grep '^ENV_TEST' all | LC_ALL=C sort >> out || framework_failure_ env -u ENV_TEST1 ENV_TEST3=c > all || fail=1 @@ -105,9 +113,10 @@ export PATH # Use -- to end options (but not variable assignments). # On some systems, execve("-i") invokes a shebang script ./-i on PATH as # '/bin/sh -i', rather than '/bin/sh -- -i', which doesn't do what we want. -# Avoid the issue by using an executable rather than a script. +# Avoid the issue by using a shebang to 'echo' passing a second parameter +# before the '-i'. See the definition of simple_echo before. # Test -u, rather than -i, to minimize PATH problems. -ln -s "$abs_top_builddir/src/echo" ./-u || framework_failure_ +ln -s "simple_echo" ./-u || framework_failure_ case $(env -u echo echo good) in good) ;; *) fail=1 ;; @@ -117,16 +126,16 @@ case $(env -u echo -- echo good) in *) fail=1 ;; esac case $(env -- -u pass) in - pass) ;; + *pass) ;; *) fail=1 ;; esac # After options have ended, the first argument not containing = is a program. env a=b -- true test $? = 127 || fail=1 -ln -s "$abs_top_builddir/src/echo" ./-- || framework_failure_ +ln -s "simple_echo" ./-- || framework_failure_ case $(env a=b -- true || echo fail) in - true) ;; + *true) ;; *) fail=1 ;; esac diff --git a/tests/misc/expand.pl b/tests/misc/expand.pl index 30be9f91..939e22b8 100755 --- a/tests/misc/expand.pl +++ b/tests/misc/expand.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Exercise expand. -# Copyright (C) 2004-2013 Free Software Foundation, Inc. +# Copyright (C) 2004-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/expr.pl b/tests/misc/expr.pl index 9b957a5c..c084b118 100755 --- a/tests/misc/expr.pl +++ b/tests/misc/expr.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Basic tests for "expr". -# Copyright (C) 2001-2013 Free Software Foundation, Inc. +# Copyright (C) 2001-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/factor.pl b/tests/misc/factor.pl index 042a8469..294b814f 100755 --- a/tests/misc/factor.pl +++ b/tests/misc/factor.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Basic tests for "factor". -# Copyright (C) 1998-2013 Free Software Foundation, Inc. +# Copyright (C) 1998-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/false-status.sh b/tests/misc/false-status.sh index 33afc0f3..77bea451 100755 --- a/tests/misc/false-status.sh +++ b/tests/misc/false-status.sh @@ -1,7 +1,8 @@ #!/bin/sh # ensure that false exits nonzero even with --help or --version +# and ensure that true exits nonzero when it can't write --help or --version -# Copyright (C) 2003-2013 Free Software Foundation, Inc. +# Copyright (C) 2003-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -17,9 +18,14 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src -print_ver_ false +print_ver_ false true -false --version > /dev/null && fail=1 -false --help > /dev/null && fail=1 +env false --version > /dev/null && fail=1 +env false --help > /dev/null && fail=1 + +if test -w /dev/full && test -c /dev/full; then + env true --version > /dev/full && fail=1 + env true --help > /dev/full && fail=1 +fi Exit $fail diff --git a/tests/misc/fold.pl b/tests/misc/fold.pl index 1d197bb4..69b0c5b5 100755 --- a/tests/misc/fold.pl +++ b/tests/misc/fold.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Exercise fold. -# Copyright (C) 2003-2013 Free Software Foundation, Inc. +# Copyright (C) 2003-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/groups-dash.sh b/tests/misc/groups-dash.sh index 598c3164..0aed2229 100755 --- a/tests/misc/groups-dash.sh +++ b/tests/misc/groups-dash.sh @@ -1,7 +1,7 @@ #!/bin/sh # ensure groups handles -- sanely -# Copyright (C) 2007-2013 Free Software Foundation, Inc. +# Copyright (C) 2007-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/groups-version.sh b/tests/misc/groups-version.sh index 5f87b325..a867701c 100755 --- a/tests/misc/groups-version.sh +++ b/tests/misc/groups-version.sh @@ -1,7 +1,7 @@ #!/bin/sh # ensure groups --version output is similar to id --version -# Copyright (C) 2007-2013 Free Software Foundation, Inc. +# Copyright (C) 2007-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/head-c.sh b/tests/misc/head-c.sh index 6807c4d5..d6433d0d 100755 --- a/tests/misc/head-c.sh +++ b/tests/misc/head-c.sh @@ -1,7 +1,7 @@ #!/bin/sh -# exercise the fix of 2001-08-18, based on test case from Ian Bruce +# exercise head -c -# Copyright (C) 2001-2013 Free Software Foundation, Inc. +# Copyright (C) 2001-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -18,13 +18,28 @@ . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src print_ver_ head +require_ulimit_v_ +getlimits_ +# exercise the fix of 2001-08-18, based on test case from Ian Bruce echo abc > in || framework_failure_ - (head -c1; head -c1) < in > out || fail=1 case "$(cat out)" in ab) ;; *) fail=1 ;; esac +# Test for a bug in coreutils 5.0.1 through 8.22. +printf 'abc\ndef\n' > in1 || framework_failure_ +(dd bs=1 skip=1 count=0 status=none && head -c-4) < in1 > out1 || fail=1 +case "$(cat out1)" in + bc) ;; + *) fail=1 ;; +esac + +# Only allocate memory as needed. +# Coreutils <= 8.21 would allocate memory up front +# based on the value passed to -c +(ulimit -v 20000; head --bytes=-$SSIZE_MAX < /dev/null) || fail=1 + Exit $fail diff --git a/tests/misc/head-elide-tail.pl b/tests/misc/head-elide-tail.pl index 71e00c6c..3c178d69 100755 --- a/tests/misc/head-elide-tail.pl +++ b/tests/misc/head-elide-tail.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Exercise head's --bytes=-N option. -# Copyright (C) 2003-2013 Free Software Foundation, Inc. +# Copyright (C) 2003-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -52,6 +52,8 @@ my @Tests = ['elide-l2', "--lines=-1", {IN=>"a"}, {OUT=>''}], ['elide-l3', "--lines=-1", {IN=>"a\nb"}, {OUT=>"a\n"}], ['elide-l4', "--lines=-1", {IN=>"a\nb\n"}, {OUT=>"a\n"}], + ['elide-l5', "--lines=-0", {IN=>"a\nb\n"}, {OUT=>"a\nb\n"}], + ['elide-l6', "--lines=-0", {IN=>"a\nb"}, {OUT=>"a\nb"}], ); if ($ENV{RUN_EXPENSIVE_TESTS}) @@ -80,9 +82,10 @@ if ($ENV{RUN_EXPENSIVE_TESTS}) } $s =~ s/(.)/$1\n/g; - for my $file_size (0..20) + $s .= 'u'; # test without trailing '\n' + for my $file_size (0..21) { - for my $n_elide (0..20) + for my $n_elide (0..21) { my $input = substr $s, 0, 2 * $file_size; my $out_len = $n_elide < $file_size ? $file_size - $n_elide : 0; diff --git a/tests/misc/head-pos.sh b/tests/misc/head-pos.sh index cb08d72e..1cf9e04b 100755 --- a/tests/misc/head-pos.sh +++ b/tests/misc/head-pos.sh @@ -2,7 +2,7 @@ # When reading a specified number of lines, ensure that the output # file pointer is positioned just after those lines. -# Copyright (C) 2002-2013 Free Software Foundation, Inc. +# Copyright (C) 2002-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/head-write-error.sh b/tests/misc/head-write-error.sh new file mode 100755 index 00000000..22ecf993 --- /dev/null +++ b/tests/misc/head-write-error.sh @@ -0,0 +1,52 @@ +#!/bin/sh +# Ensure we diagnose and not continue writing to +# the output if we get a write error. + +# Copyright (C) 2014 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ head + +if ! test -w /dev/full || ! test -c /dev/full; then + skip_ '/dev/full is required' +fi + +# We can't use /dev/zero as that's bypassed in the --lines case +# due to lseek() indicating it has a size of zero. +yes | head -c10M > bigseek || framework_failure_ + +# This is the single output diagnostic expected, +# (without the possibly varying :strerror(ENOSPC) suffix). +printf '%s\n' "head: error writing 'standard output'" > exp + +# Memory is bounded in these cases +for item in lines bytes; do + for N in 0 1; do + # pipe case + yes | timeout 10s head --$item=-$N > /dev/full 2> errt && fail=1 + test $? = 124 && fail=1 + sed 's/\(head:.*\):.*/\1/' errt > err + compare exp err || fail=1 + + # seekable case + timeout 10s head --$item=-$N bigseek > /dev/full 2> errt && fail=1 + test $? = 124 && fail=1 + sed 's/\(head:.*\):.*/\1/' errt > err + compare exp err || fail=1 + done +done + +Exit $fail diff --git a/tests/misc/head.pl b/tests/misc/head.pl index d92a0a5c..159d4efc 100755 --- a/tests/misc/head.pl +++ b/tests/misc/head.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # test head -# Copyright (C) 2008-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/help-version.sh b/tests/misc/help-version.sh index 00f30cd0..0598557f 100755 --- a/tests/misc/help-version.sh +++ b/tests/misc/help-version.sh @@ -2,7 +2,7 @@ # Make sure all of these programs work properly # when invoked with --help or --version. -# Copyright (C) 2000-2013 Free Software Foundation, Inc. +# Copyright (C) 2000-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -70,47 +70,38 @@ done test "x$v" = "x$VERSION" \ || fail_ "--version-\$VERSION mismatch" -for lang in C fr da; do - for i in $built_programs; do - - # Skip 'test'; it doesn't accept --help or --version. - test $i = test && continue; - - # false fails even when invoked with --help or --version. - if test $i = false; then - env LC_MESSAGES=$lang $i --help >/dev/null && fail=1 - env LC_MESSAGES=$lang $i --version >/dev/null && fail=1 - continue - fi +for i in $built_programs; do - # The just-built install executable is always named 'ginstall'. - test $i = install && i=ginstall - - # Make sure they exit successfully, under normal conditions. - env $i --help > h-$i || fail=1 - env $i --version >/dev/null || fail=1 - - # Make sure they mention the bug-reporting address in --help output. - grep "$PACKAGE_BUGREPORT" h-$i > /dev/null || fail=1 - rm -f h-$i - - # Make sure they fail upon 'disk full' error. - if test -w /dev/full && test -c /dev/full; then - env $i --help >/dev/full 2>/dev/null && fail=1 - env $i --version >/dev/full 2>/dev/null && fail=1 - status=$? - test $i = [ && prog=lbracket || prog=$(echo $i|sed "s/$EXEEXT$//") - eval "expected=\$expected_failure_status_$prog" - test x$expected = x && expected=1 - if test $status = $expected; then - : # ok - else - fail=1 - echo "*** $i: bad exit status '$status' (expected $expected)," 1>&2 - echo " with --help or --version output redirected to /dev/full" 1>&2 - fi + # Skip 'test'; it doesn't accept --help or --version. + test $i = test && continue + + # false fails even when invoked with --help or --version. + # true and false are tested with these options separately. + test $i = false || test $i = true && continue + + # The just-built install executable is always named 'ginstall'. + test $i = install && i=ginstall + + # Make sure they exit successfully, under normal conditions. + env $i --help >/dev/null || fail=1 + env $i --version >/dev/null || fail=1 + + # Make sure they fail upon 'disk full' error. + if test -w /dev/full && test -c /dev/full; then + env $i --help >/dev/full 2>/dev/null && fail=1 + env $i --version >/dev/full 2>/dev/null && fail=1 + status=$? + test $i = [ && prog=lbracket || prog=$(echo $i|sed "s/$EXEEXT$//") + eval "expected=\$expected_failure_status_$prog" + test x$expected = x && expected=1 + if test $status = $expected; then + : # ok + else + fail=1 + echo "*** $i: bad exit status '$status' (expected $expected)," 1>&2 + echo " with --help or --version output redirected to /dev/full" 1>&2 fi - done + fi done bigZ_in=bigZ-in.Z @@ -248,7 +239,7 @@ parted_setup () { args="-s $tmp_in mklabel gpt" # something more than --help or --version. for i in $built_programs; do # Skip these. - case $i in chroot|stty|tty|false|chcon|runcon) continue;; esac + case $i in chroot|stty|tty|false|chcon|runcon|coreutils) continue;; esac rm -rf $tmp_in $tmp_in2 $tmp_dir $tmp_out $bigZ_in $zin $zin2 echo z |gzip > $zin diff --git a/tests/misc/id-context.sh b/tests/misc/id-context.sh deleted file mode 100755 index dc023033..00000000 --- a/tests/misc/id-context.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/sh -# Ensure that "id" outputs SELinux context only without specified user -# Copyright (C) 2008-2013 Free Software Foundation, Inc. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. - -. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src -print_ver_ id -# Require selinux - when selinux is disabled, id never prints scontext. -require_selinux_ - - -# Check without specified user, context string should be present. -id | grep context= >/dev/null || fail=1 - -# Check with specified user, no context string should be present. -# But if the current user is nameless, skip this part. -id -nu > /dev/null \ - && id $(id -nu) | grep context= >/dev/null && fail=1 - -Exit $fail diff --git a/tests/misc/invalid-opt.pl b/tests/misc/invalid-opt.pl index 1d7701f0..bcf6ee71 100755 --- a/tests/misc/invalid-opt.pl +++ b/tests/misc/invalid-opt.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # exercise the 'invalid option' handling code in each program -# Copyright (C) 2008-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/join.pl b/tests/misc/join.pl index 9b93794d..cf3f4bd4 100755 --- a/tests/misc/join.pl +++ b/tests/misc/join.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Test join. -# Copyright (C) 2008-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -275,6 +275,26 @@ my @tv = ( [ "ID1 Name\n1 A\n", ""], "ID1 Name\n1 A\n", 0], +# Zero-terminated lines +['z1', '-z', + ["a\0c\0e\0", "a\0b\0c\0"], "a\0c\0", 0], + +# not zero-terminated, but related to the code change: +# the old readlinebuffer() auto-added '\n' to the last line. +# the new readlinebuffer_delim() does not. +# Ensure it doesn't matter. +['z2', '', + ["a\nc\ne\n", "a\nb\nc"], "a\nc\n", 0], +['z3', '', + ["a\nc\ne", "a\nb\nc"], "a\nc\n", 0], +# missing last NUL at the end of the last line (=end of file) +['z4', '-z', + ["a\0c\0e", "a\0b\0c"], "a\0c\0", 0], +# edge-case: the embedded newlines should treated as +# part of the nul-terminated line +['z5', '-z -a1 -a2', + ["a\n1\0c 3\0","b\n8\0c 9\0"], "a\n1\0b\n8\0c 3 9\0"], + ); # Convert the above old-style test vectors to the newer diff --git a/tests/misc/ls-misc.pl b/tests/misc/ls-misc.pl index 5bf7b9eb..a47e70b7 100755 --- a/tests/misc/ls-misc.pl +++ b/tests/misc/ls-misc.pl @@ -1,6 +1,6 @@ #!/usr/bin/perl -# Copyright (C) 1998-2013 Free Software Foundation, Inc. +# Copyright (C) 1998-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -303,9 +303,12 @@ my @Tests = . "\e[37;44msticky$e\n" }, + {PRE => sub { + push_ls_colors('ow=34;42:tw=30;42:sg=30;43:su=37;41:st=37;44'); }}, {POST => sub { unlink qw(setuid setgid); - foreach my $dir (qw(owr owt sticky)) {rmdir $dir} }}, + foreach my $dir (qw(owr owt sticky)) {rmdir $dir} + restore_ls_colors; }}, ], # For 5.97 and earlier, --file-type acted like --indicator-style=slash. diff --git a/tests/misc/ls-time.sh b/tests/misc/ls-time.sh index 80e400f4..3ce4a91c 100755 --- a/tests/misc/ls-time.sh +++ b/tests/misc/ls-time.sh @@ -1,7 +1,7 @@ #!/bin/sh # Test some of ls's sorting options. -# Copyright (C) 1998-2013 Free Software Foundation, Inc. +# Copyright (C) 1998-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/md5sum-bsd.sh b/tests/misc/md5sum-bsd.sh index 6b70f21a..f73e0622 100755 --- a/tests/misc/md5sum-bsd.sh +++ b/tests/misc/md5sum-bsd.sh @@ -2,7 +2,7 @@ # 'md5sum' tests for generation and checking of # BSD traditional and alternate formats (md5 [-r]) -# Copyright (C) 2011-2013 Free Software Foundation, Inc. +# Copyright (C) 2011-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -70,7 +70,7 @@ nl=' tab=' ' rm check.md5 for i in 'a\b' 'a\' "a${nl}b" "a${tab}b"; do - :> "$i" + > "$i" md5sum --tag "$i" >> check.md5 done md5sum --strict -c check.md5 || fail=1 diff --git a/tests/misc/md5sum-newline.pl b/tests/misc/md5sum-newline.pl index ad1b6acb..b418d5b4 100755 --- a/tests/misc/md5sum-newline.pl +++ b/tests/misc/md5sum-newline.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Newline tests for "md5sum". -# Copyright (C) 1999-2013 Free Software Foundation, Inc. +# Copyright (C) 1999-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/md5sum-parallel.sh b/tests/misc/md5sum-parallel.sh index 648bfa5b..92f66296 100755 --- a/tests/misc/md5sum-parallel.sh +++ b/tests/misc/md5sum-parallel.sh @@ -2,7 +2,7 @@ # Ensure that md5sum prints each checksum atomically # so that concurrent md5sums don't intersperse their output -# Copyright (C) 2009-2013 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/md5sum.pl b/tests/misc/md5sum.pl index 5192d55f..0aa0056f 100755 --- a/tests/misc/md5sum.pl +++ b/tests/misc/md5sum.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Basic tests for "md5sum". -# Copyright (C) 1998-2013 Free Software Foundation, Inc. +# Copyright (C) 1998-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -38,7 +38,9 @@ my @Tests = {OUT=>"d174ab98d277d9f5a5611c2c9f419d9f f\n"}], ['7', {IN=> {f=> '1234567890' x 8}}, {OUT=>"57edf4a22be3c955ac49da2e2107b67a f\n"}], - ['backslash', {IN=> {".\\foo"=> ''}}, + ['backslash-1', {IN=> {".\nfoo"=> ''}}, + {OUT=>"\\$degenerate .\\nfoo\n"}], + ['backslash-2', {IN=> {".\\foo"=> ''}}, {OUT=>"\\$degenerate .\\\\foo\n"}], ['check-1', '--check', {AUX=> {f=> ''}}, {IN=> {'f.md5' => "$degenerate f\n"}}, diff --git a/tests/misc/mknod.sh b/tests/misc/mknod.sh index 30f363f6..fb907f16 100755 --- a/tests/misc/mknod.sh +++ b/tests/misc/mknod.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure that mknod, mkfifo, mkdir -m MODE work with a restrictive umask -# Copyright (C) 2004-2013 Free Software Foundation, Inc. +# Copyright (C) 2004-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/mktemp.pl b/tests/misc/mktemp.pl index b15b6694..13ee03f5 100755 --- a/tests/misc/mktemp.pl +++ b/tests/misc/mktemp.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Test "mktemp". -# Copyright (C) 2007-2013 Free Software Foundation, Inc. +# Copyright (C) 2007-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -55,14 +55,12 @@ my @Tests = ( # test-name, [option, option, ...] {OUT=>"expected-output"} # - ['too-many', 'a b', + ['too-many', '-q a b', {ERR=>"$prog: too many templates\n" . "Try '$prog --help' for more information.\n"}, {EXIT => 1} ], - ['too-many-q', '-q a b', {EXIT => 1} ], - ['too-few-x', 'foo.XX', {EXIT => 1}, + ['too-few-x', '-q foo.XX', {EXIT => 1}, {ERR=>"$prog: too few X's in template 'foo.XX'\n"}], - ['too-few-xq', '-q foo.XX', {EXIT => 1} ], ['1f', 'bar.XXXX', {OUT => "bar.ZZZZ\n"}, {OUT_SUBST => 's,\.....$,.ZZZZ,'}, @@ -148,11 +146,9 @@ my @Tests = ['suffix6f', 'aXXXX/b', {EXIT=>1}, {ERR=>"$prog: invalid suffix '/b', contains directory separator\n"}], - ['suffix6f-q', '-q aXXXX/b', {EXIT=>1}], ['suffix7f', '--suffix= aXXXXb', {EXIT=>1}, {ERR=>"$prog: with --suffix, template 'aXXXXb' must end in X\n"}], - ['suffix7f-q', '-q --suffix= aXXXXb', {EXIT=>1}], ['suffix7d', '-d --suffix=aXXXXb ""', {EXIT=>1}, {ERR=>"$prog: with --suffix, template '' must end in X\n"}], diff --git a/tests/misc/nice-fail.sh b/tests/misc/nice-fail.sh index 3e054354..3bf823ab 100755 --- a/tests/misc/nice-fail.sh +++ b/tests/misc/nice-fail.sh @@ -1,7 +1,7 @@ #!/bin/sh # Verify that internal failure in nice gives exact status. -# Copyright (C) 2009-2013 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/nice.sh b/tests/misc/nice.sh index acee0f44..26a01ca9 100755 --- a/tests/misc/nice.sh +++ b/tests/misc/nice.sh @@ -1,7 +1,7 @@ #! /bin/sh # Test "nice". -# Copyright (C) 2002-2013 Free Software Foundation, Inc. +# Copyright (C) 2002-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -81,12 +81,12 @@ if test x$(nice -n -1 nice 2> /dev/null) = x0 ; then if test -w /dev/full && test -c /dev/full; then nice -n -1 nice > out 2> /dev/full test $? = 125 || fail=1 - test -s out && fail=1 + compare /dev/null out || fail=1 fi else # superuser - change succeeds nice -n -1 nice 2> err || fail=1 - test -s err && fail=1 + compare /dev/null err || fail=1 test x$(nice -n -1 nice) = x-1 || fail=1 test x$(nice --1 nice) = x-1 || fail=1 fi diff --git a/tests/misc/nl.sh b/tests/misc/nl.sh index dfa7b237..676c75d7 100755 --- a/tests/misc/nl.sh +++ b/tests/misc/nl.sh @@ -1,7 +1,7 @@ #!/bin/sh # exercise nl functionality -# Copyright (C) 2002-2013 Free Software Foundation, Inc. +# Copyright (C) 2002-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/nohup.sh b/tests/misc/nohup.sh index 91d9e6a2..b3f4274c 100755 --- a/tests/misc/nohup.sh +++ b/tests/misc/nohup.sh @@ -1,7 +1,7 @@ #!/bin/sh # test nohup -# Copyright (C) 2003-2013 Free Software Foundation, Inc. +# Copyright (C) 2003-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -63,12 +63,17 @@ rm -f nohup.out err # to stderr must be fatal. Requires stdout to be terminal. if test -w /dev/full && test -c /dev/full; then ( + # POSIX shells immediately exit the subshell on exec error. + # So check we can write to /dev/tty before the exec, which + # isn't possible if we've no controlling tty for example. + test -c /dev/tty && >/dev/tty || exit 0 + exec >/dev/tty test -t 1 || exit 0 nohup echo hi 2> /dev/full test $? = 125 || fail=1 test -f nohup.out || fail=1 - test -s nohup.out && fail=1 + compare /dev/null nohup.out || fail=1 rm -f nohup.out exit $fail ) || fail=1 @@ -81,7 +86,7 @@ if test -t 1; then # It must exist. test -f nohup.out || fail=1 # It must be empty. - test -s nohup.out && fail=1 + compare /dev/null nohup.out || fail=1 fi cat <<\EOF > exp || fail=1 @@ -101,7 +106,7 @@ if test -t 1; then # It must exist. test -f nohup.out || fail=1 # It must be empty. - test -s nohup.out && fail=1 + compare /dev/null nohup.out || fail=1 fi cat <<\EOF > exp || fail=1 diff --git a/tests/misc/nproc-avail.sh b/tests/misc/nproc-avail.sh index 8b0e8dcb..1a7e7219 100755 --- a/tests/misc/nproc-avail.sh +++ b/tests/misc/nproc-avail.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure that "nproc" is less than or equal to "nproc --all". -# Copyright (C) 2009-2013 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/nproc-positive.sh b/tests/misc/nproc-positive.sh index d82dc930..c8fe9bae 100755 --- a/tests/misc/nproc-positive.sh +++ b/tests/misc/nproc-positive.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure that nproc prints a number > 0 -# Copyright (C) 2009-2013 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/numfmt.pl b/tests/misc/numfmt.pl index 61917fb8..dfb4b2e0 100644..100755 --- a/tests/misc/numfmt.pl +++ b/tests/misc/numfmt.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Basic tests for "numfmt". -# Copyright (C) 2012 Free Software Foundation, Inc. +# Copyright (C) 2012-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -260,7 +260,7 @@ my @Tests = # so these are 40 of "M", not 40,000,000. ['mix-1', '--suffix=M --from=si 40M', {OUT=>"40M"}], - # These are fourty-million Ms . + # These are forty-million Ms . ['mix-2', '--suffix=M --from=si 40MM', {OUT=>"40000000M"}], ['mix-3', '--suffix=M --from=auto 40MM', {OUT=>"40000000M"}], @@ -695,11 +695,11 @@ my @Tests = {EXIT=>1}], ['fmt-err-4', '--format "%d"', {ERR=>"$prog: invalid format '%d', " . - "directive must be %['][-][N]f\n"}, + "directive must be %[0]['][-][N]f\n"}, {EXIT=>1}], ['fmt-err-5', '--format "% -43 f"', {ERR=>"$prog: invalid format '% -43 f', " . - "directive must be %['][-][N]f\n"}, + "directive must be %[0]['][-][N]f\n"}, {EXIT=>1}], ['fmt-err-6', '--format "%f %f"', {ERR=>"$prog: format '%f %f' has too many % directives\n"}, @@ -708,9 +708,6 @@ my @Tests = {ERR=>"$prog: invalid format '%123456789012345678901234567890f'". " (width overflow)\n"}, {EXIT=>1}], - ['fmt-err-8', '--format "%f" --padding 20', - {ERR=>"$prog: --padding cannot be combined with --format\n"}, - {EXIT=>1}], ['fmt-err-9', '--format "%f" --grouping', {ERR=>"$prog: --grouping cannot be combined with --format\n"}, {EXIT=>1}], @@ -748,6 +745,17 @@ my @Tests = ['fmt-15', '--format "--%100000f--" --to=si 4200', {OUT=>"--" . " " x 99996 . "4.2K--" }], + # --format padding overrides --padding + ['fmt-16', '--format="%6f" --padding=66 1234',{OUT=>" 1234"}], + + # zero padding + ['fmt-17', '--format="%06f" 1234',{OUT=>"001234"}], + # also support spaces (which are ignored as spacing is handled separately) + ['fmt-18', '--format="%0 6f" 1234',{OUT=>"001234"}], + # handle generic padding in combination + ['fmt-22', '--format="%06f" --padding=7 1234',{OUT=>" 001234"}], + ['fmt-23', '--format="%06f" --padding=-7 1234',{OUT=>"001234 "}], + ## Check all errors again, this time with --invalid=fail ## Input will be printed without conversion, @@ -881,13 +889,20 @@ my @Locale_Tests = ['lcl-fmt-4', '--format "--%-10f--" --to=si 5000000', {OUT=>"--5,0M --"}, {ENV=>"LC_ALL=$locale"}], + # handle zero/grouping in combination + ['lcl-fmt-5', '--format="%\'06f" 1234',{OUT=>"01 234"}, + {ENV=>"LC_ALL=$locale"}], + ['lcl-fmt-6', '--format="%0\'6f" 1234',{OUT=>"01 234"}, + {ENV=>"LC_ALL=$locale"}], + ['lcl-fmt-7', '--format="%0\'\'6f" 1234',{OUT=>"01 234"}, + {ENV=>"LC_ALL=$locale"}], ); if ($locale ne 'C') { # Reset locale to 'C' if LOCALE_FR_UTF8 doesn't output as expected # as determined by the separate printf program. - open(LOC_NUM, "LC_ALL=$locale printf \"%'d\" 1234|") + open(LOC_NUM, "env LC_ALL=$locale printf \"%'d\" 1234|") or die "Can't fork command: $!"; my $loc_num = <LOC_NUM>; close(LOC_NUM) || die "Failed to read grouped number from printf"; diff --git a/tests/misc/od-N.sh b/tests/misc/od-N.sh index 8a741fb1..247ea546 100755 --- a/tests/misc/od-N.sh +++ b/tests/misc/od-N.sh @@ -1,7 +1,7 @@ #!/bin/sh # Verify that 'od -N N' reads no more than N bytes of input. -# Copyright (C) 2001-2013 Free Software Foundation, Inc. +# Copyright (C) 2001-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/od-endian.sh b/tests/misc/od-endian.sh new file mode 100755 index 00000000..a01ae0a8 --- /dev/null +++ b/tests/misc/od-endian.sh @@ -0,0 +1,49 @@ +#!/bin/sh +# verify that od --endian works properly + +# Copyright (C) 2014 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ od + +in='0123456789abcdef' + +NL=' +' + +# rev(1) is not generally available, so here's a simplistic +# implementation sufficient for our purposes. +rev() { + while read line; do + printf '%s' "$line" | sed "s/./&\\$NL/g" | tac | paste -s -d '' + done +} + +in_swapped() { printf '%s' "$in" | sed "s/.\{$1\}/&\\$NL/g" | rev |tr -d '\n'; } + +for e in little big; do + test $e = little && eo=big || eo=little + for s in 1 2 4 8 16; do + for t in x f; do + od -t $t$s --endian=$e /dev/null > /dev/null 2>&1 || continue + printf '%s' "$in" | od -An -t $t$s --endian=$e > out1 + in_swapped "$s" | od -An -t $t$s --endian=$eo > out2 + compare out1 out2 || fail=1 + done + done +done + +Exit $fail diff --git a/tests/misc/od-float.sh b/tests/misc/od-float.sh index 306c3abe..8a8e29b2 100755 --- a/tests/misc/od-float.sh +++ b/tests/misc/od-float.sh @@ -1,7 +1,7 @@ #!/bin/sh # Test od on floating-point values. -# Copyright (C) 2010-2013 Free Software Foundation, Inc. +# Copyright (C) 2010-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/od-multiple-t.sh b/tests/misc/od-multiple-t.sh index 2b8de711..451fa2f5 100755 --- a/tests/misc/od-multiple-t.sh +++ b/tests/misc/od-multiple-t.sh @@ -2,7 +2,7 @@ # verify that multiple -t specifiers to od align well # This would fail before coreutils-6.13. -# Copyright (C) 2008-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/od-x8.sh b/tests/misc/od-x8.sh index f55e1b70..6e72dee7 100755 --- a/tests/misc/od-x8.sh +++ b/tests/misc/od-x8.sh @@ -2,7 +2,7 @@ # verify that od -t x8 works properly # This would fail before coreutils-4.5.2. -# Copyright (C) 2002-2013 Free Software Foundation, Inc. +# Copyright (C) 2002-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/od.pl b/tests/misc/od.pl index 0649b1c6..edddf4e3 100755 --- a/tests/misc/od.pl +++ b/tests/misc/od.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Exercise od -# Copyright (C) 2006-2013 Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -57,6 +57,13 @@ my @Tests = # even if the kernel reports that the file has stat.st_size = 0. ['j-proc', "-An -c -j $proc_file_byte_count $proc_file", {IN=>{f2=>'e'}}, {OUT=>" e\n"}], + + # Ensure that a large width does not cause trouble. + # From coreutils-7.0 through coreutils-8.21, these would print + # approximately 128KiB of padding. + ['wide-a', '-a -w65537 -An', {IN=>{g=>'x'}}, {OUT=>" x\n"}], + ['wide-c', '-c -w65537 -An', {IN=>{g=>'x'}}, {OUT=>" x\n"}], + ['wide-x', '-tx1 -w65537 -An', {IN=>{g=>'B'}}, {OUT=>" 42\n"}], ); my $save_temps = $ENV{DEBUG}; diff --git a/tests/misc/paste.pl b/tests/misc/paste.pl index 783a5d42..04f8ec07 100755 --- a/tests/misc/paste.pl +++ b/tests/misc/paste.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Test paste. -# Copyright (C) 2003-2013 Free Software Foundation, Inc. +# Copyright (C) 2003-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/pathchk1.sh b/tests/misc/pathchk1.sh index eed71d5f..616e763f 100755 --- a/tests/misc/pathchk1.sh +++ b/tests/misc/pathchk1.sh @@ -1,7 +1,7 @@ #!/bin/sh # pathchk tests -# Copyright (C) 2002-2013 Free Software Foundation, Inc. +# Copyright (C) 2002-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/printenv.sh b/tests/misc/printenv.sh index e7dbbeef..054b02c2 100755 --- a/tests/misc/printenv.sh +++ b/tests/misc/printenv.sh @@ -1,7 +1,7 @@ #!/bin/sh # Verify behavior of printenv. -# Copyright (C) 2009-2013 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -37,7 +37,7 @@ fi # Printing a single variable's value. env -- printenv ENV_TEST > out test $? = 1 || fail=1 -test -s out && fail=1 +compare /dev/null out || fail=1 echo a > exp || framework_failure_ ENV_TEST=a env -- printenv ENV_TEST > out || fail=1 compare exp out || fail=1 @@ -76,6 +76,6 @@ compare exp out || fail=1 # Bug present through coreutils 8.0. env a=b=c printenv a=b > out test $? = 1 || fail=1 -test -s out && fail=1 +compare /dev/null out || fail=1 Exit $fail diff --git a/tests/misc/printf-cov.pl b/tests/misc/printf-cov.pl index 44250aab..3d797284 100755 --- a/tests/misc/printf-cov.pl +++ b/tests/misc/printf-cov.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # improve printf.c test coverage -# Copyright (C) 2008-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/printf-hex.sh b/tests/misc/printf-hex.sh index d59899cb..27503fae 100755 --- a/tests/misc/printf-hex.sh +++ b/tests/misc/printf-hex.sh @@ -1,7 +1,7 @@ #!/bin/sh # make sure that only two hex. digits are consumed in a \xHHH sequence -# Copyright (C) 2002-2013 Free Software Foundation, Inc. +# Copyright (C) 2002-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/printf-surprise.sh b/tests/misc/printf-surprise.sh index 0db6f7b1..6083806d 100755 --- a/tests/misc/printf-surprise.sh +++ b/tests/misc/printf-surprise.sh @@ -1,7 +1,7 @@ #!/bin/sh # Detect printf(3) failure even when it doesn't set stream error indicator -# Copyright (C) 2007-2013 Free Software Foundation, Inc. +# Copyright (C) 2007-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -20,8 +20,7 @@ prog=printf . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src print_ver_ printf - -require_ulimit_ +require_ulimit_v_ # Up to coreutils-6.9, "printf %.Nf 0" would encounter an ENOMEM internal diff --git a/tests/misc/printf.sh b/tests/misc/printf.sh index d2ff3edb..b2292252 100755 --- a/tests/misc/printf.sh +++ b/tests/misc/printf.sh @@ -1,7 +1,7 @@ #!/bin/sh # basic tests for printf -# Copyright (C) 2002-2013 Free Software Foundation, Inc. +# Copyright (C) 2002-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/ptx-overrun.sh b/tests/misc/ptx-overrun.sh index a89a1b2c..be9fb524 100755 --- a/tests/misc/ptx-overrun.sh +++ b/tests/misc/ptx-overrun.sh @@ -1,7 +1,6 @@ #!/bin/sh -# Trigger a heap-clobbering bug in ptx from coreutils-6.10 and earlier. -# Copyright (C) 2008-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -19,12 +18,12 @@ . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src print_ver_ ptx +# Trigger a heap-clobbering bug in ptx from coreutils-6.10 and earlier. # Using a long file name makes an abort more likely. # Even with no file name, valgrind detects the buffer overrun. f=01234567890123456789012345678901234567890123456789 touch $f empty || framework_failure_ - # Specifying a regular expression ending in a lone backslash # would cause ptx to write beyond the end of a malloc'd buffer. ptx -F '\' $f < /dev/null > out || fail=1 @@ -32,4 +31,14 @@ ptx -S 'foo\' $f < /dev/null >> out || fail=1 ptx -W 'bar\\\' $f < /dev/null >> out || fail=1 compare out empty || fail=1 + +# Trigger an invalid heap reference noticed by gcc -fsanitize=address +# from coreutils-8.22 and earlier. As well as an invalid memory reference, +# the issue can be seen in the output, with non deterministice whitespace +# trimming when multiple files are specified. +printf '%s\n' 'This is a ptx whitespace Trimming test' > ws.in +ptx ws.in ws.in | sort | uniq -u > out +compare /dev/null out || fail=1 + + Exit $fail diff --git a/tests/misc/ptx.pl b/tests/misc/ptx.pl index b36eeb98..8a91d616 100755 --- a/tests/misc/ptx.pl +++ b/tests/misc/ptx.pl @@ -1,6 +1,6 @@ #!/usr/bin/perl -# Copyright (C) 2008-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -33,6 +33,13 @@ my @Tests = # with coreutils-6.12 and earlier, this would act like "ptx F1 F1" ["2files", '-g1 -w1', {IN=>{F1=>"a"}}, {IN=>{F2=>"b"}}, {OUT=>" a\n b\n"}], + +# with coreutils-8.22 and earlier, the --format long option would +# fall through into the --help case. +["format-r", '--format=roff', {IN=>"foo\n"}, + {OUT=>".xx \"\" \"\" \"foo\" \"\"\n"}], +["format-t", '--format=tex', {IN=>"foo\n"}, + {OUT=>"\\xx {}{}{foo}{}{}\n"}], ); @Tests = triple_test \@Tests; diff --git a/tests/misc/pwd-long.sh b/tests/misc/pwd-long.sh index 3b3f83d4..1ba0c1a9 100755 --- a/tests/misc/pwd-long.sh +++ b/tests/misc/pwd-long.sh @@ -2,7 +2,7 @@ # -*- perl -*- # Ensure that pwd works even when run from a very deep directory. -# Copyright (C) 2006-2013 Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/pwd-option.sh b/tests/misc/pwd-option.sh index 9733e108..0eba9429 100755 --- a/tests/misc/pwd-option.sh +++ b/tests/misc/pwd-option.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure that pwd options work. -# Copyright (C) 2009-2013 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -21,7 +21,7 @@ print_ver_ pwd mkdir -p a/b || framework_failure_ ln -s a/b c || framework_failure_ -base=$(env -- pwd) +base=$(env -- pwd -P) # Remove any logical paths from $PWD. cd "$base" || framework_failure_ diff --git a/tests/misc/readlink-fp-loop.sh b/tests/misc/readlink-fp-loop.sh index 6c7f70ac..4ae2dc52 100755 --- a/tests/misc/readlink-fp-loop.sh +++ b/tests/misc/readlink-fp-loop.sh @@ -1,7 +1,7 @@ #!/bin/sh # readlink from 6.9 would fail with a false-positive symlink loop error -# Copyright (C) 2007-2013 Free Software Foundation, Inc. +# Copyright (C) 2007-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -18,7 +18,7 @@ . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src print_ver_ readlink -cwd=$("$abs_top_builddir/src/pwd") +cwd=$(env pwd -P) # To trigger this bug, we have to construct a name/situation during # the resolution of which the code dereferences the same symlink (S) diff --git a/tests/misc/readlink-root.sh b/tests/misc/readlink-root.sh index ddd49092..f33574cb 100755 --- a/tests/misc/readlink-root.sh +++ b/tests/misc/readlink-root.sh @@ -1,7 +1,7 @@ #!/bin/sh # tests for canonicalize-existing mode (readlink -e) on /. -# Copyright (C) 2012-2013 Free Software Foundation, Inc. +# Copyright (C) 2012-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/realpath.sh b/tests/misc/realpath.sh index 7a8bf497..257b9f24 100755 --- a/tests/misc/realpath.sh +++ b/tests/misc/realpath.sh @@ -1,7 +1,7 @@ #!/bin/sh # Validate realpath operation -# Copyright (C) 2011-2013 Free Software Foundation, Inc. +# Copyright (C) 2011-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/runcon-no-reorder.sh b/tests/misc/runcon-no-reorder.sh index 27656c7d..ca8ad5b3 100755 --- a/tests/misc/runcon-no-reorder.sh +++ b/tests/misc/runcon-no-reorder.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure that runcon does not reorder its arguments. -# Copyright (C) 2007-2013 Free Software Foundation, Inc. +# Copyright (C) 2007-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -27,7 +27,7 @@ echo "$diag" > exp || framework_failure_ # On such a system it fails with the above diagnostic, which is fine. # Before the no-reorder change, it would have failed with a diagnostic # about -j being an invalid option. -runcon $(id -Z) true -j 2> out && : > exp +runcon $(id -Z) true -j 2> out && > exp # When run on a system with no /selinux/context (i.e., in a chroot), # it chcon fails with this: "runcon: invalid context: \ diff --git a/tests/misc/selinux.sh b/tests/misc/selinux.sh index b30bcbcf..2a8ad89f 100755 --- a/tests/misc/selinux.sh +++ b/tests/misc/selinux.sh @@ -1,7 +1,7 @@ #!/bin/sh # Test SELinux-related options. -# Copyright (C) 2007-2013 Free Software Foundation, Inc. +# Copyright (C) 2007-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -44,6 +44,12 @@ done # ensure that ls -l output includes the ".". c=$(ls -l f|cut -c11); test "$c" = . || fail=1 +# Copy with an invalid context and ensure it fails +# Note this may succeed when root and selinux is in permissive mode +if test "$(getenforce)" = Enforcing; then + cp --context='invalid-selinux-context' f f.cp && fail=1 +fi + # Copy each to a new directory and ensure that context is preserved. cp -r --preserve=all d f p s1 || fail=1 for i in d f p; do diff --git a/tests/misc/seq-long-double.sh b/tests/misc/seq-long-double.sh index 45e2f05f..78ed50f5 100755 --- a/tests/misc/seq-long-double.sh +++ b/tests/misc/seq-long-double.sh @@ -3,7 +3,7 @@ # Ensure that seq prints exactly two numbers for a 2-number integral # range at the limit of floating point precision. -# Copyright (C) 2008-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/seq.pl b/tests/misc/seq.pl index b3496d62..92484363 100755 --- a/tests/misc/seq.pl +++ b/tests/misc/seq.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Test "seq". -# Copyright (C) 1999-2013 Free Software Foundation, Inc. +# Copyright (C) 1999-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -143,6 +143,9 @@ my @Tests = ['not-fast-1', qw(1 3 1), {OUT => [qw(1)]}], ['not-fast-2', qw(1 1 4.2), {OUT => [qw(1 2 3 4)]}], ['not-fast-3', qw(1 1 0)], + # In 8.20..8.22 a start or end of -0 was broken + ['not-fast-4', qw(-0 10), {OUT => [qw(-0 1 2 3 4 5 6 7 8 9 10)]}], + ['not-fast-5', qw(1 -0)], # Ensure the correct parameters are passed to the fast path ['fast-1', qw(4), {OUT => [qw(1 2 3 4)]}], diff --git a/tests/misc/sha1sum-vec.pl b/tests/misc/sha1sum-vec.pl index 6df91d64..14005a76 100755 --- a/tests/misc/sha1sum-vec.pl +++ b/tests/misc/sha1sum-vec.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Sample vectors for "sha1sum". -# Copyright (C) 2000-2013 Free Software Foundation, Inc. +# Copyright (C) 2000-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/sha1sum.pl b/tests/misc/sha1sum.pl index 327c4dd8..fdb243a0 100755 --- a/tests/misc/sha1sum.pl +++ b/tests/misc/sha1sum.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Test "sha1sum". -# Copyright (C) 2000-2013 Free Software Foundation, Inc. +# Copyright (C) 2000-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -44,7 +44,9 @@ my @Tests = {OUT=>"50abf5706a150990a08b2c5ea40fa0e585554732 f\n"}], ['million-a', {IN=> {f=> 'a' x 1000000}}, {OUT=>"34aa973cd4c4daa4f61eeb2bdbad27316534016f f\n"}], - ['bs-sha', {IN=> {".\\foo"=> ''}}, + ['bs-sha-1', {IN=> {".\nfoo"=> ''}}, + {OUT=>"\\$sha_degenerate .\\nfoo\n"}], + ['bs-sha-2', {IN=> {".\\foo"=> ''}}, {OUT=>"\\$sha_degenerate .\\\\foo\n"}], # The sha1sum and md5sum drivers share a lot of code. # Ensure that sha1sum does *not* share the part that makes diff --git a/tests/misc/sha224sum.pl b/tests/misc/sha224sum.pl index ef881280..384738b8 100755 --- a/tests/misc/sha224sum.pl +++ b/tests/misc/sha224sum.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Test "sha224sum". -# Copyright (C) 2005-2013 Free Software Foundation, Inc. +# Copyright (C) 2005-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/sha256sum.pl b/tests/misc/sha256sum.pl index 2ad38e6e..e5f29392 100755 --- a/tests/misc/sha256sum.pl +++ b/tests/misc/sha256sum.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Test "sha256sum". -# Copyright (C) 2005-2013 Free Software Foundation, Inc. +# Copyright (C) 2005-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/sha384sum.pl b/tests/misc/sha384sum.pl index 22e95e15..eafbf5b4 100755 --- a/tests/misc/sha384sum.pl +++ b/tests/misc/sha384sum.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Test "sha384sum". -# Copyright (C) 2005-2013 Free Software Foundation, Inc. +# Copyright (C) 2005-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/sha512sum.pl b/tests/misc/sha512sum.pl index 5e121339..c4a1cd4a 100755 --- a/tests/misc/sha512sum.pl +++ b/tests/misc/sha512sum.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Test "sha512sum". -# Copyright (C) 2005-2013 Free Software Foundation, Inc. +# Copyright (C) 2005-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/shred-exact.sh b/tests/misc/shred-exact.sh index 0cdc91fc..5434229c 100755 --- a/tests/misc/shred-exact.sh +++ b/tests/misc/shred-exact.sh @@ -1,7 +1,7 @@ #!/bin/sh -# make sure that neither --exact nor --zero gobbles a command line argument +# Test functionality of --exact -# Copyright (C) 2000-2013 Free Software Foundation, Inc. +# Copyright (C) 2000-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -20,6 +20,7 @@ print_ver_ shred +# make sure that neither --exact nor --zero gobbles a command line argument for opt in --exact --zero; do echo a > a || fail=1 echo bb > b || fail=1 @@ -33,4 +34,16 @@ for opt in --exact --zero; do test -f c && fail=1 done + +# make sure direct I/O is handled appropriately at end of file +# Create a 1MiB file as we'll probably not be using blocks larger than that +# (i.e. we want to test failed writes not at the start). +truncate -s1MiB file.slop || framework_failure_ +truncate -s+1 file.slop || framework_failure_ +shred --exact -n2 file.slop || fail=1 + +# make sure direct I/O is handled appropriately at start of file +truncate -s1 file.slop || framework_failure_ +shred --exact -n2 file.slop || fail=1 + Exit $fail diff --git a/tests/misc/id-groups.sh b/tests/misc/shred-negative.sh index ff3dc59f..86cbf3e0 100755 --- a/tests/misc/id-groups.sh +++ b/tests/misc/shred-negative.sh @@ -1,6 +1,7 @@ #!/bin/sh -# Ensure that "id" outputs groups for a user -# Copyright (C) 2009-2013 Free Software Foundation, Inc. +# Exercise shred -s-3 FILE + +# Copyright (C) 2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -16,8 +17,12 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src -print_ver_ id +print_ver_ shred + +echo 'shred: -2: invalid file size' > exp || framework_failure_ +echo 1234 > f || framework_failure_ -id -G $(id -nu) || fail=1 +shred -s-2 f 2>err && fail=1 +compare exp err || fail=1 Exit $fail diff --git a/tests/misc/shred-passes.sh b/tests/misc/shred-passes.sh index cfdd68e9..268af950 100755 --- a/tests/misc/shred-passes.sh +++ b/tests/misc/shred-passes.sh @@ -1,7 +1,7 @@ #!/bin/sh # Verify the operations done by shred -# Copyright (C) 2009-2013 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -20,9 +20,9 @@ print_ver_ shred -# shred a single letter, zero length file which should result in +# shred a single letter, which should result in # 3 random passes and a single rename. -touch f || framework_failure_ +printf 1 > f || framework_failure_ echo "\ shred: f: pass 1/3 (random)... shred: f: pass 2/3 (random)... @@ -31,9 +31,21 @@ shred: f: removing shred: f: renamed to 0 shred: f: removed" > exp || framework_failure_ +shred -v -u f 2>out || fail=1 + +compare exp out || fail=1 + +# Likewise but for a zero length file +# to bypass the data passes +touch f || framework_failure_ +echo "\ +shred: f: removing +shred: f: renamed to 0 +shred: f: removed" > exp || framework_failure_ shred -v -u f 2>out || fail=1 compare exp out || fail=1 + Exit $fail diff --git a/tests/misc/shred-remove.sh b/tests/misc/shred-remove.sh index 891dc2d2..9765e352 100755 --- a/tests/misc/shred-remove.sh +++ b/tests/misc/shred-remove.sh @@ -1,7 +1,7 @@ #!/bin/sh -# Exercise a bug that was fixed in shred-4.0l +# Exercise shred --remove -# Copyright (C) 1999-2013 Free Software Foundation, Inc. +# Copyright (C) 1999-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -21,16 +21,27 @@ print_ver_ shred skip_if_root_ # The length of the basename is what matters. -# In this case, shred would try to rename the file 256^10 times +# In this case, shred-4.0l would try to rename the file 256^10 times # before terminating. file=0123456789 touch $file || framework_failure_ chmod u-w $file || framework_failure_ - # This would take so long that it appears to infloop # when using version from fileutils-4.0k. # When the command completes, expect it to fail. -shred -u $file > /dev/null 2>&1 && fail=1 || : +shred -u $file > /dev/null 2>&1 && fail=1 +rm -f $file || framework_failure_ + +# Ensure all --remove methods at least unlink the file +for mode in '' '=unlink' '=wipe' '=wipesync'; do + touch $file || framework_failure_ + shred -n0 --remove"$mode" $file || fail=1 + test -e $file && fail=1 +done + +# Ensure incorrect params are diagnosed +touch $file || framework_failure_ +shred -n0 --remove=none $file 2>/dev/null && fail=1 Exit $fail diff --git a/tests/misc/shuf-reservoir.sh b/tests/misc/shuf-reservoir.sh new file mode 100755 index 00000000..aa9edbea --- /dev/null +++ b/tests/misc/shuf-reservoir.sh @@ -0,0 +1,73 @@ +#!/bin/sh +# Exercise shuf's reservoir-sampling code +# NOTE: +# These tests do not check valid randomness, +# they just check memory allocation related code. + +# Copyright (C) 2013-2014 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ shuf +expensive_ +require_valgrind_ + +# Only exit with error for leaks when in development mode +# in which case we enable code to suppress inconsequential leaks. +grep '^#define lint 1' "$CONFIG_HEADER" && leaklevel=full || leaklevel=summary + +# Run "shuf" with specific number of input lines and output lines +# Check the output for expected number of lines. +run_shuf_n() +{ + INPUT_LINES="$1" + OUTPUT_LINES="$2" + + # Critical memory-related bugs will cause a segfault here + # (with varying numbers of input/output lines) + seq "$INPUT_LINES" | valgrind --leak-check=$leaklevel --error-exitcode=1 \ + shuf -n "$OUTPUT_LINES" -o "out_${INPUT_LINES}_${OUTPUT_LINES}" || return 1 + + EXPECTED_LINES="$OUTPUT_LINES" + test "$INPUT_LINES" -lt "$OUTPUT_LINES" && EXPECTED_LINES="$INPUT_LINES" + + # There is no sure way to verify shuffled output (as it is random). + # Ensure we have the correct number of all numeric lines non duplicated lines. + GOOD_LINES=$(grep '^[0-9][0-9]*$' "out_${INPUT_LINES}_${OUTPUT_LINES}" | + sort -un | wc -l) || framework_failure_ + LINES=$(wc -l < "out_${INPUT_LINES}_${OUTPUT_LINES}") || framework_failure_ + + test "$EXPECTED_LINES" -eq "$GOOD_LINES" || return 1 + test "$EXPECTED_LINES" -eq "$LINES" || return 1 + + return 0 +} + +# Test multiple combinations of input lines and output lines. +# (e.g. small number of input lines and large number of output lines, +# and vice-versa. Also, each reservoir allocation uses a 1024-lines batch, +# so test 1023/1024/1025 and related values). +TEST_LINES="0 1 5 1023 1024 1025 3071 3072 3073" + +for IN_N in $TEST_LINES; do + for OUT_N in $TEST_LINES; do + run_shuf_n "$IN_N" "$OUT_N" || { + fail=1 + echo "shuf-reservoir-sampling failed with IN_N=$IN_N OUT_N=$OUT_N" >&2; + } + done +done + +Exit $fail diff --git a/tests/misc/shuf.sh b/tests/misc/shuf.sh index 9c9526d4..d7251d1d 100755 --- a/tests/misc/shuf.sh +++ b/tests/misc/shuf.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure that shuf randomizes its input. -# Copyright (C) 2006-2013 Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -43,6 +43,10 @@ compare in out1 || { fail=1; echo "not a permutation" 1>&2; } t=$(shuf -e a b c d e | sort | fmt) test "$t" = 'a b c d e' || { fail=1; echo "not a permutation" 1>&2; } +# coreutils-8.22 dumps core. +shuf -er +test $? -eq 1 || fail=1 + # Before coreutils-6.3, this would infloop. # "seq 1860" produces 8193 (8K + 1) bytes of output. seq 1860 | shuf > /dev/null || fail=1 @@ -57,4 +61,104 @@ cmp out exp || { fail=1; echo "missing NUL terminator?" 1>&2; } timeout 10 shuf -i1-$SIZE_MAX -n2 >/dev/null || { fail=1; echo "couldn't get a small subset" >&2; } +# Ensure shuf -n0 doesn't read any input or open specified files +touch unreadable || framework_failure_ +chmod 0 unreadable || framework_failure_ +if ! test -r unreadable; then + shuf -n0 unreadable || fail=1 + shuf -n1 unreadable && fail=1 +fi + +# Multiple -n is accepted, should use the smallest value +shuf -n10 -i0-9 -n3 -n20 > exp || framework_failure_ +c=$(wc -l < exp) || framework_failure_ +test "$c" -eq 3 || { fail=1; echo "Multiple -n failed">&2 ; } + +# Test error conditions + +# -i and -e must not be used together +: | shuf -i0-9 -e A B && + { fail=1; echo "shuf did not detect erroneous -e and -i usage.">&2 ; } +# Test invalid value for -n +: | shuf -nA && + { fail=1; echo "shuf did not detect erroneous -n usage.">&2 ; } +# Test multiple -i +shuf -i0-9 -n10 -i8-90 && + { fail=1; echo "shuf did not detect multiple -i usage.">&2 ; } +# Test invalid range +for ARG in '1' 'A' '1-' '1-A'; do + shuf -i$ARG && + { fail=1; echo "shuf did not detect erroneous -i$ARG usage.">&2 ; } +done + +# multiple -o are forbidden +shuf -i0-9 -o A -o B && + { fail=1; echo "shuf did not detect erroneous multiple -o usage.">&2 ; } +# multiple random-sources are forbidden +shuf -i0-9 --random-source A --random-source B && + { fail=1; echo "shuf did not detect multiple --random-source usage.">&2 ; } + +# Test --repeat option + +# --repeat without count should return an indefinite number of lines +shuf --rep -i 0-10 | head -n 1000 > exp || framework_failure_ +c=$(wc -l < exp) || framework_failure_ +test "$c" -eq 1000 \ + || { fail=1; echo "--repeat does not repeat indefinitely">&2 ; } + +# --repeat can output more values than the input range +shuf --rep -i0-9 -n1000 > exp || framework_failure_ +c=$(wc -l < exp) || framework_failure_ +test "$c" -eq 1000 || { fail=1; echo "--repeat with --count failed">&2 ; } + +# Check output values (this is not bullet-proof, but drawing 1000 values +# between 0 and 9 should produce all values, unless there's a bug in shuf +# or a very poor random source, or extremely bad luck) +c=$(sort -nu exp | paste -s -d ' ') || framework_failure_ +test "$c" = "0 1 2 3 4 5 6 7 8 9" || + { fail=1; echo "--repeat produced bad output">&2 ; } + +# check --repeat with non-zero low value +shuf --rep -i222-233 -n2000 > exp || framework_failure_ +c=$(cat exp | sort -nu | paste -s -d ' ') || framework_failure_ +test "$c" = "222 223 224 225 226 227 228 229 230 231 232 233" || + { fail=1; echo "--repeat produced bad output with non-zero low">&2 ; } + +# --repeat,-i,count=0 should not fail and produce no output +shuf --rep -i0-9 -n0 > exp || framework_failure_ +# file size should be zero (no output from shuf) +test \! -s exp || + { fail=1; echo "--repeat,-i0-9,-n0 produced bad output">&2 ; } + +# --repeat with -e, without count, should repeat indefinitely +shuf --rep -e A B C D | head -n 1000 > exp || framework_failure_ +c=$(wc -l < exp) || framework_failure_ +test "$c" -eq 1000 || + { fail=1; echo "--repeat,-e does not repeat indefinitely">&2 ; } + +# --repeat with STDIN, without count, should repeat indefinitely +printf "A\nB\nC\nD\nE\n" | shuf --rep | head -n 1000 > exp || framework_failure_ +c=$(wc -l < exp) || framework_failure_ +test "$c" -eq 1000 || + { fail=1; echo "--repeat,STDIN does not repeat indefinitely">&2 ; } + +# --repeat with STDIN,count - can return move values than input lines +printf "A\nB\nC\nD\nE\n" | shuf --rep -n2000 > exp || framework_failure_ +c=$(wc -l < exp) || framework_failure_ +test "$c" -eq 2000 || + { fail=1; echo "--repeat,STDIN,count failed">&2 ; } + +# Check output values (this is not bullet-proof, but drawing 2000 values +# between A and E should produce all values, unless there's a bug in shuf +# or a very poor random source, or extremely bad luck) +c=$(sort -u exp | paste -s -d ' ') || framework_failure_ +test "$c" = "A B C D E" || + { fail=1; echo "--repeat,STDIN,count produced bad output">&2 ; } + +# --repeat,stdin,count=0 should not fail and produce no output +printf "A\nB\nC\nD\nE\n" | shuf --rep -n0 > exp || framework_failure_ +# file size should be zero (no output from shuf) +test \! -s exp || + { fail=1; echo "--repeat,STDIN,-n0 produced bad output">&2 ; } + Exit $fail diff --git a/tests/misc/sort-NaN-infloop.sh b/tests/misc/sort-NaN-infloop.sh index 2ec13ee0..9c6e021a 100755 --- a/tests/misc/sort-NaN-infloop.sh +++ b/tests/misc/sort-NaN-infloop.sh @@ -1,7 +1,7 @@ #!/bin/sh # exercise the NaN-infloop bug in coreutils-8.13 -# Copyright (C) 2011-2013 Free Software Foundation, Inc. +# Copyright (C) 2011-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/sort-benchmark-random.sh b/tests/misc/sort-benchmark-random.sh index 04f2af99..c074301f 100755 --- a/tests/misc/sort-benchmark-random.sh +++ b/tests/misc/sort-benchmark-random.sh @@ -1,7 +1,7 @@ #!/bin/sh # Benchmark sort on randomly generated data. -# Copyright (C) 2010-2013 Free Software Foundation, Inc. +# Copyright (C) 2010-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/sort-compress-hang.sh b/tests/misc/sort-compress-hang.sh index 1b1f3a9c..cc1e6d36 100755 --- a/tests/misc/sort-compress-hang.sh +++ b/tests/misc/sort-compress-hang.sh @@ -1,7 +1,7 @@ #!/bin/sh # Test for sort --compress hang -# Copyright (C) 2010-2013 Free Software Foundation, Inc. +# Copyright (C) 2010-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/sort-compress-proc.sh b/tests/misc/sort-compress-proc.sh index 3888fdb6..d06eb56f 100755 --- a/tests/misc/sort-compress-proc.sh +++ b/tests/misc/sort-compress-proc.sh @@ -1,7 +1,7 @@ #!/bin/sh # Test use of compression subprocesses by sort -# Copyright (C) 2010-2013 Free Software Foundation, Inc. +# Copyright (C) 2010-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/sort-compress.sh b/tests/misc/sort-compress.sh index c7587c43..8f215b8b 100755 --- a/tests/misc/sort-compress.sh +++ b/tests/misc/sort-compress.sh @@ -1,7 +1,7 @@ #!/bin/sh # Test use of compression by sort -# Copyright (C) 2007-2013 Free Software Foundation, Inc. +# Copyright (C) 2007-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -39,7 +39,7 @@ chmod +x gzip # Use a subshell and an exec to work around a bug in FreeBSD 5.0 /bin/sh. ( # ash doesn't support "trap '' CHLD"; it knows only signal numbers. - sig=$("$abs_top_builddir/src/kill" -l CHLD 2>/dev/null) && trap '' $sig + sig=$(env kill -l CHLD 2>/dev/null) && trap '' $sig # This should force the use of child processes for "compression" PATH=.:$PATH exec sort -S 1k --compress-program=gzip in > /dev/null diff --git a/tests/misc/sort-continue.sh b/tests/misc/sort-continue.sh index bd569d0d..1c4030d9 100755 --- a/tests/misc/sort-continue.sh +++ b/tests/misc/sort-continue.sh @@ -1,7 +1,7 @@ #!/bin/sh # Tests for file descriptor exhaustion. -# Copyright (C) 2009-2013 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/sort-debug-keys.sh b/tests/misc/sort-debug-keys.sh index 9d4f8295..ff1e19b6 100755 --- a/tests/misc/sort-debug-keys.sh +++ b/tests/misc/sort-debug-keys.sh @@ -1,7 +1,7 @@ #!/bin/sh # Test annotation of sort keys -# Copyright (C) 2010-2013 Free Software Foundation, Inc. +# Copyright (C) 2010-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/sort-debug-warn.sh b/tests/misc/sort-debug-warn.sh index c9f1b9f3..fd16829b 100755 --- a/tests/misc/sort-debug-warn.sh +++ b/tests/misc/sort-debug-warn.sh @@ -1,7 +1,7 @@ #!/bin/sh # Test warnings for sort options -# Copyright (C) 2010-2013 Free Software Foundation, Inc. +# Copyright (C) 2010-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/sort-discrim.sh b/tests/misc/sort-discrim.sh index 0dac3a9d..e3cd1907 100755 --- a/tests/misc/sort-discrim.sh +++ b/tests/misc/sort-discrim.sh @@ -1,7 +1,7 @@ #!/bin/sh # Test discriminator-based sorting. -# Copyright (C) 2012-2013 Free Software Foundation, Inc. +# Copyright (C) 2012-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/sort-exit-early.sh b/tests/misc/sort-exit-early.sh index 83a55f51..2a70253e 100755 --- a/tests/misc/sort-exit-early.sh +++ b/tests/misc/sort-exit-early.sh @@ -1,7 +1,7 @@ #!/bin/sh # Test 'sort' exits early on inaccessible inputs or output -# Copyright (C) 2012-2013 Free Software Foundation, Inc. +# Copyright (C) 2012-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/sort-files0-from.pl b/tests/misc/sort-files0-from.pl index d843b646..77c1b1aa 100755 --- a/tests/misc/sort-files0-from.pl +++ b/tests/misc/sort-files0-from.pl @@ -2,7 +2,7 @@ # Exercise sort's --files0-from option. # FIXME: keep this file in sync with tests/du/files0-from. -# Copyright (C) 2006-2013 Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/sort-float.sh b/tests/misc/sort-float.sh index dd3c079c..7a4e8292 100755 --- a/tests/misc/sort-float.sh +++ b/tests/misc/sort-float.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure sort -g sorts floating point limits correctly -# Copyright (C) 2010-2013 Free Software Foundation, Inc. +# Copyright (C) 2010-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/sort-merge-fdlimit.sh b/tests/misc/sort-merge-fdlimit.sh index bcd023ae..0df7aa66 100755 --- a/tests/misc/sort-merge-fdlimit.sh +++ b/tests/misc/sort-merge-fdlimit.sh @@ -2,7 +2,7 @@ # Test whether sort avoids opening more file descriptors than it is # allowed when merging files. -# Copyright (C) 2009-2013 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -19,7 +19,6 @@ . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src print_ver_ sort -require_ulimit_ mkdir in err || framework_failure_ diff --git a/tests/misc/sort-merge.pl b/tests/misc/sort-merge.pl index 5b940f25..06e3c15f 100755 --- a/tests/misc/sort-merge.pl +++ b/tests/misc/sort-merge.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Test "sort -m". -# Copyright (C) 2002-2013 Free Software Foundation, Inc. +# Copyright (C) 2002-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/sort-month.sh b/tests/misc/sort-month.sh index 99008367..40c814da 100755 --- a/tests/misc/sort-month.sh +++ b/tests/misc/sort-month.sh @@ -1,7 +1,7 @@ #!/bin/sh # Test sorting of abbreviated months from the locale -# Copyright (C) 2010-2013 Free Software Foundation, Inc. +# Copyright (C) 2010-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/sort-rand.sh b/tests/misc/sort-rand.sh index 4313eb2f..2397fb4b 100755 --- a/tests/misc/sort-rand.sh +++ b/tests/misc/sort-rand.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure that sort --sort-random doesn't sort. -# Copyright (C) 2005-2013 Free Software Foundation, Inc. +# Copyright (C) 2005-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/sort-spinlock-abuse.sh b/tests/misc/sort-spinlock-abuse.sh index 768fc1f4..49ed920f 100755 --- a/tests/misc/sort-spinlock-abuse.sh +++ b/tests/misc/sort-spinlock-abuse.sh @@ -2,7 +2,7 @@ # trigger a bug that would make parallel sort use 100% of one or more # CPU while blocked on output. -# Copyright (C) 2010-2013 Free Software Foundation, Inc. +# Copyright (C) 2010-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/sort-stale-thread-mem.sh b/tests/misc/sort-stale-thread-mem.sh index 78fa2cda..78defd23 100755 --- a/tests/misc/sort-stale-thread-mem.sh +++ b/tests/misc/sort-stale-thread-mem.sh @@ -1,7 +1,7 @@ #!/bin/sh # Trigger a bug that would cause 'sort' to reference stale thread stack memory. -# Copyright (C) 2010-2013 Free Software Foundation, Inc. +# Copyright (C) 2010-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/sort-u-FMR.sh b/tests/misc/sort-u-FMR.sh index c13e9823..3019cbe8 100755 --- a/tests/misc/sort-u-FMR.sh +++ b/tests/misc/sort-u-FMR.sh @@ -1,7 +1,7 @@ #!/bin/sh # Before 8.19, this would trigger a free-memory read. -# Copyright (C) 2012-2013 Free Software Foundation, Inc. +# Copyright (C) 2012-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/sort-unique-segv.sh b/tests/misc/sort-unique-segv.sh index 58893158..148dc243 100755 --- a/tests/misc/sort-unique-segv.sh +++ b/tests/misc/sort-unique-segv.sh @@ -1,7 +1,7 @@ #!/bin/sh # parallel sort with --unique (-u) would segfault -# Copyright (C) 2010-2013 Free Software Foundation, Inc. +# Copyright (C) 2010-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/sort-unique.sh b/tests/misc/sort-unique.sh index f34df96e..d7a7629c 100755 --- a/tests/misc/sort-unique.sh +++ b/tests/misc/sort-unique.sh @@ -1,7 +1,7 @@ #!/bin/sh # Test 'sort -u'. -# Copyright (C) 2010-2013 Free Software Foundation, Inc. +# Copyright (C) 2010-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/sort-version.sh b/tests/misc/sort-version.sh index d9686fbe..d8db1e1c 100755 --- a/tests/misc/sort-version.sh +++ b/tests/misc/sort-version.sh @@ -1,7 +1,7 @@ #!/bin/sh # exercise sort's --sort=version option -# Copyright (C) 2008-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/sort.pl b/tests/misc/sort.pl index 59c30e56..db732094 100755 --- a/tests/misc/sort.pl +++ b/tests/misc/sort.pl @@ -1,6 +1,6 @@ #!/usr/bin/perl -# Copyright (C) 2008-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/stat-birthtime.sh b/tests/misc/stat-birthtime.sh index b30c972b..f06ddea8 100755 --- a/tests/misc/stat-birthtime.sh +++ b/tests/misc/stat-birthtime.sh @@ -1,7 +1,7 @@ #!/bin/sh # ensure that stat attempts birthtime access -# Copyright (C) 2010-2013 Free Software Foundation, Inc. +# Copyright (C) 2010-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/stat-fmt.sh b/tests/misc/stat-fmt.sh index 547f5b8f..3982f23b 100755 --- a/tests/misc/stat-fmt.sh +++ b/tests/misc/stat-fmt.sh @@ -1,7 +1,7 @@ #!/bin/sh # ensure that stat properly handles a format string ending with % -# Copyright (C) 2003-2013 Free Software Foundation, Inc. +# Copyright (C) 2003-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/stat-hyphen.sh b/tests/misc/stat-hyphen.sh index a817b285..9f090a0f 100755 --- a/tests/misc/stat-hyphen.sh +++ b/tests/misc/stat-hyphen.sh @@ -1,7 +1,7 @@ #!/bin/sh # demonstrate that stat - works and stat -f - does not. -# Copyright (C) 2009-2013 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/stat-mount.sh b/tests/misc/stat-mount.sh index f94c77cb..ab1ff479 100755 --- a/tests/misc/stat-mount.sh +++ b/tests/misc/stat-mount.sh @@ -1,7 +1,7 @@ #!/bin/sh # Test stat -c%m -# Copyright (C) 2010-2013 Free Software Foundation, Inc. +# Copyright (C) 2010-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -19,8 +19,10 @@ . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src print_ver_ stat -df_mnt=$(df -P . | sed -n '2s/.* \([^ ]*$\)/\1/p') stat_mnt=$(stat -c%m .) || fail=1 -test "$stat_mnt" || fail=1 +case "$stat_mnt" in + /*) ;; + *) fail=1;; +esac Exit $fail diff --git a/tests/misc/stat-nanoseconds.sh b/tests/misc/stat-nanoseconds.sh index 9c891b76..30c47c02 100755 --- a/tests/misc/stat-nanoseconds.sh +++ b/tests/misc/stat-nanoseconds.sh @@ -1,7 +1,7 @@ #!/bin/sh # Exercise format strings involving %:X, %:Y, etc. -# Copyright (C) 2010-2013 Free Software Foundation, Inc. +# Copyright (C) 2010-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/stat-printf.pl b/tests/misc/stat-printf.pl index fb31043f..5021130d 100755 --- a/tests/misc/stat-printf.pl +++ b/tests/misc/stat-printf.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Test "stat --printf". -# Copyright (C) 2005-2013 Free Software Foundation, Inc. +# Copyright (C) 2005-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/stat-slash.sh b/tests/misc/stat-slash.sh index 47aa7907..465de2ed 100755 --- a/tests/misc/stat-slash.sh +++ b/tests/misc/stat-slash.sh @@ -1,7 +1,7 @@ #!/bin/sh # demonstrate that stat handles trailing slashes correctly -# Copyright (C) 2009-2013 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/stdbuf.sh b/tests/misc/stdbuf.sh index 12347ecc..e0ca3530 100755 --- a/tests/misc/stdbuf.sh +++ b/tests/misc/stdbuf.sh @@ -1,7 +1,7 @@ #!/bin/sh # Exercise stdbuf functionality -# Copyright (C) 2009-2013 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -50,6 +50,8 @@ stdbuf -o$SIZE_OFLOW true # size too large test $? = 125 || fail=1 stdbuf -iL true # line buffering stdin disallowed test $? = 125 || fail=1 +stdbuf true # a buffering mode must be specified +test $? = 125 || fail=1 stdbuf -i0 -o0 -e0 true || fail=1 #check all files stdbuf -o1 . # invalid command test $? = 126 || fail=1 diff --git a/tests/misc/stty-invalid.sh b/tests/misc/stty-invalid.sh index c6400fcf..36bc8aa0 100755 --- a/tests/misc/stty-invalid.sh +++ b/tests/misc/stty-invalid.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure that stty diagnoses invalid inputs, rather than silently misbehaving. -# Copyright (C) 2007-2013 Free Software Foundation, Inc. +# Copyright (C) 2007-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/stty-pairs.sh b/tests/misc/stty-pairs.sh index be5b6f84..1a7c26cf 100755 --- a/tests/misc/stty-pairs.sh +++ b/tests/misc/stty-pairs.sh @@ -1,7 +1,7 @@ #!/bin/sh # Make sure stty can parse most of its options - in pairs [expensive]. -# Copyright (C) 1998-2013 Free Software Foundation, Inc. +# Copyright (C) 1998-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/stty-row-col.sh b/tests/misc/stty-row-col.sh index 586674ad..729d6f91 100755 --- a/tests/misc/stty-row-col.sh +++ b/tests/misc/stty-row-col.sh @@ -1,7 +1,7 @@ #! /bin/sh # Test "stty" with rows and columns. -# Copyright (C) 1998-2013 Free Software Foundation, Inc. +# Copyright (C) 1998-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/stty.sh b/tests/misc/stty.sh index 2f9b9a3b..ab1c78de 100755 --- a/tests/misc/stty.sh +++ b/tests/misc/stty.sh @@ -1,7 +1,7 @@ #! /bin/sh # Make sure stty can parse most of its options. -# Copyright (C) 1998-2013 Free Software Foundation, Inc. +# Copyright (C) 1998-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -52,7 +52,10 @@ for opt in $options; do # other serial control settings give the same error. So skip them. # Also on ppc*|sparc* glibc platforms 'icanon' gives the same error. # See: http://debbugs.gnu.org/7228#14 - case $opt in parenb|parodd|cstopb|crtscts|cdtrdsr|icanon) continue;; esac + case $opt in + parenb|parodd|cmspar) continue;; + cstopb|crtscts|cdtrdsr|icanon) continue;; + esac stty $opt || fail=1 diff --git a/tests/misc/sum-sysv.sh b/tests/misc/sum-sysv.sh index a1e8cee9..7624685f 100755 --- a/tests/misc/sum-sysv.sh +++ b/tests/misc/sum-sysv.sh @@ -1,7 +1,7 @@ #!/bin/sh # make sure 'sum -s' works for input whose sum of bytes is larger than 2^32 -# Copyright (C) 2001-2013 Free Software Foundation, Inc. +# Copyright (C) 2001-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/sum.pl b/tests/misc/sum.pl index 3cabcc53..696eda4b 100755 --- a/tests/misc/sum.pl +++ b/tests/misc/sum.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Test "sum". -# Copyright (C) 2000-2013 Free Software Foundation, Inc. +# Copyright (C) 2000-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/tac-2-nonseekable.sh b/tests/misc/tac-2-nonseekable.sh index ef434807..c27694c1 100755 --- a/tests/misc/tac-2-nonseekable.sh +++ b/tests/misc/tac-2-nonseekable.sh @@ -1,7 +1,7 @@ #!/bin/sh # ensure that tac works with two or more non-seekable inputs -# Copyright (C) 2011-2013 Free Software Foundation, Inc. +# Copyright (C) 2011-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/tac-continue.sh b/tests/misc/tac-continue.sh index 95f37d7b..d4280650 100755 --- a/tests/misc/tac-continue.sh +++ b/tests/misc/tac-continue.sh @@ -3,7 +3,7 @@ # when it encounters an error with say the first one. # With coreutils-5.2.1 and earlier, this test would fail. -# Copyright (C) 2004-2013 Free Software Foundation, Inc. +# Copyright (C) 2004-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/tac.pl b/tests/misc/tac.pl index b064b9d2..0f21affd 100755 --- a/tests/misc/tac.pl +++ b/tests/misc/tac.pl @@ -1,6 +1,6 @@ #!/usr/bin/perl -# Copyright (C) 2008-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/tail.pl b/tests/misc/tail.pl index bc6e6d4a..6798eb05 100755 --- a/tests/misc/tail.pl +++ b/tests/misc/tail.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Test tail. -# Copyright (C) 2008-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/tee-dash.sh b/tests/misc/tee-dash.sh index 9e511beb..761a4780 100755 --- a/tests/misc/tee-dash.sh +++ b/tests/misc/tee-dash.sh @@ -1,7 +1,7 @@ #!/bin/sh # test for "tee -". -# Copyright (C) 2005-2013 Free Software Foundation, Inc. +# Copyright (C) 2005-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/tee.sh b/tests/misc/tee.sh index bbaf99b7..f0072bfd 100755 --- a/tests/misc/tee.sh +++ b/tests/misc/tee.sh @@ -1,7 +1,7 @@ #!/bin/sh # test for basic tee functionality. -# Copyright (C) 2005-2013 Free Software Foundation, Inc. +# Copyright (C) 2005-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/test-diag.pl b/tests/misc/test-diag.pl index 81ab60d8..14d0f4d5 100755 --- a/tests/misc/test-diag.pl +++ b/tests/misc/test-diag.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Test the diagnostics of "test". -# Copyright (C) 2006-2013 Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/test.pl b/tests/misc/test.pl index ee9150d7..b27adb48 100755 --- a/tests/misc/test.pl +++ b/tests/misc/test.pl @@ -1,6 +1,6 @@ #!/usr/bin/perl -# Copyright (C) 2008-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/timeout-blocked.pl b/tests/misc/timeout-blocked.pl index 6f16ba4c..b5f31c96 100755 --- a/tests/misc/timeout-blocked.pl +++ b/tests/misc/timeout-blocked.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Test that timeout handles blocked SIGALRM from its parent. -# Copyright (C) 2013 Free Software Foundation, Inc. +# Copyright (C) 2013-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/timeout-group.sh b/tests/misc/timeout-group.sh index 35a6be0b..23c1b065 100755 --- a/tests/misc/timeout-group.sh +++ b/tests/misc/timeout-group.sh @@ -1,7 +1,7 @@ #!/bin/sh # test program group handling -# Copyright (C) 2011-2013 Free Software Foundation, Inc. +# Copyright (C) 2011-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/timeout-parameters.sh b/tests/misc/timeout-parameters.sh index 06cdfb39..fca30f0b 100755 --- a/tests/misc/timeout-parameters.sh +++ b/tests/misc/timeout-parameters.sh @@ -1,7 +1,7 @@ #!/bin/sh # Validate timeout parameter combinations -# Copyright (C) 2008-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/timeout.sh b/tests/misc/timeout.sh index 6b5a6f10..8eaeef95 100755 --- a/tests/misc/timeout.sh +++ b/tests/misc/timeout.sh @@ -1,7 +1,7 @@ #!/bin/sh # Validate timeout basic operation -# Copyright (C) 2008-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -51,7 +51,7 @@ test $? = 124 && fail=1 # Use a subshell and an exec to work around a bug in FreeBSD 5.0 /bin/sh. ( # ash doesn't support "trap '' CHLD"; it knows only signal numbers. - sig=$("$abs_top_builddir/src/kill" -l CHLD 2>/dev/null) && trap '' $sig + sig=$(env kill -l CHLD 2>/dev/null) && trap '' $sig exec timeout 10 true ) || fail=1 diff --git a/tests/misc/tr-case-class.sh b/tests/misc/tr-case-class.sh index 1294f965..952aae45 100755 --- a/tests/misc/tr-case-class.sh +++ b/tests/misc/tr-case-class.sh @@ -1,7 +1,7 @@ #!/bin/sh # Test case conversion classes -# Copyright (C) 2010-2013 Free Software Foundation, Inc. +# Copyright (C) 2010-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/tr.pl b/tests/misc/tr.pl index 89693f91..e7018e79 100755 --- a/tests/misc/tr.pl +++ b/tests/misc/tr.pl @@ -1,6 +1,6 @@ #!/usr/bin/perl -# Copyright (C) 2008-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/truncate-dangling-symlink.sh b/tests/misc/truncate-dangling-symlink.sh index 5386ce2d..c5bbc3b6 100755 --- a/tests/misc/truncate-dangling-symlink.sh +++ b/tests/misc/truncate-dangling-symlink.sh @@ -1,7 +1,7 @@ #!/bin/sh # Make sure truncate can create a file through a dangling symlink. -# Copyright (C) 2008-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/truncate-dir-fail.sh b/tests/misc/truncate-dir-fail.sh index 8bd67b6e..8ff09179 100755 --- a/tests/misc/truncate-dir-fail.sh +++ b/tests/misc/truncate-dir-fail.sh @@ -1,7 +1,7 @@ #!/bin/sh # Make sure truncate fails for a directory. -# Copyright (C) 2008-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/truncate-fail-diag.sh b/tests/misc/truncate-fail-diag.sh index 8e5f07ba..9f242d34 100755 --- a/tests/misc/truncate-fail-diag.sh +++ b/tests/misc/truncate-fail-diag.sh @@ -5,7 +5,7 @@ # open ("missing/", O_CREAT & (O_WRONLY | O_RDWR), ...) -> EISDIR # open ("missing/file", O_CREAT & (O_WRONLY | O_RDWR), ...) -> ENOENT -# Copyright (C) 2008-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/truncate-fifo.sh b/tests/misc/truncate-fifo.sh index 58e5c14e..c2c0bbfc 100755 --- a/tests/misc/truncate-fifo.sh +++ b/tests/misc/truncate-fifo.sh @@ -1,7 +1,7 @@ #!/bin/sh # Make sure truncate works on fifos without hanging -# Copyright (C) 2008-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/truncate-no-create-missing.sh b/tests/misc/truncate-no-create-missing.sh index 6fa1f0c6..1cf55330 100755 --- a/tests/misc/truncate-no-create-missing.sh +++ b/tests/misc/truncate-no-create-missing.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure that truncate -c no-such-file doesn't fail. -# Copyright (C) 2008-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/truncate-overflow.sh b/tests/misc/truncate-overflow.sh index dd0fc730..72ed626b 100755 --- a/tests/misc/truncate-overflow.sh +++ b/tests/misc/truncate-overflow.sh @@ -1,7 +1,7 @@ #!/bin/sh # Validate truncate integer overflow -# Copyright (C) 2008-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/truncate-owned-by-other.sh b/tests/misc/truncate-owned-by-other.sh index e7f7157c..e70badb6 100755 --- a/tests/misc/truncate-owned-by-other.sh +++ b/tests/misc/truncate-owned-by-other.sh @@ -1,7 +1,7 @@ #!/bin/sh # Demonstrate that "truncate -s0 writable-but-owned-by-other" works. -# Copyright (C) 2008-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -21,16 +21,15 @@ print_ver_ truncate require_root_ -group_num=$(id -g $NON_ROOT_USERNAME) - # Create a file owned by root, and writable by $NON_ROOT_USERNAME. echo > root-owned || framework_failure_ -chgrp +$group_num . root-owned || framework_failure_ +chgrp +$NON_ROOT_GID . root-owned || framework_failure_ chmod g+w root-owned # Ensure that the current directory is searchable by $NON_ROOT_USERNAME. chmod g+x . -setuidgid $NON_ROOT_USERNAME env PATH="$PATH" truncate -s0 root-owned || fail=1 +chroot --user=$NON_ROOT_USERNAME / env PATH="$PATH" \ + truncate -s0 root-owned || fail=1 Exit $fail diff --git a/tests/misc/truncate-parameters.sh b/tests/misc/truncate-parameters.sh index 21713d99..d9e6d64d 100755 --- a/tests/misc/truncate-parameters.sh +++ b/tests/misc/truncate-parameters.sh @@ -1,7 +1,7 @@ #!/bin/sh # Validate truncate parameter combinations -# Copyright (C) 2008-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/truncate-relative.sh b/tests/misc/truncate-relative.sh index fbbd4f97..3daa073e 100755 --- a/tests/misc/truncate-relative.sh +++ b/tests/misc/truncate-relative.sh @@ -1,7 +1,7 @@ #!/bin/sh # Validate truncate relative sizes -# Copyright (C) 2008-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/tsort.pl b/tests/misc/tsort.pl index 5e598c74..e59af328 100755 --- a/tests/misc/tsort.pl +++ b/tests/misc/tsort.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Test "tsort". -# Copyright (C) 1999-2013 Free Software Foundation, Inc. +# Copyright (C) 1999-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/tty-eof.pl b/tests/misc/tty-eof.pl index 755ffac0..b4d36de6 100755 --- a/tests/misc/tty-eof.pl +++ b/tests/misc/tty-eof.pl @@ -4,7 +4,7 @@ # Do the same for all programs that can read stdin, # require no arguments and that write to standard output. -# Copyright (C) 2003-2013 Free Software Foundation, Inc. +# Copyright (C) 2003-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/unexpand.pl b/tests/misc/unexpand.pl index a1ce5c52..8c5b693b 100755 --- a/tests/misc/unexpand.pl +++ b/tests/misc/unexpand.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Test "unexpand". -# Copyright (C) 2000-2013 Free Software Foundation, Inc. +# Copyright (C) 2000-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/uniq-perf.sh b/tests/misc/uniq-perf.sh index 35dff8e5..31c40e53 100755 --- a/tests/misc/uniq-perf.sh +++ b/tests/misc/uniq-perf.sh @@ -1,7 +1,7 @@ #!/bin/sh # before coreutils-8.10, seq 100000|uniq -f 10000000000 would run for days -# Copyright (C) 2011-2013 Free Software Foundation, Inc. +# Copyright (C) 2011-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/uniq.pl b/tests/misc/uniq.pl index 140a49b4..d07f15f1 100755 --- a/tests/misc/uniq.pl +++ b/tests/misc/uniq.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Test uniq. -# Copyright (C) 2008-2013 Free Software Foundation, Inc. +# Copyright (C) 2008-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -80,23 +80,8 @@ sub add_z_variants($) return @new; } -# I've only ever triggered the problem in a non-C locale. -my $locale = $ENV{LOCALE_FR}; -! defined $locale || $locale eq 'none' - and CuSkip::skip "$prog: skipping this test -- no appropriate locale\n"; - -# See if isblank returns true for nbsp. -my $x = qx!env printf '\xa0'| LC_ALL=$locale tr '[:blank:]' x!; -# If so, expect just one line of output in the schar test. -# Otherwise, expect two. -my $in = " y z\n\xa0 y z\n"; -my $schar_exp = $x eq 'x' ? " y z\n" : $in; - my @Tests = ( - # Test for a subtle, system-and-locale-dependent bug in uniq. - ['schar', '-f1', {IN => $in}, {OUT => $schar_exp}, - {ENV => "LC_ALL=$locale"}], ['1', '', {IN=>''}, {OUT=>''}], ['2', '', {IN=>"a\na\n"}, {OUT=>"a\n"}], ['3', '', {IN=>"a\na"}, {OUT=>"a\n"}], @@ -199,8 +184,76 @@ my @Tests = # Check that --zero-terminated is synonymous with -z. ['123', '--zero-terminated', {IN=>"a\na\nb"}, {OUT=>"a\na\nb\0"}], ['124', '--zero-terminated', {IN=>"a\0a\0b"}, {OUT=>"a\0b\0"}], + # Check ignore-case + ['125', '', {IN=>"A\na\n"}, {OUT=>"A\na\n"}], + ['126', '-i', {IN=>"A\na\n"}, {OUT=>"A\n"}], + ['127', '--ignore-case', {IN=>"A\na\n"}, {OUT=>"A\n"}], + # Check grouping + ['128', '--group=prepend', {IN=>"a\na\nb\n"}, {OUT=>"\na\na\n\nb\n"}], + ['129', '--group=append', {IN=>"a\na\nb\n"}, {OUT=>"a\na\n\nb\n\n"}], + ['130', '--group=separate',{IN=>"a\na\nb\n"}, {OUT=>"a\na\n\nb\n"}], + # no explicit grouping = separate + ['131', '--group', {IN=>"a\na\nb\n"}, {OUT=>"a\na\n\nb\n"}], + ['132', '--group=both', {IN=>"a\na\nb\n"}, {OUT=>"\na\na\n\nb\n\n"}], + # Grouping in the special case of a single group + ['133', '--group=prepend', {IN=>"a\na\n"}, {OUT=>"\na\na\n"}], + ['134', '--group=append', {IN=>"a\na\n"}, {OUT=>"a\na\n\n"}], + ['135', '--group=separate',{IN=>"a\na\n"}, {OUT=>"a\na\n"}], + ['136', '--group', {IN=>"a\na\n"}, {OUT=>"a\na\n"}], + # Grouping with empty input - should never print anything + ['137', '--group=prepend', {IN=>""}, {OUT=>""}], + ['138', '--group=append', {IN=>""}, {OUT=>""}], + ['139', '--group=separate', {IN=>""}, {OUT=>""}], + ['140', '--group=both', {IN=>""}, {OUT=>""}], + # Grouping with other options - must fail + ['141', '--group -c', {IN=>""}, {OUT=>""}, {EXIT=>1}, + {ERR=>"$prog: --group is mutually exclusive with -c/-d/-D/-u\n" . + "Try 'uniq --help' for more information.\n"}], + ['142', '--group -d', {IN=>""}, {OUT=>""}, {EXIT=>1}, + {ERR=>"$prog: --group is mutually exclusive with -c/-d/-D/-u\n" . + "Try 'uniq --help' for more information.\n"}], + ['143', '--group -u', {IN=>""}, {OUT=>""}, {EXIT=>1}, + {ERR=>"$prog: --group is mutually exclusive with -c/-d/-D/-u\n" . + "Try 'uniq --help' for more information.\n"}], + ['144', '--group -D', {IN=>""}, {OUT=>""}, {EXIT=>1}, + {ERR=>"$prog: --group is mutually exclusive with -c/-d/-D/-u\n" . + "Try 'uniq --help' for more information.\n"}], + # Grouping with badoption + ['145', '--group=badoption',{IN=>""}, {OUT=>""}, {EXIT=>1}, + {ERR=>"$prog: invalid argument 'badoption' for '--group'\n" . + "Valid arguments are:\n" . + " - 'prepend'\n" . + " - 'append'\n" . + " - 'separate'\n" . + " - 'both'\n" . + "Try '$prog --help' for more information.\n"}], ); +# Locale related tests + +my $locale = $ENV{LOCALE_FR}; +if ( defined $locale && $locale ne 'none' ) + { + # I've only ever triggered the problem in a non-C locale. + + # See if isblank returns true for nbsp. + my $x = qx!env printf '\xa0'| LC_ALL=$locale tr '[:blank:]' x!; + # If so, expect just one line of output in the schar test. + # Otherwise, expect two. + my $in = " y z\n\xa0 y z\n"; + my $schar_exp = $x eq 'x' ? " y z\n" : $in; + + my @Locale_Tests = + ( + # Test for a subtle, system-and-locale-dependent bug in uniq. + ['schar', '-f1', {IN => $in}, {OUT => $schar_exp}, + {ENV => "LC_ALL=$locale"}] + ); + + push @Tests, @Locale_Tests; + } + + # Set _POSIX2_VERSION=199209 in the environment of each obs-plus* test. foreach my $t (@Tests) { diff --git a/tests/misc/wc-files0-from.pl b/tests/misc/wc-files0-from.pl index a14bf97f..4ff10019 100755 --- a/tests/misc/wc-files0-from.pl +++ b/tests/misc/wc-files0-from.pl @@ -2,7 +2,7 @@ # Exercise wc's --files0-from option. # FIXME: keep this file in sync with tests/du/files0-from. -# Copyright (C) 2006-2013 Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/wc-files0.sh b/tests/misc/wc-files0.sh index 06be054d..37fd1ab0 100755 --- a/tests/misc/wc-files0.sh +++ b/tests/misc/wc-files0.sh @@ -1,7 +1,7 @@ #!/bin/sh # Show that wc's new --files0-from option works. -# Copyright (C) 2006-2013 Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/wc-parallel.sh b/tests/misc/wc-parallel.sh index bf6b7b29..01005820 100755 --- a/tests/misc/wc-parallel.sh +++ b/tests/misc/wc-parallel.sh @@ -2,7 +2,7 @@ # Ensure that wc prints counts atomically # so that concurrent processes don't intersperse their output -# Copyright (C) 2009-2013 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/wc.pl b/tests/misc/wc.pl index ed2feafd..076ce049 100755 --- a/tests/misc/wc.pl +++ b/tests/misc/wc.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Basic tests for "wc". -# Copyright (C) 1997-2013 Free Software Foundation, Inc. +# Copyright (C) 1997-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/misc/xattr.sh b/tests/misc/xattr.sh index 6eccc10d..f208090f 100755 --- a/tests/misc/xattr.sh +++ b/tests/misc/xattr.sh @@ -3,7 +3,7 @@ # attributes and install does not preserve extended attributes. # cp -a should preserve xattr, error diagnostics should not be displayed -# Copyright (C) 2009-2013 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -66,7 +66,7 @@ getfattr -d c >out_c || skip_ "failed to get xattr of file" grep -F "$xattr_pair" out_c || fail=1 # cp's -a option must produce no diagnostics. -cp -a a d 2>err && test -s err && fail=1 +cp -a a d 2>err && { compare /dev/null err || fail=1; } getfattr -d d >out_d || skip_ "failed to get xattr of file" grep -F "$xattr_pair" out_d || fail=1 diff --git a/tests/misc/xstrtol.pl b/tests/misc/xstrtol.pl index b2f38b61..fed8d7d6 100755 --- a/tests/misc/xstrtol.pl +++ b/tests/misc/xstrtol.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # exercise xstrtol's diagnostics via pr -# Copyright (C) 2007-2013 Free Software Foundation, Inc. +# Copyright (C) 2007-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by |