Commit | Line | Data |
0b09a93a |
1 | #!/usr/bin/perl -w |
2 | use strict; |
3 | use Test::More; |
4 | use FindBin qw($Bin); |
5 | use constant TMPFILE => "$Bin/unlink_test_delete_me"; |
6 | |
7 | # Create a file to practice unlinking |
8 | open(my $fh, ">", TMPFILE) |
9 | or plan skip_all => "Unable to create test file: $!"; |
10 | print {$fh} "Test\n"; |
11 | close $fh; |
12 | |
13 | # Check that file now exists |
14 | -e TMPFILE or plan skip_all => "Failed to create test file"; |
15 | |
16 | # Check we can unlink |
17 | unlink TMPFILE; |
18 | |
19 | # Check it's gone |
20 | if(-e TMPFILE) {plan skip_all => "Failed to delete test file: $!";} |
21 | |
22 | # Re-create file |
23 | open(my $fh2, ">", TMPFILE) |
24 | or plan skip_all => "Unable to create test file: $!"; |
25 | print {$fh2} "Test\n"; |
26 | close $fh2; |
27 | |
28 | # Check that file now exists |
29 | -e TMPFILE or plan skip_all => "Failed to create test file"; |
30 | |
31 | plan tests => 6; |
32 | |
33 | # Try to delete directory (this should succeed) |
34 | eval { |
35 | use autodie; |
36 | |
37 | unlink TMPFILE; |
38 | }; |
39 | is($@, "", "Unlink appears to have been successful"); |
40 | ok(! -e TMPFILE, "File does not exist"); |
41 | |
42 | # Try to delete file again (this should fail) |
43 | eval { |
44 | use autodie; |
45 | |
46 | unlink TMPFILE; |
47 | }; |
48 | ok($@, "Re-unlinking file causes failure."); |
49 | isa_ok($@, "autodie::exception", "... errors are of the correct type"); |
50 | ok($@->matches("unlink"), "... it's also a unlink object"); |
51 | ok($@->matches(":filesys"), "... and a filesys object"); |
52 | |