reverse order of PERL_LOCAL_LIB_ROOT to match standard env order
[p5sagit/local-lib.git] / t / stackable.t
1 use strict;
2 use warnings;
3 use Test::More;
4 use File::Spec;
5 use Config;
6
7 plan tests => 24;
8
9 use local::lib ();
10
11 use lib 't/lib'; use TempDir;
12
13 my $dir1 = mk_temp_dir('test_local_lib-XXXXX');
14 my $dir2 = mk_temp_dir('test_local_lib-XXXXX');
15
16 my ($dir1_arch, $dir2_arch) = map { File::Spec->catfile($_, qw'lib perl5', $Config{archname}) } $dir1, $dir2;
17 note $dir1_arch;
18 note $dir2_arch;
19
20
21 my $prev_active = () = local::lib->active_paths;
22
23 local::lib->import($dir1);
24 is +() = local::lib->active_paths, $prev_active + 1, 'one active path';
25 like $ENV{PERL_LOCAL_LIB_ROOT}, qr/\Q$dir1/, 'added one dir in root';
26 like $ENV{PERL5LIB}, qr/\Q$dir1/, 'added one dir in lib';
27 note $ENV{PERL5LIB};
28 unlike $ENV{PERL5LIB}, qr/\Q$dir1_arch/, 'no arch in PERL5LIB';
29 my $dir1_escape = local::lib::_mm_escape_path($dir1);
30 like $ENV{PERL_MM_OPT}, qr/\Q$dir1_escape/, 'first path is installation target';
31
32 local::lib->import($dir1);
33 is +() = local::lib->active_paths, $prev_active + 1, 'still one active path after adding it twice';
34
35 local::lib->import($dir2);
36 is +() = local::lib->active_paths, $prev_active + 2, 'two active paths';
37 like $ENV{PERL_LOCAL_LIB_ROOT}, qr/\Q$dir2/, 'added another dir in root';
38 like $ENV{PERL5LIB}, qr/\Q$dir2/, 'added another dir in lib';
39 unlike $ENV{PERL5LIB}, qr/\Q$dir2_arch/, 'no arch in PERL5LIB';
40 like $ENV{PERL_LOCAL_LIB_ROOT}, qr/\Q$dir1/, 'first dir is still in root';
41 like $ENV{PERL5LIB}, qr/\Q$dir1/, 'first dir is still in lib';
42 unlike $ENV{PERL5LIB}, qr/\Q$dir1_arch/, 'no arch in PERL5LIB';
43 my $dir2_escape = local::lib::_mm_escape_path($dir2);
44 like $ENV{PERL_MM_OPT}, qr/\Q$dir2_escape/, 'second path is installation target';
45
46 local::lib->import($dir1);
47 my @active = local::lib->active_paths;
48 is @active, $prev_active + 2, 'still two active dirs after re-adding first';
49 is $active[0], $dir1, 'first dir was re-added on top';
50 like $ENV{PERL_MM_OPT}, qr/\Q$dir1_escape/, 'first path is installation target again';
51
52 local::lib->import('--deactivate', $dir2);
53 unlike $ENV{PERL_LOCAL_LIB_ROOT}, qr/\Q$dir2/, 'second dir was removed from root';
54 unlike $ENV{PERL5LIB}, qr/\Q$dir2/, 'second dir was removed from lib';
55 unlike $ENV{PERL5LIB}, qr/\Q$dir2_arch/, 'no arch in PERL5LIB';
56 like $ENV{PERL_LOCAL_LIB_ROOT}, qr/\Q$dir1/, q{first dir didn't go away from root};
57 like $ENV{PERL5LIB}, qr/\Q$dir1/, q{first dir didn't go away from lib};
58 unlike $ENV{PERL5LIB}, qr/\Q$dir1_arch/, 'no arch in PERL5LIB';
59 like $ENV{PERL_MM_OPT}, qr/\Q$dir1_escape/, 'first dir stays installation target';