| 1 |
#!/usr/bin/perl |
| 2 |
# Exercise the --files0-from option. |
| 3 |
# FIXME: keep this file in sync with coreutils/tests/du/files0-from. |
| 4 |
|
| 5 |
# Copyright (C) 2006-2020 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 3 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, see <http://www.gnu.org/licenses/>. |
| 19 |
|
| 20 |
use strict; |
| 21 |
|
| 22 |
(my $program_name = $0) =~ s|.*/||; |
| 23 |
|
| 24 |
my $prog = 'mkid'; |
| 25 |
|
| 26 |
# Turn off localization of executable's output. |
| 27 |
@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; |
| 28 |
|
| 29 |
my $nothing_to_do = "$prog: nothing to do\n"; |
| 30 |
|
| 31 |
my @Tests = |
| 32 |
( |
| 33 |
# invalid extra command line argument |
| 34 |
['f-extra-arg', '--files0-from=- no-such', {IN=>"a"}, {EXIT=>1}, |
| 35 |
{ERR => "$prog: extra operand 'no-such'\n" |
| 36 |
. "file operands cannot be combined with --files0-from\n" |
| 37 |
. "Try `$prog --help' for more information.\n"} |
| 38 |
], |
| 39 |
|
| 40 |
# missing input file |
| 41 |
['missing', '--files0-from=missing', {EXIT=>1}, |
| 42 |
{ERR => "$prog: cannot open 'missing' for reading: " |
| 43 |
. "No such file or directory\n"}], |
| 44 |
|
| 45 |
# empty input, regular file |
| 46 |
['empty', '--files0-from=@AUX@', {AUX=>''}, {ERR => $nothing_to_do}], |
| 47 |
|
| 48 |
# empty input, from non-regular file |
| 49 |
['empty-nonreg', '--files0-from=/dev/null', {ERR => $nothing_to_do}], |
| 50 |
|
| 51 |
# one NUL |
| 52 |
['nul-1', '--files0-from=-', '<', {IN=>"\0"}, {EXIT=>1}, |
| 53 |
{ERR => "$prog: -:1: invalid zero-length file name\n" . $nothing_to_do}], |
| 54 |
|
| 55 |
# two NULs |
| 56 |
['nul-2', '--files0-from=-', '<', {IN=>"\0\0"}, {EXIT=>1}, |
| 57 |
{ERR => "$prog: -:1: invalid zero-length file name\n" |
| 58 |
. "$prog: -:2: invalid zero-length file name\n" |
| 59 |
. $nothing_to_do }], |
| 60 |
|
| 61 |
# one file name, no NUL |
| 62 |
['1', '--files0-from=-', '<', |
| 63 |
{IN=>{f=>"g"}}, {AUX=>{g=>''}}, |
| 64 |
{ERR => $nothing_to_do}], |
| 65 |
|
| 66 |
# one file name, with NUL |
| 67 |
['1a', '--files0-from=-', '<', |
| 68 |
{IN=>{f=>"g\0"}}, {AUX=>{g=>''}}, |
| 69 |
{ERR => $nothing_to_do}], |
| 70 |
|
| 71 |
# two file names, no final NUL |
| 72 |
['2', '--files0-from=-', '<', |
| 73 |
{IN=>{f=>"g\0g"}}, {AUX=>{g=>''}}, |
| 74 |
{ERR => $nothing_to_do}], |
| 75 |
|
| 76 |
# two file names, with final NUL |
| 77 |
['2a', '--files0-from=-', '<', |
| 78 |
{IN=>{f=>"g\0g\0"}}, {AUX=>{g=>''}}, |
| 79 |
{ERR => $nothing_to_do}], |
| 80 |
|
| 81 |
# Ensure that $prog processes FILEs following a zero-length name. |
| 82 |
['zero-len', '--files0-from=-', '<', |
| 83 |
{IN=>{f=>"\0g\0"}}, {AUX=>{g=>''}}, |
| 84 |
{ERR => "$prog: -:1: invalid zero-length file name\n" . $nothing_to_do}, |
| 85 |
{EXIT=>1} ], |
| 86 |
); |
| 87 |
|
| 88 |
# Insert '--lang-map=/dev/null' after each test name. |
| 89 |
my $t; |
| 90 |
foreach $t (@Tests) |
| 91 |
{ |
| 92 |
splice @$t, 1, 0, '--lang-map=/dev/null'; |
| 93 |
} |
| 94 |
|
| 95 |
my $save_temps = $ENV{DEBUG}; |
| 96 |
my $verbose = $ENV{VERBOSE}; |
| 97 |
|
| 98 |
my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose); |
| 99 |
exit $fail; |