Move Win32 magic out of ensure_dir_structure_for()
[p5sagit/local-lib.git] / t / stackable.t
CommitLineData
b0e4e8db 1use strict;
2use warnings;
3use Test::More;
4use File::Temp qw(tempdir);
5use Cwd;
6
6369ed6d 7plan tests => 19;
b0e4e8db 8
f694b8aa 9use local::lib ();
10
c1ed5f4b 11sub mk_temp_dir
12{
13 my $name_template = shift;
14
15 my $path = tempdir($name_template, DIR => Cwd::abs_path('t'), CLEANUP => 1);
16 local::lib->ensure_dir_structure_for($path);
17 # On Win32 the path where the distribution is built usually contains
18 # spaces. This is a problem for some parts of the CPAN toolchain, so
19 # local::lib uses the GetShortPathName trick do get an alternate
20 # representation of the path that doesn't constain spaces.
21 return ($^O eq 'MSWin32')
22 ? Win32::GetShortPathName($path)
23 : $path
24}
25
26my $dir1 = mk_temp_dir('test_local_lib-XXXXX');
27my $dir2 = mk_temp_dir('test_local_lib-XXXXX');
b0e4e8db 28
a20a4a55 29my $prev_active = () = local::lib->active_paths;
30
b0e4e8db 31local::lib->import($dir1);
a20a4a55 32is +() = local::lib->active_paths, $prev_active + 1, 'one active path';
b0e4e8db 33like $ENV{PERL_LOCAL_LIB_ROOT}, qr/\Q$dir1/, 'added one dir in root';
34like $ENV{PERL5LIB}, qr/\Q$dir1/, 'added one dir in lib';
6369ed6d 35like $ENV{PERL_MM_OPT}, qr/\Q$dir1/, 'first path is installation target';
36
37local::lib->import($dir1);
a20a4a55 38is +() = local::lib->active_paths, $prev_active + 1, 'still one active path after adding it twice';
b0e4e8db 39
40local::lib->import($dir2);
a20a4a55 41is +() = local::lib->active_paths, $prev_active + 2, 'two active paths';
b0e4e8db 42like $ENV{PERL_LOCAL_LIB_ROOT}, qr/\Q$dir2/, 'added another dir in root';
43like $ENV{PERL5LIB}, qr/\Q$dir2/, 'added another dir in lib';
44like $ENV{PERL_LOCAL_LIB_ROOT}, qr/\Q$dir1/, 'first dir is still in root';
45like $ENV{PERL5LIB}, qr/\Q$dir1/, 'first dir is still in lib';
6369ed6d 46like $ENV{PERL_MM_OPT}, qr/\Q$dir2/, 'second path is installation target';
47
48local::lib->import($dir1);
49my @active = local::lib->active_paths;
a20a4a55 50is @active, $prev_active + 2, 'still two active dirs after re-adding first';
6369ed6d 51is $active[-1], $dir1, 'first dir was re-added on top';
52like $ENV{PERL_MM_OPT}, qr/\Q$dir1/, 'first path is installation target again';
b0e4e8db 53
6369ed6d 54local::lib->import('--deactivate', $dir2);
55unlike $ENV{PERL_LOCAL_LIB_ROOT}, qr/\Q$dir2/, 'second dir was removed from root';
56unlike $ENV{PERL5LIB}, qr/\Q$dir2/, 'second dir was removed from lib';
57like $ENV{PERL_LOCAL_LIB_ROOT}, qr/\Q$dir1/, q{first dir didn't go away from root};
58like $ENV{PERL5LIB}, qr/\Q$dir1/, q{first dir didn't go away from lib};
59like $ENV{PERL_MM_OPT}, qr/\Q$dir1/, 'first dir stays installation target';