File: mkdir.t

package info (click to toggle)
perl 5.42.0-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 128,392 kB
  • sloc: perl: 534,963; ansic: 240,563; sh: 72,042; pascal: 6,934; xml: 2,428; yacc: 1,360; makefile: 1,197; cpp: 208; lisp: 1
file content (83 lines) | stat: -rw-r--r-- 2,487 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/perl -w
use strict;
use Test::More;
use FindBin qw($Bin);
use constant TMPDIR => "$Bin/mkdir_test_delete_me";
use constant ERROR_REGEXP => qr{Can't mkdir\('\Q${\(TMPDIR)}\E', 0777\):};
use constant SINGLE_DIGIT_ERROR_REGEXP => qr{Can't mkdir\('\Q${\(TMPDIR)}\E', 0010\):};

# Delete our directory if it's there
rmdir TMPDIR;

# See if we can create directories and remove them
mkdir TMPDIR or plan skip_all => "Failed to make test directory";

# Test the directory was created
-d TMPDIR or plan skip_all => "Failed to make test directory";

# Try making it a second time (this should fail)
if(mkdir TMPDIR) { plan skip_all => "Attempt to remake a directory succeeded";}

# See if we can remove the directory
rmdir TMPDIR or plan skip_all => "Failed to remove directory";

# Check that the directory was removed
if(-d TMPDIR) { plan skip_all => "Failed to delete test directory"; }

# Try to delete second time
if(rmdir TMPDIR) { plan skip_all => "Able to rmdir directory twice"; }

plan tests => 18;

# Create a directory (this should succeed)
eval {
	use autodie;

	mkdir TMPDIR;
};
is($@, "", "mkdir returned success");
ok(-d TMPDIR, "Successfully created test directory");

# Try to create it again (this should fail)
eval {
	use autodie;

	mkdir TMPDIR, 0777;
};
ok($@, "Re-creating directory causes failure.");
isa_ok($@, "autodie::exception", "... errors are of the correct type");
ok($@->matches("mkdir"), "... it's also a mkdir object");
ok($@->matches(":filesys"), "... and a filesys object");
like($@, ERROR_REGEXP, "Message should include numeric mask in octal form");

eval {
        use autodie;

        mkdir TMPDIR, 8;
};
ok($@, "Re-creating directory causes failure.");
isa_ok($@, "autodie::exception", "... errors are of the correct type");
ok($@->matches("mkdir"), "... it's also a mkdir object");
ok($@->matches(":filesys"), "... and a filesys object");
like($@, SINGLE_DIGIT_ERROR_REGEXP, "Message should include numeric mask in octal form");

# Try to delete directory (this should succeed)
eval {
	use autodie;

	rmdir TMPDIR;
};
is($@, "", "rmdir returned success");
ok(! -d TMPDIR, "Successfully removed test directory");

# Try to delete directory again (this should fail)
eval {
	use autodie;

	rmdir TMPDIR;
};
ok($@, "Re-deleting directory causes failure.");
isa_ok($@, "autodie::exception", "... errors are of the correct type");
ok($@->matches("rmdir"), "... it's also a rmdir object");
ok($@->matches(":filesys"), "... and a filesys object");