Tizen 2.0 Release
[external/tizen-coreutils.git] / tests / misc / wc-files0-from
1 #!/bin/sh
2 # -*- perl -*-
3 # Exercise wc's --files0-from option.
4 # This file bears a striking resemblance to tests/du/files0-from.
5
6 # Copyright (C) 2006 Free Software Foundation, Inc.
7
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
12
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 # 02110-1301, USA.
22
23 : ${PERL=perl}
24 : ${srcdir=.}
25
26 . $srcdir/../envvar-check
27
28 $PERL -e 1 > /dev/null 2>&1 || {
29   echo 1>&2 "$0: configure didn't find a usable version of Perl," \
30     "so can't run this test"
31   exit 77
32 }
33
34 exec $PERL -w -I$srcdir/.. -MCoreutils -- - <<\EOF
35 #/
36 require 5.003;
37 use strict;
38
39 (my $program_name = $0) =~ s|.*/||;
40
41 $ENV{PROG} = 'wc';
42 my $ME = $ENV{PROG};
43
44 # Turn off localization of executable's ouput.
45 @ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3;
46
47 my @Tests =
48   (
49    # invalid extra command line argument
50    ['f-extra-arg', '--files0-from=- no-such', {IN=>"a"}, {EXIT=>1},
51     {ERR => "$ME: extra operand `no-such'\n"
52         . "File operands cannot be combined with --files0-from.\n"
53         . "Try `$ME --help' for more information.\n"}
54     ],
55
56    # missing input file
57    ['missing', '--files0-from=missing', {EXIT=>1},
58     {ERR => "$ME: cannot open `missing' for reading: "
59      . "No such file or directory\n"}],
60
61    # empty input
62    ['empty', '--files0-from=-'],
63
64    # empty input, from non-regular file
65    ['empty-nonreg', '--files0-from=/dev/null'],
66
67    # one NUL
68    ['nul-1', '--files0-from=-', '<', {IN=>"\0"}, {EXIT=>1},
69     {ERR => "$ME: : No such file or directory\n"}],
70
71    # two NULs
72    ['nul-2', '--files0-from=-', '<', {IN=>"\0\0"}, {EXIT=>1},
73     {OUT=>"0 0 0 total\n"},
74     {ERR => "$ME: : No such file or directory\n"
75           . "$ME: : No such file or directory\n"}],
76
77    # one file name, no NUL
78    ['1', '--files0-from=-', '<',
79     {IN=>{f=>"g"}}, {AUX=>{g=>''}}, {OUT=>"0 0 0 g\n"} ],
80
81    # one file name, with NUL
82    ['1a', '--files0-from=-', '<',
83     {IN=>{f=>"g\0"}}, {AUX=>{g=>''}}, {OUT=>"0 0 0 g\n"} ],
84
85    # two file names, no final NUL
86    ['2', '--files0-from=-', '<',
87     {IN=>{f=>"g\0g"}}, {AUX=>{g=>''}},
88      {OUT=>"0 0 0 g\n0 0 0 g\n0 0 0 total\n"} ],
89
90    # two file names, with final NUL
91    ['2a', '--files0-from=-', '<',
92     {IN=>{f=>"g\0g\0"}}, {AUX=>{g=>''}},
93      {OUT=>"0 0 0 g\n0 0 0 g\n0 0 0 total\n"} ],
94
95    # Ensure that wc processes FILEs following a zero-length name.
96    ['zero-len', '--files0-from=-', '<',
97     {IN=>{f=>"\0g\0"}}, {AUX=>{g=>''}},
98     {OUT=>"0 0 0 g\n0 0 0 total\n"},
99     {ERR => "$ME: : No such file or directory\n"}, {EXIT=>1} ],
100   );
101
102 my $save_temps = $ENV{DEBUG};
103 my $verbose = $ENV{VERBOSE};
104
105 my $prog = $ENV{PROG} || die "$0: \$PROG not specified in environment\n";
106 my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose);
107 exit $fail;
108 EOF