De-dup @INC and $ENV{PERL5LIB} entries
[p5sagit/local-lib.git] / t / de-dup.t
1 use strict;
2 use warnings;
3 use Test::More;
4 use File::Temp qw(tempdir);
5 use Cwd;
6
7 plan tests => 4;
8
9 my $dir = tempdir('test_local_lib-XXXXX', DIR => Cwd::abs_path('t'), CLEANUP => 1);
10
11 use local::lib ();
12 local::lib->import($dir);
13 local::lib->import($dir);
14
15 {
16     my (%inc, %perl5lib);
17     map { $inc{$_}++ } @INC;
18     map { $perl5lib{$_} } split /:/, $ENV{PERL5LIB};
19     ok ! grep({ $inc{$_} > 1 } keys %inc), '@INC entries not duplicated';
20 use Data::Dumper;
21 warn Dumper(\@INC);
22     ok ! grep({ $perl5lib{$_} > 1 } keys %perl5lib), 'ENV{PERL5LIB} entries not duplicated';
23 }
24
25 local::lib->import('--self-contained', $dir);
26
27 {
28     my (%inc, %perl5lib);
29     map { $inc{$_}++ } @INC;
30     map { $perl5lib{$_} } split /:/, $ENV{PERL5LIB};
31     ok ! grep({ $inc{$_} > 1 } keys %inc), '@INC entries not duplicated (--self-contained)';
32     ok ! grep({ $perl5lib{$_} > 1 } keys %perl5lib), 'ENV{PERL5LIB} entries not duplicated (--self-contained)';
33 }
34