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