Debian Codegraph @

cpan/autodie/t/chown.t

raw
1 #!/usr/bin/perl -w
2 use strict;
3 use Test::More;
4 use constant NO_SUCH_FILE => "this_file_had_better_not_exist";
5 use autodie;
6 use File::Temp qw(tempfile);
7
8 if ($^O eq 'MSWin32') {
9 plan skip_all => 'chown() seems to always succeed on Windows';
10 }
11
12 plan tests => 4;
13
14 eval {
15 chown(1234, 1234, NO_SUCH_FILE);
16 };
17
18 isa_ok($@, 'autodie::exception', 'exception thrown for chown');
19
20 # Chown returns the number of files that we chowned. So really we
21 # should die if the return value is not equal to the number of arguments
22 # minus two.
23
24 my ($fh, $filename) = tempfile;
25
26 eval { chown($<, -1, $filename); };
27 ok(! $@, "Can chown a file we own just fine.");
28
29 eval { chown($<, -1, $filename, NO_SUCH_FILE); };
30 isa_ok($@, 'autodie::exception', "Exception if ANY file changemode fails");
31 is($@->return, 1, "Confirm we're dying on a 'true' chown failure.");