1#!/usr/bin/perl -w 2use strict; 3use Test::More; 4use constant NO_SUCH_FILE => "this_file_had_better_not_exist"; 5use autodie; 6use File::Temp qw(tempfile); 7 8if ($^O eq 'MSWin32') { 9 plan skip_all => 'chown() seems to always succeed on Windows'; 10} 11 12plan tests => 4; 13 14eval { 15 chown(1234, 1234, NO_SUCH_FILE); 16}; 17 18isa_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 24my ($fh, $filename) = tempfile; 25 26eval { chown($<, -1, $filename); }; 27ok(! $@, "Can chown a file we own just fine."); 28 29eval { chown($<, -1, $filename, NO_SUCH_FILE); }; 30isa_ok($@, 'autodie::exception', "Exception if ANY file changemode fails"); 31is($@->return, 1, "Confirm we're dying on a 'true' chown failure."); 32