Commit | Line | Data |
0b09a93a |
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 | |
7 | # Delete our directory if it's there |
8 | rmdir TMPDIR; |
9 | |
10 | # See if we can create directories and remove them |
11 | mkdir TMPDIR or plan skip_all => "Failed to make test directory"; |
12 | |
13 | # Test the directory was created |
14 | -d TMPDIR or plan skip_all => "Failed to make test directory"; |
15 | |
16 | # Try making it a second time (this should fail) |
17 | if(mkdir TMPDIR) { plan skip_all => "Attempt to remake a directory succeeded";} |
18 | |
19 | # See if we can remove the directory |
20 | rmdir TMPDIR or plan skip_all => "Failed to remove directory"; |
21 | |
22 | # Check that the directory was removed |
23 | if(-d TMPDIR) { plan skip_all => "Failed to delete test directory"; } |
24 | |
25 | # Try to delete second time |
26 | if(rmdir TMPDIR) { plan skip_all => "Able to rmdir directory twice"; } |
27 | |
28 | plan tests => 12; |
29 | |
30 | # Create a directory (this should succeed) |
31 | eval { |
32 | use autodie; |
33 | |
34 | mkdir TMPDIR; |
35 | }; |
36 | is($@, "", "mkdir returned success"); |
37 | ok(-d TMPDIR, "Successfully created test directory"); |
38 | |
39 | # Try to create it again (this should fail) |
40 | eval { |
41 | use autodie; |
42 | |
43 | mkdir TMPDIR; |
44 | }; |
45 | ok($@, "Re-creating directory causes failure."); |
46 | isa_ok($@, "autodie::exception", "... errors are of the correct type"); |
47 | ok($@->matches("mkdir"), "... it's also a mkdir object"); |
48 | ok($@->matches(":filesys"), "... and a filesys object"); |
49 | |
50 | # Try to delete directory (this should succeed) |
51 | eval { |
52 | use autodie; |
53 | |
54 | rmdir TMPDIR; |
55 | }; |
56 | is($@, "", "rmdir returned success"); |
57 | ok(! -d TMPDIR, "Successfully removed test directory"); |
58 | |
59 | # Try to delete directory again (this should fail) |
60 | eval { |
61 | use autodie; |
62 | |
63 | rmdir TMPDIR; |
64 | }; |
65 | ok($@, "Re-deleting directory causes failure."); |
66 | isa_ok($@, "autodie::exception", "... errors are of the correct type"); |
67 | ok($@->matches("rmdir"), "... it's also a rmdir object"); |
68 | ok($@->matches(":filesys"), "... and a filesys object"); |
69 | |