Skip to content

Commit

Permalink
[io grant] Test &*chdir
Browse files Browse the repository at this point in the history
  • Loading branch information
zoffixznet committed Apr 3, 2017
1 parent 86f79ce commit 430ab89
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions S32-io/chdir-process.t
@@ -0,0 +1,39 @@
use v6;
use lib <t/spec/packages/>;
use Test;
use Test::Util;

# Tests of &*chdir (the process-chdir-changing version)

plan 7;

unless $*TMPDIR ~~ :d & :r and $*HOME ~~ :d & :r {
skip-rest 'Cannot test without $*TPMDIR and $*HOME set to readable dirs';
exit;
}

my &sys-cwd = $*DISTRO.is-win ?? {qx`echo %cd%`.chomp.IO} !! {qx`pwd`.chomp.IO};

subtest '&*chdir to non-existent directory' => {
plan 3;

my $before = make-temp-dir;
temp $*CWD = $before;
my $res = &*chdir( make-temp-dir() ~ 'non-existent' );
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 unchanged on failure';
}

{
temp $*CWD;
cmp-ok &*chdir($*TMPDIR), '~~', $*TMPDIR, '&*chdir returns new $*CWD';
cmp-ok $*CWD, '~~', $*TMPDIR, '&*chdir updates $*CWD';
cmp-ok sys-cwd(), '~~', $*TMPDIR, '&*chdir updates process dir';
cmp-ok &*chdir($*HOME), '~~', $*HOME, '&*chdir returns new $*CWD [2]';
cmp-ok $*CWD, '~~', $*HOME, '&*chdir updates $*CWD [2]';
cmp-ok sys-cwd(), '~~', $*HOME, '&*chdir updates process dir [2]';
}

# vim: ft=perl6

0 comments on commit 430ab89

Please sign in to comment.