Debian lenny version packages
[pkg-perl] / deb-src / libfile-chdir-perl / libfile-chdir-perl-0.06 / t / var.t
1 #!/usr/bin/perl -Tw
2
3 use strict;
4 use lib qw(t/lib);
5 use Test::More tests => 11;
6
7 BEGIN { use_ok('File::chdir') }
8
9 use Cwd;
10
11 # Don't want to depend on File::Spec::Functions
12 sub catdir { File::Spec->catdir(@_) }
13
14 my $cwd = getcwd;
15
16 ok( tied $CWD,      '$CWD is fit to be tied' );
17
18 # First, let's try unlocalized $CWD.
19 {
20     $CWD = 't';
21     ::is( getcwd, catdir($cwd,'t'), 'unlocalized $CWD works' );
22     ::is( $CWD,   catdir($cwd,'t'), '  $CWD set' );
23 }
24
25 ::is( getcwd, catdir($cwd,'t'), 'unlocalized $CWD unneffected by blocks' );
26 ::is( $CWD,   catdir($cwd,'t'), '  and still set' );
27
28
29 # Ok, reset ourself for the real test.
30 $CWD = $cwd;
31
32 {
33     my $old_dir = $CWD;
34     local $CWD = "t";
35     ::is( $old_dir, $cwd,           '$CWD fetch works' );
36     ::is( getcwd, catdir($cwd,'t'), 'localized $CWD works' );
37 }
38
39 ::is( getcwd, $cwd,                 '  and resets automatically!' );
40 ::is( $CWD,   $cwd,                 '  $CWD reset, too' );
41
42
43 chdir('t');
44 is( $CWD,   catdir($cwd,'t'),       'chdir() and $CWD work together' );