a748da422dd05229dfd1c448931673cf26308abb
[platform/upstream/coreutils.git] / tests / rm / unreadable
1 #!/bin/sh
2
3 : ${PERL=perl}
4 : ${srcdir=.}
5
6 $PERL -e 1 > /dev/null 2>&1 || {
7   echo 1>&2 "$0: configure didn't find a usable version of Perl," \
8     "so can't run this test"
9   exit 77
10 }
11
12 exec $PERL -w -I$srcdir/.. -MCoreutils -- - << \EOF
13 require 5.003;
14 use strict;
15
16 (my $program_name = $0) =~ s|.*/||;
17
18 # Turn off localisation of executable's ouput.
19 @ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3;
20
21 my $d = "dir-$$";
22 my $mkdir = {PRE => sub {mkdir $d,0100 or die "$d: $!\n"}};
23 my $prog = $ENV{PROG} || die "$0: \$PROG not specified in environment\n";
24
25 my @Tests =
26     (
27      # test-name options input expected-output
28      #
29      ['unreadable-1', '-rf', $d,
30       {EXIT => 1}, {ERR => "$prog: $d/.: Permission denied\n"}, $mkdir],
31      ['unreadable-2', '-rf', $d,
32       {EXIT => 1},
33       {ERR => "$prog: $d/.: Permission denied\n" .
34        "$prog: cannot remove directory `$d': File exists\n"},
35       {PRE => sub { (mkdir $d,0700 and mkdir "$d/x",0700 and chmod 0100,$d)
36                     or die "$d: $!\n"}} ],
37     );
38
39 my $save_temps = $ENV{SAVE_TEMPS};
40 my $verbose = $ENV{VERBOSE};
41
42 my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose);
43 exit $fail;
44 EOF