oops, some of these variables aren't always initialized
[p5sagit/local-lib.git] / t / bad_variables.t
1 use strict;
2 use warnings;
3 use Test::More tests => 5;
4 use File::Temp 'tempdir';
5 use local::lib ();
6
7 # remember the original value of this, in case we are already running inside a
8 # local::lib
9 my $orig_llr = $ENV{PERL_LOCAL_LIB_ROOT} || '';
10
11 my $dir1 = tempdir('test_local_lib-XXXXX', DIR => Cwd::abs_path('t'), CLEANUP => 1);
12 my $dir2 = tempdir('test_local_lib-XXXXX', DIR => Cwd::abs_path('t'), CLEANUP => 1);
13 my $dir3 = tempdir('test_local_lib-XXXXX', DIR => Cwd::abs_path('t'), CLEANUP => 1);
14
15 ok(!(grep { $dir1 eq $_ } @INC), 'new dir is not already in @INC');
16 ok(!(grep { $dir1 eq $_ } split /:/, ($ENV{PERL5LIB}||'')), 'new dir is not already in PERL5LIB');
17
18 local::lib->import($dir1);
19 local::lib->import($dir2);
20
21 # we have junk in here now
22 $ENV{PERL_LOCAL_LIB_ROOT} .= ':' . $dir3;
23
24 local::lib->import($dir1);
25
26 is(
27     $ENV{PERL_LOCAL_LIB_ROOT},
28     join(':', (grep { $_ } $orig_llr, $dir2, $dir1)),
29     'dir1 should have been removed and added back in at the top',
30 );
31
32 ok((grep { /\Q$dir1\E/ } @INC), 'new dir has been added to @INC');
33 ok((grep { /\Q$dir1\E/ } split /:/, $ENV{PERL5LIB}), 'new dir has been added to PERL5LIB');
34