tests: avoid false failure in tail inotify test
[coreutils.git] / tests / misc / sort-files0-from.pl
blob0777a3bb3b4cc16b0b25eaadcd80f0c9995865d9
1 #!/usr/bin/perl
2 # Exercise sort's --files0-from option.
3 # FIXME: keep this file in sync with tests/du/files0-from.
5 # Copyright (C) 2006-2016 Free Software Foundation, Inc.
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 3 of the License, or
10 # (at your option) any later version.
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.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 use strict;
22 (my $program_name = $0) =~ s|.*/||;
24 my $prog = 'sort';
26 # Turn off localization of executable's output.
27 @ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3;
29 my @Tests =
31 # invalid extra command line argument
32 ['f-extra-arg', '--files0-from=- no-such', {IN=>"a"}, {EXIT=>2},
33 {ERR => "$prog: extra operand 'no-such'\n"
34 . "file operands cannot be combined with --files0-from\n"
35 . "Try '$prog --help' for more information.\n"}
38 # missing input file
39 ['missing', '--files0-from=missing', {EXIT=>2},
40 {ERR => "$prog: cannot open 'missing' for reading: "
41 . "No such file or directory\n"}],
43 # input file name of '-'
44 ['minus-in-stdin', '--files0-from=-', '<', {IN=>{f=>'-'}}, {EXIT=>2},
45 {ERR => "$prog: when reading file names from stdin, no file name of"
46 . " '-' allowed\n"}],
48 # empty input, regular file
49 ['empty', '--files0-from=@AUX@', {AUX=>''}, {EXIT=>2},
50 {ERR_SUBST => 's/no input from.+$//'}, {ERR => "$prog: \n"}],
52 # empty input, from non-regular file
53 ['empty-nonreg', '--files0-from=/dev/null', {EXIT=>2},
54 {ERR => "$prog: no input from '/dev/null'\n"}],
56 # one NUL
57 ['nul-1', '--files0-from=-', '<', {IN=>"\0"}, {EXIT=>2},
58 {ERR => "$prog: -:1: invalid zero-length file name\n"}],
60 # two NULs
61 # Note that the behavior here differs from 'wc' in that the
62 # first zero-length file name is treated as fatal, so there
63 # is only one line of diagnostic output.
64 ['nul-2', '--files0-from=-', '<', {IN=>"\0\0"}, {EXIT=>2},
65 {ERR => "$prog: -:1: invalid zero-length file name\n"}],
67 # one file name, no NUL
68 ['1', '--files0-from=-', '<',
69 {IN=>{f=>"g"}}, {AUX=>{g=>'a'}}, {OUT=>"a\n"} ],
71 # one file name, with NUL
72 ['1a', '--files0-from=-', '<',
73 {IN=>{f=>"g\0"}}, {AUX=>{g=>'a'}}, {OUT=>"a\n"} ],
75 # two file names, no final NUL
76 ['2', '--files0-from=-', '<',
77 {IN=>{f=>"g\0g"}}, {AUX=>{g=>'a'}}, {OUT=>"a\na\n"} ],
79 # two file names, with final NUL
80 ['2a', '--files0-from=-', '<',
81 {IN=>{f=>"g\0g\0"}}, {AUX=>{g=>'a'}}, {OUT=>"a\na\n"} ],
83 # Ensure that $prog does nothing when there is a zero-length filename.
84 # Note that the behavior here differs from 'wc' in that the
85 # first zero-length file name is treated as fatal, so there
86 # should be no output on STDOUT.
87 ['zero-len', '--files0-from=-', '<',
88 {IN=>{f=>"\0g\0"}}, {AUX=>{g=>''}},
89 {ERR => "$prog: -:1: invalid zero-length file name\n"}, {EXIT=>2} ],
92 my $save_temps = $ENV{DEBUG};
93 my $verbose = $ENV{VERBOSE};
95 my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose);
96 exit $fail;