Skip to content

Commit

Permalink
Test for RT #125489
Browse files Browse the repository at this point in the history
Requires a Rakudo built with PR #773 (rakudo/rakudo#773)
  • Loading branch information
MasterDuke17 committed Jun 15, 2016
1 parent cef40ed commit 9e76d49
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions S16-filehandles/mode.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
use v6;
use Test;

# L<S32::IO/IO::FSNode::Unix/mode>

=begin pod
mode - retrieve the rights of a file
Proposed behaviour
MODE = "path/to/file".IO.mode
MODE is an IntStr, where the Int portion can be used in the chmod method and
the Str portion is four octal digits.
=end pod

plan 15;

if $*DISTRO.is-win {
skip-rest "file tests not fully available on win32";
exit;
};


{
my $file = create_temporary_file;
my @result = chmod 0o700, $file;
is +@result, 1, "One file successfully changed";
is @result[0], $file, "name of the file returned";

ok $file.IO.mode eq '0700', "successfully set to 700 and read back as such";
@result = chmod 0o600, $file;
is +@result, 1, "One file successfully changed";
is @result[0], $file, "name of the file returned";
ok $file.IO.mode eq '0600', "successfully changed to 600 and read back as such";
remove_file($file);
}


{
my $file1 = create_temporary_file;
my @result = chmod 0o777, $file1;
is +@result, 1, "One file successfully changed";
is @result[0], $file1, "name of the file returned";

my $file2 = create_temporary_file;
ok $file2.IO.mode ne '0777', "permission not 777 when created";
@result = chmod $file1.IO.mode, $file2;
is +@result, 1, "One file successfully changed";
is @result[0], $file2, "name of the file returned";
ok $file2.IO.mode eq '0777', "successfully changed '$file2' to have the same
permissions as '$file1' by chmodding '$file2' with the output of '$file1'.IO.mode";
remove_file($file1);
remove_file($file2);
}

sub create_temporary_file {
my $time = now.narrow;
my $file = "temp_$time";
my $fh = open $file, :w orelse die "Could not create $file"; #OK not used
diag "Using file $file";
return $file;
}
sub remove_file ($file) {
unlink $file;
ok($file.IO ~~ :!e, "Test file was successfully removed");
}


# vim: ft=perl6

0 comments on commit 9e76d49

Please sign in to comment.