3 # Exercise wc's --files0-from option.
4 # This file bears a striking resemblance to tests/du/files0-from.
6 # Copyright (C) 2006 Free Software Foundation, Inc.
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 . $srcdir/../envvar-check
28 $PERL -e 1 > /dev/null 2>&1 || {
29 echo 1>&2 "$0: configure didn't find a usable version of Perl," \
30 "so can't run this test"
34 exec $PERL -w -I$srcdir/.. -MCoreutils -- - <<\EOF
39 (my $program_name = $0) =~ s|.*/||;
44 # Turn off localization of executable's ouput.
45 @ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3;
49 # invalid extra command line argument
50 ['f-extra-arg', '--files0-from=- no-such', {IN=>"a"}, {EXIT=>1},
51 {ERR => "$ME: extra operand `no-such'\n"
52 . "File operands cannot be combined with --files0-from.\n"
53 . "Try `$ME --help' for more information.\n"}
57 ['missing', '--files0-from=missing', {EXIT=>1},
58 {ERR => "$ME: cannot open `missing' for reading: "
59 . "No such file or directory\n"}],
62 ['empty', '--files0-from=-'],
64 # empty input, from non-regular file
65 ['empty-nonreg', '--files0-from=/dev/null'],
68 ['nul-1', '--files0-from=-', '<', {IN=>"\0"}, {EXIT=>1},
69 {ERR => "$ME: : No such file or directory\n"}],
72 ['nul-2', '--files0-from=-', '<', {IN=>"\0\0"}, {EXIT=>1},
73 {OUT=>"0 0 0 total\n"},
74 {ERR => "$ME: : No such file or directory\n"
75 . "$ME: : No such file or directory\n"}],
77 # one file name, no NUL
78 ['1', '--files0-from=-', '<',
79 {IN=>{f=>"g"}}, {AUX=>{g=>''}}, {OUT=>"0 0 0 g\n"} ],
81 # one file name, with NUL
82 ['1a', '--files0-from=-', '<',
83 {IN=>{f=>"g\0"}}, {AUX=>{g=>''}}, {OUT=>"0 0 0 g\n"} ],
85 # two file names, no final NUL
86 ['2', '--files0-from=-', '<',
87 {IN=>{f=>"g\0g"}}, {AUX=>{g=>''}},
88 {OUT=>"0 0 0 g\n0 0 0 g\n0 0 0 total\n"} ],
90 # two file names, with final NUL
91 ['2a', '--files0-from=-', '<',
92 {IN=>{f=>"g\0g\0"}}, {AUX=>{g=>''}},
93 {OUT=>"0 0 0 g\n0 0 0 g\n0 0 0 total\n"} ],
95 # Ensure that wc processes FILEs following a zero-length name.
96 ['zero-len', '--files0-from=-', '<',
97 {IN=>{f=>"\0g\0"}}, {AUX=>{g=>''}},
98 {OUT=>"0 0 0 g\n0 0 0 total\n"},
99 {ERR => "$ME: : No such file or directory\n"}, {EXIT=>1} ],
102 my $save_temps = $ENV{DEBUG};
103 my $verbose = $ENV{VERBOSE};
105 my $prog = $ENV{PROG} || die "$0: \$PROG not specified in environment\n";
106 my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose);