Skip to content

Commit

Permalink
[v6.d REVIEW] Improve IO.mode tests
Browse files Browse the repository at this point in the history
- Use our standard temp file routines for temp files
- Shorten test descriptions
- Use more appropriate test routines
- Toss full-file Windows fudge. Any failures here will be dealt
    separately, as part of resolving #320
  • Loading branch information
zoffixznet committed Dec 31, 2017
1 parent 8060033 commit 0147de8
Showing 1 changed file with 15 additions and 35 deletions.
50 changes: 15 additions & 35 deletions S16-filehandles/mode.t
@@ -1,5 +1,7 @@
use v6;
use lib <t/spec/packages>;
use Test;
use Test::Util;

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

Expand All @@ -15,57 +17,35 @@ 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;
};

plan 12;

{
my $file = create_temporary_file;
my $file = make-temp-file :content('');
my @result = chmod 0o700, $file;
is +@result, 1, "One file successfully changed";
is @result[0], $file, "name of the file returned";
is-deeply @result[0], $file, "name of the file returned";

ok $file.IO.mode eq '0700', "successfully set to 700 and read back as such";
is $file.IO.mode, '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);
is-deeply @result[0], $file, "name of the file returned";
is $file.IO.mode, '0600',
"successfully changed to 600 and read back as such";
}


{
my $file1 = create_temporary_file;
my $file1 = make-temp-file :content('');
my @result = chmod 0o777, $file1;
is +@result, 1, "One file successfully changed";
is @result[0], $file1, "name of the file returned";
is-deeply @result[0], $file1, "name of the file returned";

my $file2 = create_temporary_file;
ok $file2.IO.mode ne '0777', "permission not 777 when created";
my $file2 = make-temp-file :content('');
isnt $file2.IO.mode, '0777', "permission is 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");
is-deeply @result[0], $file2, "name of the file returned";
is $file2.IO.mode, '0777', 'changed mode of one file using mode of another';
}


# vim: ft=perl6

0 comments on commit 0147de8

Please sign in to comment.