Debian Codegraph @

cpan/autodie/t/mkdir.t

raw
1 #!/usr/bin/perl -w
2 use strict;
3 use Test::More;
4 use FindBin qw($Bin);
5 use constant TMPDIR => "$Bin/mkdir_test_delete_me";
6 use constant ERROR_REGEXP => qr{Can't mkdir\('\Q${\(TMPDIR)}\E', 0777\):};
7 use constant SINGLE_DIGIT_ERROR_REGEXP => qr{Can't mkdir\('\Q${\(TMPDIR)}\E', 0010\):};
8
9 # Delete our directory if it's there
10 rmdir TMPDIR;
11
12 # See if we can create directories and remove them
13 mkdir TMPDIR or plan skip_all => "Failed to make test directory";
14
15 # Test the directory was created
16 -d TMPDIR or plan skip_all => "Failed to make test directory";
17
18 # Try making it a second time (this should fail)
19 if(mkdir TMPDIR) { plan skip_all => "Attempt to remake a directory succeeded";}
20
21 # See if we can remove the directory
22 rmdir TMPDIR or plan skip_all => "Failed to remove directory";
23
24 # Check that the directory was removed
25 if(-d TMPDIR) { plan skip_all => "Failed to delete test directory"; }
26
27 # Try to delete second time
28 if(rmdir TMPDIR) { plan skip_all => "Able to rmdir directory twice"; }
29
30 plan tests => 18;
31
32 # Create a directory (this should succeed)
33 eval {
34 use autodie;
35
36 mkdir TMPDIR;
37 };
38 is($@, "", "mkdir returned success");
39 ok(-d TMPDIR, "Successfully created test directory");
40
41 # Try to create it again (this should fail)
42 eval {
43 use autodie;
44
45 mkdir TMPDIR, 0777;
46 };
47 ok($@, "Re-creating directory causes failure.");
48 isa_ok($@, "autodie::exception", "... errors are of the correct type");
49 ok($@->matches("mkdir"), "... it's also a mkdir object");
50 ok($@->matches(":filesys"), "... and a filesys object");
51 like($@, ERROR_REGEXP, "Message should include numeric mask in octal form");
52
53 eval {
54 use autodie;
55
56 mkdir TMPDIR, 8;
57 };
58 ok($@, "Re-creating directory causes failure.");
59 isa_ok($@, "autodie::exception", "... errors are of the correct type");
60 ok($@->matches("mkdir"), "... it's also a mkdir object");
61 ok($@->matches(":filesys"), "... and a filesys object");
62 like($@, SINGLE_DIGIT_ERROR_REGEXP, "Message should include numeric mask in octal form");
63
64 # Try to delete directory (this should succeed)
65 eval {
66 use autodie;
67
68 rmdir TMPDIR;
69 };
70 is($@, "", "rmdir returned success");
71 ok(! -d TMPDIR, "Successfully removed test directory");
72
73 # Try to delete directory again (this should fail)
74 eval {
75 use autodie;
76
77 rmdir TMPDIR;
78 };
79 ok($@, "Re-deleting directory causes failure.");
80 isa_ok($@, "autodie::exception", "... errors are of the correct type");
81 ok($@->matches("rmdir"), "... it's also a rmdir object");
82 ok($@->matches(":filesys"), "... and a filesys object");
83