tests: remove ugly /bin/sh wrapper around each perl-based test script
[coreutils.git] / tests / du / files0-from
blob26a749961f141ffb319614d0385ad3d1eda4ec10
1 #!/usr/bin/perl
2 # Exercise du's --files0-from option.
4 # Copyright (C) 2004, 2005, 2007-2008 Free Software Foundation, Inc.
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 use strict;
21 (my $program_name = $0) =~ s|.*/||;
23 $ENV{PROG} = 'du';
25 # Turn off localization of executable's output.
26 @ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3;
28 my @Tests =
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"}
37 # missing input file
38 ['missing', '--files0-from=missing', {EXIT=>1},
39 {ERR => "du: cannot open `missing' for reading: "
40 . "No such file or directory\n"}],
42 # empty input, regular file
43 ['empty', '--files0-from=@AUX@', {AUX=>''}],
45 # empty input, from non-regular file
46 ['empty-nonreg', '--files0-from=/dev/null'],
48 # one NUL
49 ['nul-1', '--files0-from=-', '<', {IN=>"\0"}, {EXIT=>1},
50 {ERR => "du: -:1: invalid zero-length file name\n"}],
52 # two NULs
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);
89 exit $fail;