(NEW): Undefine to avoid warning about redefinition.
[coreutils.git] / tests / basename / basic
blobbdbf19c1fcc3d04a66d9f1caaa51d90cb1a596d6
1 #!/bin/sh
2 # This is really a -*-perl-*- script
4 : ${PERL=perl}
5 : ${srcdir=.}
7 case "$PERL" in
8 *'missing perl')
9 echo 1>&2 "$0: configure didn't find a usable version of Perl,"
10 "so can't run this test"
11 # '
12 exit 77
14 esac
16 exec $PERL -w -I$srcdir/.. -MFetish -- - << \EOF
17 require 5.003;
18 use strict;
20 (my $program_name = $0) =~ s|.*/||;
22 # Turn off localisation of executable's ouput.
23 @ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3;
25 my $prog = $ENV{PROG} || die "$0: \$PROG not specified in environment\n";
27 my @Tests =
29 ['fail-1', {ERR => "$prog: too few arguments\n"
30 . "Try `$prog --help' for more information.\n"}, {EXIT => '1'}],
31 ['fail-2', qw(a a a), {ERR => "$prog: too many arguments\n"
32 . "Try `$prog --help' for more information.\n"}, {EXIT => '1'}],
34 ['a', qw(d/f), {OUT => 'f'}],
35 ['b', qw(/d/f), {OUT => 'f'}],
36 ['c', qw(d/f/), {OUT => 'f'}],
37 ['d', qw(d/f//), {OUT => 'f'}],
38 ['e', qw(f), {OUT => 'f'}],
39 ['f', qw(/), {OUT => '/'}],
40 ['g', qw(//), {OUT => '/'}],
41 ['h', qw(///), {OUT => '/'}],
42 ['i', qw(///a///), {OUT => 'a'}],
43 ['1', qw(f.s .s), {OUT => 'f'}],
44 ['2', qw(fs s), {OUT => 'f'}],
45 ['3', qw(fs fs), {OUT => 'fs'}],
46 ['4', qw(fs fs), {OUT => 'fs'}],
47 ['5', qw(dir/file.suf .suf), {OUT => 'file'}],
50 # Append a newline to end of each expected `OUT' string.
51 my $t;
52 foreach $t (@Tests)
54 my $arg1 = $t->[1];
55 my $e;
56 foreach $e (@$t)
58 $e->{OUT} = "$e->{OUT}\n"
59 if ref $e eq 'HASH' and exists $e->{OUT};
63 my $save_temps = $ENV{SAVE_TEMPS};
64 my $verbose = $ENV{VERBOSE};
66 my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose);
67 exit $fail;
68 EOF