tests: add test for locale decimal processing
[coreutils.git] / tests / misc / dirname.pl
blob3b45cd3a3eefc927d98f187de7654a63239e3230
1 #!/usr/bin/perl
2 # Test "dirname".
4 # Copyright (C) 2006-2019 Free Software Foundation, Inc.
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <https://www.gnu.org/licenses/>.
19 use strict;
20 use File::stat;
22 (my $program_name = $0) =~ s|.*/||;
24 # Turn off localization of executable's output.
25 @ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3;
27 my $stat_single = stat('/');
28 my $stat_double = stat('//');
29 my $double_slash = ($stat_single->dev == $stat_double->dev
30 && $stat_single->ino == $stat_double->ino) ? '/' : '//';
32 my $prog = 'dirname';
34 my @Tests =
36 ['fail-1', {ERR => "$prog: missing operand\n"
37 . "Try '$prog --help' for more information.\n"}, {EXIT => '1'}],
39 ['a', qw(d/f), {OUT => 'd'}],
40 ['b', qw(/d/f), {OUT => '/d'}],
41 ['c', qw(d/f/), {OUT => 'd'}],
42 ['d', qw(d/f//), {OUT => 'd'}],
43 ['e', qw(f), {OUT => '.'}],
44 ['f', qw(/), {OUT => '/'}],
45 ['g', qw(//), {OUT => "$double_slash"}],
46 ['h', qw(///), {OUT => '/'}],
47 ['i', qw(//a//), {OUT => "$double_slash"}],
48 ['j', qw(///a///), {OUT => '/'}],
49 ['k', qw(///a///b), {OUT => '///a'}],
50 ['l', qw(///a//b/), {OUT => '///a'}],
51 ['m', qw(''), {OUT => '.'}],
52 ['n', qw(a/b c/d), {OUT => "a\nc"}],
55 # Append a newline to end of each expected 'OUT' string.
56 my $t;
57 foreach $t (@Tests)
59 my $arg1 = $t->[1];
60 my $e;
61 foreach $e (@$t)
63 $e->{OUT} = "$e->{OUT}\n"
64 if ref $e eq 'HASH' and exists $e->{OUT};
68 my $save_temps = $ENV{SAVE_TEMPS};
69 my $verbose = $ENV{VERBOSE};
71 my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose);
72 exit $fail;