3 # Exercise du's --files0-from option.
8 . $srcdir/../envvar-check
10 $PERL -e 1 > /dev/null 2>&1 || {
11 echo 1>&2 "$0: configure didn't find a usable version of Perl," \
12 "so can't run this test"
16 exec $PERL -w -I$srcdir/.. -MCoreutils -- - <<\EOF
21 (my $program_name = $0) =~ s|.*/||;
25 # Turn off localization of executable's ouput.
26 @ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3;
30 # invalid extra command line argument
31 ['f-extra-arg', '--files0-from=- no-such', {IN=>"a"}, {EXIT=>1},
32 {ERR => "du: extra operand `no-such'\n"
33 . "File operands cannot be combined with --files0-from.\n"
34 . "Try `du --help' for more information.\n"}
38 ['missing', '--files0-from=missing', {EXIT=>1},
39 {ERR => "du: cannot open `missing' for reading: "
40 . "No such file or directory\n"}],
43 ['empty', '--files0-from=-'],
45 # empty input, from non-regular file
46 ['empty-nonreg', '--files0-from=/dev/null'],
49 ['nul-1', '--files0-from=-', '<', {IN=>"\0"}, {EXIT=>1},
50 {ERR => "du: -:1: invalid zero-length file name\n"}],
53 ['nul-2', '--files0-from=-', '<', {IN=>"\0\0"}, {EXIT=>1},
54 {ERR => "du: -:1: invalid zero-length file name\n"
55 . "du: -:2: invalid zero-length file name\n"}],
57 # one file name, no NUL
58 ['1', '--files0-from=-', '<',
59 {IN=>{f=>"g"}}, {AUX=>{g=>''}},
60 {OUT=>"0\tg\n"}, {OUT_SUBST=>'s/^\d+/0/'} ],
62 # one file name, with NUL
63 ['1a', '--files0-from=-', '<',
64 {IN=>{f=>"g\0"}}, {AUX=>{g=>''}},
65 {OUT=>"0\tg\n"}, {OUT_SUBST=>'s/^\d+/0/'} ],
67 # two file names, no final NUL
68 ['2', '--files0-from=-', '<',
69 {IN=>{f=>"g\0g"}}, {AUX=>{g=>''}},
70 {OUT=>"0\tg\n0\tg\n"}, {OUT_SUBST=>'s/^\d+/0/'} ],
72 # two file names, with final NUL
73 ['2a', '--files0-from=-', '<',
74 {IN=>{f=>"g\0g\0"}}, {AUX=>{g=>''}},
75 {OUT=>"0\tg\n0\tg\n"}, {OUT_SUBST=>'s/^\d+/0/'} ],
77 # Ensure that du processes FILEs following a zero-length name.
78 ['zero-len', '--files0-from=-', '<',
79 {IN=>{f=>"\0g\0"}}, {AUX=>{g=>''}},
80 {OUT=>"0\tg\n"}, {OUT_SUBST=>'s/^\d+/0/'},
81 {ERR => "du: -:1: invalid zero-length file name\n"}, {EXIT=>1} ],
84 my $save_temps = $ENV{DEBUG};
85 my $verbose = $ENV{VERBOSE};
87 my $prog = $ENV{PROG} || die "$0: \$PROG not specified in environment\n";
88 my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose);