build: ensure make-prime-list doesn't access out of bounds memory
[platform/upstream/coreutils.git] / tests / misc / dirname.pl
1 #!/usr/bin/perl
2 # Test "dirname".
3
4 # Copyright (C) 2006-2013 Free Software Foundation, Inc.
5
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.
10
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.
15
16 # You should have received a copy of the GNU General Public License
17 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
19 use strict;
20 use File::stat;
21
22 (my $program_name = $0) =~ s|.*/||;
23
24 # Turn off localization of executable's output.
25 @ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3;
26
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) ? '/' : '//';
31
32 my $prog = 'dirname';
33
34 my @Tests =
35     (
36      ['fail-1', {ERR => "$prog: missing operand\n"
37        . "Try '$prog --help' for more information.\n"}, {EXIT => '1'}],
38
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"}],
53     );
54
55 # Append a newline to end of each expected 'OUT' string.
56 my $t;
57 foreach $t (@Tests)
58   {
59     my $arg1 = $t->[1];
60     my $e;
61     foreach $e (@$t)
62       {
63         $e->{OUT} = "$e->{OUT}\n"
64           if ref $e eq 'HASH' and exists $e->{OUT};
65       }
66   }
67
68 my $save_temps = $ENV{SAVE_TEMPS};
69 my $verbose = $ENV{VERBOSE};
70
71 my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose);
72 exit $fail;