3 # Exercise du's --files0-from option.
5 # Copyright (C) 2004, 2005 Free Software Foundation, Inc.
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 . $srcdir/../envvar-check
27 $PERL -e 1 > /dev/null 2>&1 || {
28 echo 1>&2 "$0: configure didn't find a usable version of Perl," \
29 "so can't run this test"
33 exec $PERL -w -I$srcdir/.. -MCoreutils -- - <<\EOF
38 (my $program_name = $0) =~ s|.*/||;
42 # Turn off localization of executable's ouput.
43 @ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3;
47 # invalid extra command line argument
48 ['f-extra-arg', '--files0-from=- no-such', {IN=>"a"}, {EXIT=>1},
49 {ERR => "du: extra operand `no-such'\n"
50 . "File operands cannot be combined with --files0-from.\n"
51 . "Try `du --help' for more information.\n"}
55 ['missing', '--files0-from=missing', {EXIT=>1},
56 {ERR => "du: cannot open `missing' for reading: "
57 . "No such file or directory\n"}],
60 ['empty', '--files0-from=-'],
62 # empty input, from non-regular file
63 ['empty-nonreg', '--files0-from=/dev/null'],
66 ['nul-1', '--files0-from=-', '<', {IN=>"\0"}, {EXIT=>1},
67 {ERR => "du: -:1: invalid zero-length file name\n"}],
70 ['nul-2', '--files0-from=-', '<', {IN=>"\0\0"}, {EXIT=>1},
71 {ERR => "du: -:1: invalid zero-length file name\n"
72 . "du: -:2: invalid zero-length file name\n"}],
74 # one file name, no NUL
75 ['1', '--files0-from=-', '<',
76 {IN=>{f=>"g"}}, {AUX=>{g=>''}},
77 {OUT=>"0\tg\n"}, {OUT_SUBST=>'s/^\d+/0/'} ],
79 # one file name, with NUL
80 ['1a', '--files0-from=-', '<',
81 {IN=>{f=>"g\0"}}, {AUX=>{g=>''}},
82 {OUT=>"0\tg\n"}, {OUT_SUBST=>'s/^\d+/0/'} ],
84 # two file names, no final NUL
85 ['2', '--files0-from=-', '<',
86 {IN=>{f=>"g\0g"}}, {AUX=>{g=>''}},
87 {OUT=>"0\tg\n0\tg\n"}, {OUT_SUBST=>'s/^\d+/0/'} ],
89 # two file names, with final NUL
90 ['2a', '--files0-from=-', '<',
91 {IN=>{f=>"g\0g\0"}}, {AUX=>{g=>''}},
92 {OUT=>"0\tg\n0\tg\n"}, {OUT_SUBST=>'s/^\d+/0/'} ],
94 # Ensure that du processes FILEs following a zero-length name.
95 ['zero-len', '--files0-from=-', '<',
96 {IN=>{f=>"\0g\0"}}, {AUX=>{g=>''}},
97 {OUT=>"0\tg\n"}, {OUT_SUBST=>'s/^\d+/0/'},
98 {ERR => "du: -:1: invalid zero-length file name\n"}, {EXIT=>1} ],
101 my $save_temps = $ENV{DEBUG};
102 my $verbose = $ENV{VERBOSE};
104 my $prog = $ENV{PROG} || die "$0: \$PROG not specified in environment\n";
105 my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose);