1use strict;
2use warnings;
3use Test::More tests => 6;
4use Config;
5use local::lib ();
6
7use lib 't/lib'; use TempDir;
8
9delete $ENV{PERL_LOCAL_LIB_ROOT};
10
11my $dir1 = mk_temp_ll_dir;
12my $dir2 = mk_temp_ll_dir;
13my $dir3 = mk_temp_ll_dir;
14
15ok(!(grep { $dir1 eq $_ } @INC), 'new dir is not already in @INC');
16ok(!(grep { $dir1 eq $_ } split /\Q$Config{path_sep}\E/, ($ENV{PERL5LIB}||'')), 'new dir is not already in PERL5LIB');
17
18local::lib->import($dir1);
19local::lib->import($dir2);
20
21# we have junk in here now
22$ENV{PERL_LOCAL_LIB_ROOT} = $dir3 . $Config{path_sep} . $ENV{PERL_LOCAL_LIB_ROOT};
23
24local::lib->import($dir1);
25
26is(
27    $ENV{PERL_LOCAL_LIB_ROOT},
28    join($Config{path_sep}, (grep { defined $_ and $_ ne '' } $dir1, $dir3, $dir2)),
29    'dir1 should have been removed and added back in at the top'
30);
31
32ok((!grep { $_ eq $dir3 } local::lib->active_paths), 'junk dir added not included in active_paths');
33
34ok((grep { /\Q$dir1\E/ } @INC), 'new dir has been added to @INC');
35ok((grep { /\Q$dir1\E/ } split /\Q$Config{path_sep}\E/, $ENV{PERL5LIB}), 'new dir has been added to PERL5LIB');
36