adding docs on how to maintain multiple perls
[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
b0e4e8db 11my $dir1 = tempdir('test_local_lib-XXXXX', DIR => Cwd::abs_path('t'), CLEANUP => 1);
f694b8aa 12$dir1 = local::lib->ensure_dir_structure_for($dir1);
b0e4e8db 13
f694b8aa 14my $dir2 = tempdir('test_local_lib-XXXXX', DIR => Cwd::abs_path('t'), CLEANUP => 1);
15$dir2 = local::lib->ensure_dir_structure_for($dir2);
b0e4e8db 16
a20a4a55 17my $prev_active = () = local::lib->active_paths;
18
b0e4e8db 19local::lib->import($dir1);
a20a4a55 20is +() = local::lib->active_paths, $prev_active + 1, 'one active path';
b0e4e8db 21like $ENV{PERL_LOCAL_LIB_ROOT}, qr/\Q$dir1/, 'added one dir in root';
22like $ENV{PERL5LIB}, qr/\Q$dir1/, 'added one dir in lib';
6369ed6d 23like $ENV{PERL_MM_OPT}, qr/\Q$dir1/, 'first path is installation target';
24
25local::lib->import($dir1);
a20a4a55 26is +() = local::lib->active_paths, $prev_active + 1, 'still one active path after adding it twice';
b0e4e8db 27
28local::lib->import($dir2);
a20a4a55 29is +() = local::lib->active_paths, $prev_active + 2, 'two active paths';
b0e4e8db 30like $ENV{PERL_LOCAL_LIB_ROOT}, qr/\Q$dir2/, 'added another dir in root';
31like $ENV{PERL5LIB}, qr/\Q$dir2/, 'added another dir in lib';
32like $ENV{PERL_LOCAL_LIB_ROOT}, qr/\Q$dir1/, 'first dir is still in root';
33like $ENV{PERL5LIB}, qr/\Q$dir1/, 'first dir is still in lib';
6369ed6d 34like $ENV{PERL_MM_OPT}, qr/\Q$dir2/, 'second path is installation target';
35
36local::lib->import($dir1);
37my @active = local::lib->active_paths;
a20a4a55 38is @active, $prev_active + 2, 'still two active dirs after re-adding first';
6369ed6d 39is $active[-1], $dir1, 'first dir was re-added on top';
40like $ENV{PERL_MM_OPT}, qr/\Q$dir1/, 'first path is installation target again';
b0e4e8db 41
6369ed6d 42local::lib->import('--deactivate', $dir2);
43unlike $ENV{PERL_LOCAL_LIB_ROOT}, qr/\Q$dir2/, 'second dir was removed from root';
44unlike $ENV{PERL5LIB}, qr/\Q$dir2/, 'second dir was removed from lib';
45like $ENV{PERL_LOCAL_LIB_ROOT}, qr/\Q$dir1/, q{first dir didn't go away from root};
46like $ENV{PERL5LIB}, qr/\Q$dir1/, q{first dir didn't go away from lib};
47like $ENV{PERL_MM_OPT}, qr/\Q$dir1/, 'first dir stays installation target';