tests: fix false failure with disabled SELinux support
[coreutils.git] / tests / misc / basename.pl
blobb84412bbcf68303c02e494de12ef38c58e19f22d
1 #!/usr/bin/perl
2 # Test basename.
3 # Copyright (C) 2006-2013 Free Software Foundation, Inc.
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 use strict;
19 use File::stat;
21 (my $program_name = $0) =~ s|.*/||;
23 # Turn off localization of executable's output.
24 @ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3;
26 my $stat_single = stat('/');
27 my $stat_double = stat('//');
28 my $double_slash = ($stat_single->dev == $stat_double->dev
29 && $stat_single->ino == $stat_double->ino) ? '/' : '//';
31 my $prog = 'basename';
33 my @Tests =
35 ['fail-1', {ERR => "$prog: missing operand\n"
36 . "Try '$prog --help' for more information.\n"}, {EXIT => '1'}],
37 ['fail-2', qw(a b c), {ERR => "$prog: extra operand 'c'\n"
38 . "Try '$prog --help' for more information.\n"}, {EXIT => '1'}],
40 ['a', qw(d/f), {OUT => 'f'}],
41 ['b', qw(/d/f), {OUT => 'f'}],
42 ['c', qw(d/f/), {OUT => 'f'}],
43 ['d', qw(d/f//), {OUT => 'f'}],
44 ['e', qw(f), {OUT => 'f'}],
45 ['f', qw(/), {OUT => '/'}],
46 ['g', qw(//), {OUT => "$double_slash"}],
47 ['h', qw(///), {OUT => '/'}],
48 ['i', qw(///a///), {OUT => 'a'}],
49 ['j', qw(''), {OUT => ''}],
50 ['k', qw(aa a), {OUT => 'a'}],
51 ['l', qw(-a a b), {OUT => "a\nb"}],
52 ['m', qw(-s a aa ba ab), {OUT => "a\nb\nab"}],
53 ['n', qw(a-a -a), {OUT => 'a'}],
54 ['1', qw(f.s .s), {OUT => 'f'}],
55 ['2', qw(fs s), {OUT => 'f'}],
56 ['3', qw(fs fs), {OUT => 'fs'}],
57 ['4', qw(fs/ s), {OUT => 'f'}],
58 ['5', qw(dir/file.suf .suf), {OUT => 'file'}],
59 ['6', qw(// /), {OUT => "$double_slash"}],
60 ['7', qw(// //), {OUT => "$double_slash"}],
61 ['8', qw(fs x), {OUT => 'fs'}],
62 ['9', qw(fs ''), {OUT => 'fs'}],
63 ['10', qw(fs/ s/), {OUT => 'fs'}],
65 # Exercise -z option.
66 ['z0', qw(-z a), {OUT => "a\0"}],
67 ['z1', qw(--zero a), {OUT => "a\0"}],
68 ['z2', qw(-za a b), {OUT => "a\0b\0"}],
69 ['z3', qw(-z ba a), {OUT => "b\0"}],
70 ['z4', qw(-z -s a ba), {OUT => "b\0"}],
73 # Append a newline to end of each expected 'OUT' string.
74 # Skip -z tests, i.e. those whose 'OUT' string has a trailing '\0'.
75 my $t;
76 foreach $t (@Tests)
78 my $arg1 = $t->[1];
79 my $e;
80 foreach $e (@$t)
82 $e->{OUT} = "$e->{OUT}\n"
83 if ref $e eq 'HASH' and exists $e->{OUT}
84 and not $e->{OUT} =~ /\0$/;
88 my $save_temps = $ENV{SAVE_TEMPS};
89 my $verbose = $ENV{VERBOSE};
91 my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose);
92 exit $fail;