-
Notifications
You must be signed in to change notification settings - Fork 7
/
chdir.t
45 lines (33 loc) · 1.02 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
#!/usr/bin/perl -w
use strict;
use Test::More tests => 6;
use File::Spec::Functions qw/canonpath catdir/;
use Cwd qw/getcwd/;
BEGIN { use_ok('File::chdir') }
# _catdir has OS-specific path separators so do the same for getcwd
sub _getcwd { canonpath( getcwd ) }
my($cwd) = _getcwd =~ /(.*)/; # detaint otherwise nothing's gonna work
# First, let's try normal chdir()
{
chdir('t');
::is( _getcwd, catdir($cwd,'t'), 'void chdir still works' );
chdir($cwd); # reset
if( chdir('t') ) {
1;
}
else {
::fail('chdir() failed completely in boolean context!');
}
::is( _getcwd, catdir($cwd,'t'), ' even in boolean context' );
}
::is( _getcwd, catdir($cwd,'t'), ' unneffected by blocks' );
# Ok, reset ourself for the real test.
chdir($cwd) or die $!;
{
local $ENV{HOME} = 't';
chdir;
::is( _getcwd, catdir($cwd, 't'), 'chdir() with no args' );
::is( $CWD, catdir($cwd, 't'), ' $CWD follows' );
}
# Final chdir() back to the original or we confuse the debugger.
chdir($cwd);