Debian Codegraph @

cpan/autodie/t/chmod.t

raw
1 #!/usr/bin/perl -w
2 use strict;
3 use Test::More tests => 7;
4 use constant NO_SUCH_FILE => "this_file_had_better_not_exist";
5 use constant ERROR_REGEXP => qr{Can't chmod\(0755, '${\(NO_SUCH_FILE)}'\):};
6 use constant SINGLE_DIGIT_ERROR_REGEXP => qr{Can't chmod\(0010, '${\(NO_SUCH_FILE)}'\):};
7 use File::Temp qw(tempfile);
8 use autodie;
9
10 # This tests RT #50423, Debian #550462
11
12 eval { chmod(0755, NO_SUCH_FILE); };
13 isa_ok($@, 'autodie::exception', 'exception thrown for chmod');
14 like($@, ERROR_REGEXP, "Message should include numeric mode in octal form");
15
16 eval { chmod(8, NO_SUCH_FILE); };
17 isa_ok($@, 'autodie::exception', 'exception thrown for chmod');
18 like($@, SINGLE_DIGIT_ERROR_REGEXP, "Message should include numeric mode in octal form");
19
20 my ($fh, $filename) = tempfile;
21
22 eval { chmod(0755, $filename); };
23 ok(! $@, "We can chmod a file we own just fine.");
24
25 eval { chmod(0755, $filename, NO_SUCH_FILE) };
26 isa_ok($@, 'autodie::exception', 'chmod exception on any file failure.');
27 is($@->return,1,"Confirm autodie on a 'true' chown failure.");