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