efe62f63206354249c103fec23998227a896dd6b
[platform/upstream/coreutils.git] / tests / du / files0-from
1 #!/bin/sh
2 # -*- perl -*-
3 # Exercise du's --files0-from option.
4
5 : ${PERL=perl}
6 : ${srcdir=.}
7
8 . $srcdir/../envvar-check
9
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"
13   exit 77
14 }
15
16 exec $PERL -w -I$srcdir/.. -MCoreutils -- - <<\EOF
17 #/
18 require 5.003;
19 use strict;
20
21 (my $program_name = $0) =~ s|.*/||;
22
23 $ENV{PROG} = 'du';
24
25 # Turn off localization of executable's ouput.
26 @ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3;
27
28 my @Tests =
29   (
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"}
35     ],
36
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"}],
41
42    # empty input
43    ['empty', '--files0-from=-'],
44
45    # empty input, from non-regular file
46    ['empty-nonreg', '--files0-from=/dev/null'],
47
48    # one NUL
49    ['nul-1', '--files0-from=-', '<', {IN=>"\0"}, {EXIT=>1},
50     {ERR => "du: -:1: invalid zero-length file name\n"}],
51
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"}],
56
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/'} ],
61
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/'} ],
66
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/'} ],
71
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/'} ],
76
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} ],
82   );
83
84 my $save_temps = $ENV{DEBUG};
85 my $verbose = $ENV{VERBOSE};
86
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;
90 EOF