Fix stackable tests on win32 by canonicalizing the path ahead of time
[p5sagit/local-lib.git] / t / stackable.t
1 use strict;
2 use warnings;
3 use Test::More;
4 use File::Temp qw(tempdir);
5 use Cwd;
6
7 plan tests => 19;
8
9 use local::lib ();
10
11 my $dir1 = tempdir('test_local_lib-XXXXX', DIR => Cwd::abs_path('t'), CLEANUP => 1);
12 $dir1 = local::lib->ensure_dir_structure_for($dir1);
13
14 my $dir2 = tempdir('test_local_lib-XXXXX', DIR => Cwd::abs_path('t'), CLEANUP => 1);
15 $dir2 = local::lib->ensure_dir_structure_for($dir2);
16
17 my $prev_active = () = local::lib->active_paths;
18
19 local::lib->import($dir1);
20 is +() = local::lib->active_paths, $prev_active + 1, 'one active path';
21 like $ENV{PERL_LOCAL_LIB_ROOT}, qr/\Q$dir1/, 'added one dir in root';
22 like $ENV{PERL5LIB}, qr/\Q$dir1/, 'added one dir in lib';
23 like $ENV{PERL_MM_OPT}, qr/\Q$dir1/, 'first path is installation target';
24
25 local::lib->import($dir1);
26 is +() = local::lib->active_paths, $prev_active + 1, 'still one active path after adding it twice';
27
28 local::lib->import($dir2);
29 is +() = local::lib->active_paths, $prev_active + 2, 'two active paths';
30 like $ENV{PERL_LOCAL_LIB_ROOT}, qr/\Q$dir2/, 'added another dir in root';
31 like $ENV{PERL5LIB}, qr/\Q$dir2/, 'added another dir in lib';
32 like $ENV{PERL_LOCAL_LIB_ROOT}, qr/\Q$dir1/, 'first dir is still in root';
33 like $ENV{PERL5LIB}, qr/\Q$dir1/, 'first dir is still in lib';
34 like $ENV{PERL_MM_OPT}, qr/\Q$dir2/, 'second path is installation target';
35
36 local::lib->import($dir1);
37 my @active = local::lib->active_paths;
38 is @active, $prev_active + 2, 'still two active dirs after re-adding first';
39 is $active[-1], $dir1, 'first dir was re-added on top';
40 like $ENV{PERL_MM_OPT}, qr/\Q$dir1/, 'first path is installation target again';
41
42 local::lib->import('--deactivate', $dir2);
43 unlike $ENV{PERL_LOCAL_LIB_ROOT}, qr/\Q$dir2/, 'second dir was removed from root';
44 unlike $ENV{PERL5LIB}, qr/\Q$dir2/, 'second dir was removed from lib';
45 like $ENV{PERL_LOCAL_LIB_ROOT}, qr/\Q$dir1/, q{first dir didn't go away from root};
46 like $ENV{PERL5LIB}, qr/\Q$dir1/, q{first dir didn't go away from lib};
47 like $ENV{PERL_MM_OPT}, qr/\Q$dir1/, 'first dir stays installation target';