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