move mk_temp_dir into a lib so we can reuse it
[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 like $ENV{PERL_MM_OPT}, qr/\Q$dir1/, 'first path is installation target';
30
31 local::lib->import($dir1);
32 is +() = local::lib->active_paths, $prev_active + 1, 'still one active path after adding it twice';
33
34 local::lib->import($dir2);
35 is +() = local::lib->active_paths, $prev_active + 2, 'two active paths';
36 like $ENV{PERL_LOCAL_LIB_ROOT}, qr/\Q$dir2/, 'added another dir in root';
37 like $ENV{PERL5LIB}, qr/\Q$dir2/, 'added another dir in lib';
38 unlike $ENV{PERL5LIB}, qr/\Q$dir2_arch/, 'no arch in PERL5LIB';
39 like $ENV{PERL_LOCAL_LIB_ROOT}, qr/\Q$dir1/, 'first dir is still in root';
40 like $ENV{PERL5LIB}, qr/\Q$dir1/, 'first dir is still in lib';
41 unlike $ENV{PERL5LIB}, qr/\Q$dir1_arch/, 'no arch in PERL5LIB';
42 like $ENV{PERL_MM_OPT}, qr/\Q$dir2/, 'second path is installation target';
43
44 local::lib->import($dir1);
45 my @active = local::lib->active_paths;
46 is @active, $prev_active + 2, 'still two active dirs after re-adding first';
47 is $active[-1], $dir1, 'first dir was re-added on top';
48 like $ENV{PERL_MM_OPT}, qr/\Q$dir1/, 'first path is installation target again';
49
50 local::lib->import('--deactivate', $dir2);
51 unlike $ENV{PERL_LOCAL_LIB_ROOT}, qr/\Q$dir2/, 'second dir was removed from root';
52 unlike $ENV{PERL5LIB}, qr/\Q$dir2/, 'second dir was removed from lib';
53 unlike $ENV{PERL5LIB}, qr/\Q$dir2_arch/, 'no arch in PERL5LIB';
54 like $ENV{PERL_LOCAL_LIB_ROOT}, qr/\Q$dir1/, q{first dir didn't go away from root};
55 like $ENV{PERL5LIB}, qr/\Q$dir1/, q{first dir didn't go away from lib};
56 unlike $ENV{PERL5LIB}, qr/\Q$dir1_arch/, 'no arch in PERL5LIB';
57 like $ENV{PERL_MM_OPT}, qr/\Q$dir1/, 'first dir stays installation target';