global: convert indentation-TABs to spaces
[coreutils.git] / tests / misc / basename
blob48b11afc3b41baeb35ce6ba82d8da001065d23cf
1 #!/usr/bin/perl
2 # Test basename.
3 # Copyright (C) 2006-2009 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 ['1', qw(f.s .s), {OUT => 'f'}],
51 ['2', qw(fs s), {OUT => 'f'}],
52 ['3', qw(fs fs), {OUT => 'fs'}],
53 ['4', qw(fs/ s), {OUT => 'f'}],
54 ['5', qw(dir/file.suf .suf), {OUT => 'file'}],
55 ['6', qw(// /), {OUT => "$double_slash"}],
56 ['7', qw(// //), {OUT => "$double_slash"}],
57 ['8', qw(fs x), {OUT => 'fs'}],
58 ['9', qw(fs ''), {OUT => 'fs'}],
59 ['10', qw(fs/ s/), {OUT => 'fs'}],
62 # Append a newline to end of each expected `OUT' string.
63 my $t;
64 foreach $t (@Tests)
66 my $arg1 = $t->[1];
67 my $e;
68 foreach $e (@$t)
70 $e->{OUT} = "$e->{OUT}\n"
71 if ref $e eq 'HASH' and exists $e->{OUT};
75 my $save_temps = $ENV{SAVE_TEMPS};
76 my $verbose = $ENV{VERBOSE};
78 my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose);
79 exit $fail;