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