diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/misc/Makefile.am | 2 | ||||
-rwxr-xr-x | tests/misc/wc-files0 | 49 | ||||
-rwxr-xr-x | tests/misc/wc-files0-from | 91 |
3 files changed, 142 insertions, 0 deletions
diff --git a/tests/misc/Makefile.am b/tests/misc/Makefile.am index 696b9fdc1..7fe077def 100644 --- a/tests/misc/Makefile.am +++ b/tests/misc/Makefile.am @@ -18,6 +18,8 @@ TESTS_ENVIRONMENT = \ # will execute the test script rather than the standard utility. TESTS = \ + wc-files0-from \ + wc-files0 \ cat-proc \ base64 \ basename \ diff --git a/tests/misc/wc-files0 b/tests/misc/wc-files0 new file mode 100755 index 000000000..8041359c8 --- /dev/null +++ b/tests/misc/wc-files0 @@ -0,0 +1,49 @@ +#!/bin/sh +# Show that wc's new --files0-from option works. + +if test "$VERBOSE" = yes; then + set -x + wc --version +fi + +. $srcdir/../lang-default + +pwd=`pwd` +t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$ +trap 'status=$?; cd $pwd; chmod -R u+rwx $t0; rm -rf $t0 && exit $status' 0 +trap '(exit $?); exit $?' 1 2 13 15 + +framework_failure=0 +mkdir -p $tmp || framework_failure=1 +cd $tmp || framework_failure=1 + +echo 2 > 2b || framework_failure=1 +echo 2 words > 2w || framework_failure=1 +printf '2b\n2w\n' |tr '\n' '\0' > names || framework_failure=1 + +if test $framework_failure = 1; then + echo "$0: failure in testing framework" 1>&2 + (exit 1); exit 1 +fi + +fail=0 + +wc --files0-from=names > out || fail=1 +cat <<\EOF > exp || fail=1 + 1 1 2 2b + 1 2 8 2w + 2 3 10 total +EOF + +cmp out exp || fail=1 +test $fail = 1 && diff out exp 2> /dev/null + +if test "$fail" = ''; then + # Repeat the above test, but read the file name list from stdin. + rm -f out + wc --files0-from=- < names > out || fail=1 + cmp out exp || fail=1 + test $fail = 1 && diff out exp 2> /dev/null +fi + +(exit $fail); exit $fail diff --git a/tests/misc/wc-files0-from b/tests/misc/wc-files0-from new file mode 100755 index 000000000..459d87792 --- /dev/null +++ b/tests/misc/wc-files0-from @@ -0,0 +1,91 @@ +#!/bin/sh +# -*- perl -*- +# Exercise wc's --files0-from option. +# This file bears a striking resemblance to tests/du/files0-from. + +: ${PERL=perl} +: ${srcdir=.} + +. $srcdir/../envvar-check + +$PERL -e 1 > /dev/null 2>&1 || { + echo 1>&2 "$0: configure didn't find a usable version of Perl," \ + "so can't run this test" + exit 77 +} + +exec $PERL -w -I$srcdir/.. -MCoreutils -- - <<\EOF +#/ +require 5.003; +use strict; + +(my $program_name = $0) =~ s|.*/||; + +$ENV{PROG} = 'wc'; +my $ME = $ENV{PROG}; + +# Turn off localization of executable's ouput. +@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; + +my @Tests = + ( + # invalid extra command line argument + ['f-extra-arg', '--files0-from=- no-such', {IN=>"a"}, {EXIT=>1}, + {ERR => "$ME: extra operand `no-such'\n" + . "File operands cannot be combined with --files0-from.\n" + . "Try `$ME --help' for more information.\n"} + ], + + # missing input file + ['missing', '--files0-from=missing', {EXIT=>1}, + {ERR => "$ME: cannot open `missing' for reading: " + . "No such file or directory\n"}], + + # empty input + ['empty', '--files0-from=-'], + + # empty input, from non-regular file + ['empty-nonreg', '--files0-from=/dev/null'], + + # one NUL + ['nul-1', '--files0-from=-', '<', {IN=>"\0"}, {EXIT=>1}, + {ERR => "$ME: : No such file or directory\n"}], + + # two NULs + ['nul-2', '--files0-from=-', '<', {IN=>"\0\0"}, {EXIT=>1}, + {OUT=>"0 0 0 total\n"}, + {ERR => "$ME: : No such file or directory\n" + . "$ME: : No such file or directory\n"}], + + # one file name, no NUL + ['1', '--files0-from=-', '<', + {IN=>{f=>"g"}}, {AUX=>{g=>''}}, {OUT=>"0 0 0 g\n"} ], + + # one file name, with NUL + ['1a', '--files0-from=-', '<', + {IN=>{f=>"g\0"}}, {AUX=>{g=>''}}, {OUT=>"0 0 0 g\n"} ], + + # two file names, no final NUL + ['2', '--files0-from=-', '<', + {IN=>{f=>"g\0g"}}, {AUX=>{g=>''}}, + {OUT=>"0 0 0 g\n0 0 0 g\n0 0 0 total\n"} ], + + # two file names, with final NUL + ['2a', '--files0-from=-', '<', + {IN=>{f=>"g\0g\0"}}, {AUX=>{g=>''}}, + {OUT=>"0 0 0 g\n0 0 0 g\n0 0 0 total\n"} ], + + # Ensure that wc processes FILEs following a zero-length name. + ['zero-len', '--files0-from=-', '<', + {IN=>{f=>"\0g\0"}}, {AUX=>{g=>''}}, + {OUT=>"0 0 0 g\n0 0 0 total\n"}, + {ERR => "$ME: : No such file or directory\n"}, {EXIT=>1} ], + ); + +my $save_temps = $ENV{DEBUG}; +my $verbose = $ENV{VERBOSE}; + +my $prog = $ENV{PROG} || die "$0: \$PROG not specified in environment\n"; +my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose); +exit $fail; +EOF |