This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
startkve.t: Refactor setting of $errpat
[perl5.git] / t / op / mkdir.t
1 #!./perl -w
2
3 BEGIN {
4     chdir 't' if -d 't';
5     @INC = '../lib';
6     require './test.pl';
7 }
8
9 plan tests => 17;
10
11 unless (eval {
12     require File::Path;
13     File::Path::rmtree('blurfl') if -d 'blurfl';
14     1
15 }) {
16     diag("$0 may fail if its temporary directory remains from a previous run");
17     diag("Attempted to load File::Path to delete directory t/blurfl - error was\n$@");
18     diag("\nIf you have problems, please manually delete t/blurfl");
19 }    
20
21 # tests 3 and 7 rather naughtily expect English error messages
22 $ENV{'LC_ALL'} = 'C';
23 $ENV{LANGUAGE} = 'C'; # GNU locale extension
24
25 sub errno_or_skip {
26     SKIP: {
27         if (is_miniperl && !eval { local $!; require Errno }) {
28             skip "Errno not built yet", 1;
29         }
30         eval "ok($_[0])";
31     }
32 }
33
34 ok(mkdir('blurfl',0777));
35 ok(!mkdir('blurfl',0777));
36 errno_or_skip('$!{EEXIST} || $! =~ /cannot move|exist|denied|unknown/i');
37 ok(-d 'blurfl');
38 ok(rmdir('blurfl'));
39 ok(!rmdir('blurfl'));
40 errno_or_skip('
41     $!{ENOENT}
42        || $! =~ /cannot find|such|exist|not found|not a directory|unknown/i
43 ');
44 ok(mkdir('blurfl'));
45 ok(rmdir('blurfl'));
46
47 # trailing slashes will be removed before the system call to mkdir
48 ok(mkdir('blurfl///'));
49 ok(-d 'blurfl');
50 ok(rmdir('blurfl///'));
51 ok(!-d 'blurfl');
52
53 # test default argument
54
55 $_ = 'blurfl';
56 ok(mkdir);
57 ok(-d);
58 ok(rmdir);
59 ok(!-d);
60 $_ = 'lfrulb';