Commit | Line | Data |
b0e4e8db |
1 | use strict; |
2 | use warnings; |
3 | use Test::More; |
4 | use File::Temp qw(tempdir); |
5 | use Cwd; |
6 | |
6369ed6d |
7 | plan tests => 19; |
b0e4e8db |
8 | |
f694b8aa |
9 | use local::lib (); |
10 | |
b0e4e8db |
11 | my $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 |
14 | my $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 |
17 | my $prev_active = () = local::lib->active_paths; |
18 | |
b0e4e8db |
19 | local::lib->import($dir1); |
a20a4a55 |
20 | is +() = local::lib->active_paths, $prev_active + 1, 'one active path'; |
b0e4e8db |
21 | like $ENV{PERL_LOCAL_LIB_ROOT}, qr/\Q$dir1/, 'added one dir in root'; |
22 | like $ENV{PERL5LIB}, qr/\Q$dir1/, 'added one dir in lib'; |
6369ed6d |
23 | like $ENV{PERL_MM_OPT}, qr/\Q$dir1/, 'first path is installation target'; |
24 | |
25 | local::lib->import($dir1); |
a20a4a55 |
26 | is +() = local::lib->active_paths, $prev_active + 1, 'still one active path after adding it twice'; |
b0e4e8db |
27 | |
28 | local::lib->import($dir2); |
a20a4a55 |
29 | is +() = local::lib->active_paths, $prev_active + 2, 'two active paths'; |
b0e4e8db |
30 | like $ENV{PERL_LOCAL_LIB_ROOT}, qr/\Q$dir2/, 'added another dir in root'; |
31 | like $ENV{PERL5LIB}, qr/\Q$dir2/, 'added another dir in lib'; |
32 | like $ENV{PERL_LOCAL_LIB_ROOT}, qr/\Q$dir1/, 'first dir is still in root'; |
33 | like $ENV{PERL5LIB}, qr/\Q$dir1/, 'first dir is still in lib'; |
6369ed6d |
34 | like $ENV{PERL_MM_OPT}, qr/\Q$dir2/, 'second path is installation target'; |
35 | |
36 | local::lib->import($dir1); |
37 | my @active = local::lib->active_paths; |
a20a4a55 |
38 | is @active, $prev_active + 2, 'still two active dirs after re-adding first'; |
6369ed6d |
39 | is $active[-1], $dir1, 'first dir was re-added on top'; |
40 | like $ENV{PERL_MM_OPT}, qr/\Q$dir1/, 'first path is installation target again'; |
b0e4e8db |
41 | |
6369ed6d |
42 | local::lib->import('--deactivate', $dir2); |
43 | unlike $ENV{PERL_LOCAL_LIB_ROOT}, qr/\Q$dir2/, 'second dir was removed from root'; |
44 | unlike $ENV{PERL5LIB}, qr/\Q$dir2/, 'second dir was removed from lib'; |
45 | like $ENV{PERL_LOCAL_LIB_ROOT}, qr/\Q$dir1/, q{first dir didn't go away from root}; |
46 | like $ENV{PERL5LIB}, qr/\Q$dir1/, q{first dir didn't go away from lib}; |
47 | like $ENV{PERL_MM_OPT}, qr/\Q$dir1/, 'first dir stays installation target'; |