Tizen 2.0 Release
[external/tizen-coreutils.git] / tests / du / files0-from
1 #!/bin/sh
2 # -*- perl -*-
3 # Exercise du's --files0-from option.
4
5 # Copyright (C) 2004, 2005 Free Software Foundation, Inc.
6
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.
11
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.
16
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
20 # 02110-1301, USA.
21
22 : ${PERL=perl}
23 : ${srcdir=.}
24
25 . $srcdir/../envvar-check
26
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"
30   exit 77
31 }
32
33 exec $PERL -w -I$srcdir/.. -MCoreutils -- - <<\EOF
34 #/
35 require 5.003;
36 use strict;
37
38 (my $program_name = $0) =~ s|.*/||;
39
40 $ENV{PROG} = 'du';
41
42 # Turn off localization of executable's ouput.
43 @ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3;
44
45 my @Tests =
46   (
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"}
52     ],
53
54    # missing input file
55    ['missing', '--files0-from=missing', {EXIT=>1},
56     {ERR => "du: cannot open `missing' for reading: "
57      . "No such file or directory\n"}],
58
59    # empty input
60    ['empty', '--files0-from=-'],
61
62    # empty input, from non-regular file
63    ['empty-nonreg', '--files0-from=/dev/null'],
64
65    # one NUL
66    ['nul-1', '--files0-from=-', '<', {IN=>"\0"}, {EXIT=>1},
67     {ERR => "du: -:1: invalid zero-length file name\n"}],
68
69    # two NULs
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"}],
73
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/'} ],
78
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/'} ],
83
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/'} ],
88
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/'} ],
93
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} ],
99   );
100
101 my $save_temps = $ENV{DEBUG};
102 my $verbose = $ENV{VERBOSE};
103
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);
106 exit $fail;
107 EOF