Skip to content

Commit

Permalink
[io grant] Expand &chdir tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zoffixznet committed Apr 3, 2017
1 parent a627e59 commit 86f79ce
Showing 1 changed file with 106 additions and 1 deletion.
107 changes: 106 additions & 1 deletion S32-io/chdir.t
Expand Up @@ -5,7 +5,7 @@ use Test::Util;

# L<S32::IO/Functions/chdir>

plan 8;
plan 81;

throws-like ' chdir() ', Exception, 'Cannot call chdir without an argument';

Expand Down Expand Up @@ -34,4 +34,109 @@ else {
"Current directory is '$subdir' subfolder (relative)";
}

sub test-chdir ($desc, $after, |args) {
my $before = make-temp-dir;
subtest "chdir with {args.perl}" => {
temp $*CWD = $before;
ok chdir($after, |args), "call to chdir succeeds";
cmp-ok $*CWD, '~~', $after, 'new $*CWD is correct';
}
}

sub test-chdir-fails ($desc, $why, $after, |args) {
my $before = make-temp-dir;
subtest "chdir with {args.perl} fails because of $why" => {
temp $*CWD = $before;
my $res = chdir($after, |args);
isa-ok $res, Failure, "call to chdir returned a Failure";
throws-like { $res.sink }, X::IO::Chdir,
'the Failure contains correct exception';
cmp-ok $*CWD, '~~', $before, '$*CWD remains untouched';
}
}

test-chdir-fails 'non-existent path', 'path does not exist',
(make-temp-dir() ~ '-non-existent').IO;

test-chdir :!d, 'chmod 0o777', make-temp-file :chmod<0o777>;
test-chdir :!d, 'chmod 0o666', make-temp-file :chmod<0o666>;
test-chdir :!d, 'chmod 0o555', make-temp-file :chmod<0o555>;
test-chdir :!d, 'chmod 0o444', make-temp-file :chmod<0o444>;
test-chdir :!d, 'chmod 0o333', make-temp-file :chmod<0o333>;
test-chdir :!d, 'chmod 0o222', make-temp-file :chmod<0o222>;
test-chdir :!d, 'chmod 0o111', make-temp-file :chmod<0o111>;
test-chdir :!d, 'chmod 0o000', make-temp-file :chmod<0o000>;

test-chdir 'chmod 0o777', make-temp-dir 0o777;
test-chdir 'chmod 0o666', make-temp-dir 0o666;
test-chdir 'chmod 0o555', make-temp-dir 0o555;
test-chdir 'chmod 0o444', make-temp-dir 0o444;
test-chdir 'chmod 0o333', make-temp-dir 0o333;
test-chdir 'chmod 0o222', make-temp-dir 0o222;
test-chdir 'chmod 0o111', make-temp-dir 0o111;
test-chdir 'chmod 0o000', make-temp-dir 0o000;

test-chdir :r, 'chmod 0o777', make-temp-dir 0o777;
test-chdir :r, 'chmod 0o666', make-temp-dir 0o666;
test-chdir :r, 'chmod 0o555', make-temp-dir 0o555;
test-chdir :r, 'chmod 0o444', make-temp-dir 0o444;
test-chdir-fails :r, 'chmod 0o333', 'permissions', make-temp-dir 0o333;
test-chdir-fails :r, 'chmod 0o222', 'permissions', make-temp-dir 0o222;
test-chdir-fails :r, 'chmod 0o111', 'permissions', make-temp-dir 0o111;
test-chdir-fails :r, 'chmod 0o000', 'permissions', make-temp-dir 0o000;

test-chdir :w, 'chmod 0o777', make-temp-dir 0o777;
test-chdir-fails :w, 'chmod 0o555', 'permissions', make-temp-dir 0o555;
test-chdir :w, 'chmod 0o666', make-temp-dir 0o666;
test-chdir :w, 'chmod 0o333', make-temp-dir 0o333;
test-chdir-fails :w, 'chmod 0o444', 'permissions', make-temp-dir 0o444;
test-chdir :w, 'chmod 0o222', make-temp-dir 0o222;
test-chdir-fails :w, 'chmod 0o111', 'permissions', make-temp-dir 0o111;
test-chdir-fails :w, 'chmod 0o000', 'permissions', make-temp-dir 0o000;

test-chdir :x, 'chmod 0o777', make-temp-dir 0o777;
test-chdir-fails :x, 'chmod 0o666', 'permissions', make-temp-dir 0o666;
test-chdir :x, 'chmod 0o555', make-temp-dir 0o555;
test-chdir-fails :x, 'chmod 0o444', 'permissions', make-temp-dir 0o444;
test-chdir :x, 'chmod 0o333', make-temp-dir 0o333;
test-chdir-fails :x, 'chmod 0o222', 'permissions', make-temp-dir 0o222;
test-chdir :x, 'chmod 0o111', make-temp-dir 0o111;
test-chdir-fails :x, 'chmod 0o000', 'permissions', make-temp-dir 0o000;

test-chdir :r:w, 'chmod 0o777', make-temp-dir 0o777;
test-chdir :r:w, 'chmod 0o666', make-temp-dir 0o666;
test-chdir-fails :r:w, 'chmod 0o555', 'permissions', make-temp-dir 0o555;
test-chdir-fails :r:w, 'chmod 0o444', 'permissions', make-temp-dir 0o444;
test-chdir-fails :r:w, 'chmod 0o333', 'permissions', make-temp-dir 0o333;
test-chdir-fails :r:w, 'chmod 0o222', 'permissions', make-temp-dir 0o222;
test-chdir-fails :r:w, 'chmod 0o111', 'permissions', make-temp-dir 0o111;
test-chdir-fails :r:w, 'chmod 0o000', 'permissions', make-temp-dir 0o000;

test-chdir :r:x, 'chmod 0o777', make-temp-dir 0o777;
test-chdir-fails :r:x, 'chmod 0o666', 'permissions', make-temp-dir 0o666;
test-chdir :r:x, 'chmod 0o555', make-temp-dir 0o555;
test-chdir-fails :r:x, 'chmod 0o444', 'permissions', make-temp-dir 0o444;
test-chdir-fails :r:x, 'chmod 0o333', 'permissions', make-temp-dir 0o333;
test-chdir-fails :r:x, 'chmod 0o222', 'permissions', make-temp-dir 0o222;
test-chdir-fails :r:x, 'chmod 0o111', 'permissions', make-temp-dir 0o111;
test-chdir-fails :r:x, 'chmod 0o000', 'permissions', make-temp-dir 0o000;

test-chdir :x:w, 'chmod 0o777', make-temp-dir 0o777;
test-chdir-fails :x:w, 'chmod 0o666', 'permissions', make-temp-dir 0o666;
test-chdir-fails :x:w, 'chmod 0o555', 'permissions', make-temp-dir 0o555;
test-chdir-fails :x:w, 'chmod 0o444', 'permissions', make-temp-dir 0o444;
test-chdir :x:w, 'chmod 0o333', make-temp-dir 0o333;
test-chdir-fails :x:w, 'chmod 0o222', 'permissions', make-temp-dir 0o222;
test-chdir-fails :x:w, 'chmod 0o111', 'permissions', make-temp-dir 0o111;
test-chdir-fails :x:w, 'chmod 0o000', 'permissions', make-temp-dir 0o000;

test-chdir :r:w:x, 'chmod 0o777', make-temp-dir 0o777;
test-chdir-fails :r:w:x, 'chmod 0o666', 'permissions', make-temp-dir 0o666;
test-chdir-fails :r:w:x, 'chmod 0o555', 'permissions', make-temp-dir 0o555;
test-chdir-fails :r:w:x, 'chmod 0o444', 'permissions', make-temp-dir 0o444;
test-chdir-fails :r:w:x, 'chmod 0o333', 'permissions', make-temp-dir 0o333;
test-chdir-fails :r:w:x, 'chmod 0o222', 'permissions', make-temp-dir 0o222;
test-chdir-fails :r:w:x, 'chmod 0o111', 'permissions', make-temp-dir 0o111;
test-chdir-fails :r:w:x, 'chmod 0o000', 'permissions', make-temp-dir 0o000;

# vim: ft=perl6

0 comments on commit 86f79ce

Please sign in to comment.