/
chdir.t
51 lines (42 loc) 路 1.41 KB
/
chdir.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
use v6;
use Test;
# L<S32::IO/IO::DirectoryNode/chdir>
plan 10;
eval_dies_ok ' chdir() ', 'Cannot call chdir without an argument';
### Although you can use Unix style folder separator / to set folders, what's returned
### is in the native style, such as \ for windows
my $sep = '/';
if $*OS eq "MSWin32" {
$sep = '\\';
}
# change to t subfolder and see if cwd is updated
my $subdir = 't';
if $subdir.IO !~~ :d {
skip "Directory, '$subdir', does not exist", 7;
}
else {
my $cwd = $*CWD;
ok chdir("$*CWD/$subdir"), 'chdir gave a true value';
isnt $*CWD, $cwd, 'Directory has changed';
is $*CWD, "$cwd$sep$subdir",
"Current directory is '$subdir' subfolder (absolute)";
# relative change back up.
ok chdir( ".." ), 'chdir gave a true value';
is $*CWD, $cwd, 'Change back up to .. worked';
# relative change to t
ok chdir( "$subdir" ), 'chdir gave a true value';
is $*CWD, "$cwd$sep$subdir",
"Current directory is '$subdir' subfolder (relative)";
}
my $no_subdir = 'lol does not exist';
if $no_subdir.IO ~~ :d {
skip "subdir '$no_subdir' does exist, actually.", 2;
}
else {
#?rakudo 2 skip 'spec non-conformance due to missing sink context'
lives_ok { chdir("$no_subdir") },
'chdir to a non-existent does not by default throw an exception';
ok !chdir("$no_subdir"),
'change to non-existent directory gives a false value';
}
# vim: ft=perl6