459d87792f23ebe25090c95791460d4b0e770a7b
[platform/upstream/coreutils.git] / tests / misc / wc-files0-from
1 #!/bin/sh
2 # -*- perl -*-
3 # Exercise wc's --files0-from option.
4 # This file bears a striking resemblance to tests/du/files0-from.
5
6 : ${PERL=perl}
7 : ${srcdir=.}
8
9 . $srcdir/../envvar-check
10
11 $PERL -e 1 > /dev/null 2>&1 || {
12   echo 1>&2 "$0: configure didn't find a usable version of Perl," \
13     "so can't run this test"
14   exit 77
15 }
16
17 exec $PERL -w -I$srcdir/.. -MCoreutils -- - <<\EOF
18 #/
19 require 5.003;
20 use strict;
21
22 (my $program_name = $0) =~ s|.*/||;
23
24 $ENV{PROG} = 'wc';
25 my $ME = $ENV{PROG};
26
27 # Turn off localization of executable's ouput.
28 @ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3;
29
30 my @Tests =
31   (
32    # invalid extra command line argument
33    ['f-extra-arg', '--files0-from=- no-such', {IN=>"a"}, {EXIT=>1},
34     {ERR => "$ME: extra operand `no-such'\n"
35         . "File operands cannot be combined with --files0-from.\n"
36         . "Try `$ME --help' for more information.\n"}
37     ],
38
39    # missing input file
40    ['missing', '--files0-from=missing', {EXIT=>1},
41     {ERR => "$ME: cannot open `missing' for reading: "
42      . "No such file or directory\n"}],
43
44    # empty input
45    ['empty', '--files0-from=-'],
46
47    # empty input, from non-regular file
48    ['empty-nonreg', '--files0-from=/dev/null'],
49
50    # one NUL
51    ['nul-1', '--files0-from=-', '<', {IN=>"\0"}, {EXIT=>1},
52     {ERR => "$ME: : No such file or directory\n"}],
53
54    # two NULs
55    ['nul-2', '--files0-from=-', '<', {IN=>"\0\0"}, {EXIT=>1},
56     {OUT=>"0 0 0 total\n"},
57     {ERR => "$ME: : No such file or directory\n"
58           . "$ME: : No such file or directory\n"}],
59
60    # one file name, no NUL
61    ['1', '--files0-from=-', '<',
62     {IN=>{f=>"g"}}, {AUX=>{g=>''}}, {OUT=>"0 0 0 g\n"} ],
63
64    # one file name, with NUL
65    ['1a', '--files0-from=-', '<',
66     {IN=>{f=>"g\0"}}, {AUX=>{g=>''}}, {OUT=>"0 0 0 g\n"} ],
67
68    # two file names, no final NUL
69    ['2', '--files0-from=-', '<',
70     {IN=>{f=>"g\0g"}}, {AUX=>{g=>''}},
71      {OUT=>"0 0 0 g\n0 0 0 g\n0 0 0 total\n"} ],
72
73    # two file names, with final NUL
74    ['2a', '--files0-from=-', '<',
75     {IN=>{f=>"g\0g\0"}}, {AUX=>{g=>''}},
76      {OUT=>"0 0 0 g\n0 0 0 g\n0 0 0 total\n"} ],
77
78    # Ensure that wc processes FILEs following a zero-length name.
79    ['zero-len', '--files0-from=-', '<',
80     {IN=>{f=>"\0g\0"}}, {AUX=>{g=>''}},
81     {OUT=>"0 0 0 g\n0 0 0 total\n"},
82     {ERR => "$ME: : No such file or directory\n"}, {EXIT=>1} ],
83   );
84
85 my $save_temps = $ENV{DEBUG};
86 my $verbose = $ENV{VERBOSE};
87
88 my $prog = $ENV{PROG} || die "$0: \$PROG not specified in environment\n";
89 my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose);
90 exit $fail;
91 EOF