Commit | Line | Data |
e7bf5e49 |
1 | #!./perl -w |
2 | |
3 | BEGIN { |
4 | chdir 't'; |
6f03633b |
5 | unshift @INC, '..'; |
70f874d3 |
6 | unshift @INC, '../lib'; |
e7bf5e49 |
7 | @OrigINC = @INC; |
8 | } |
9 | |
57797241 |
10 | use Test::More tests => 13; |
e7bf5e49 |
11 | use Config; |
12 | use File::Spec; |
13 | use File::Path; |
14 | |
15 | #set up files and directories |
16 | my @lib_dir; |
17 | my $Lib_Dir; |
18 | my $Arch_Dir; |
19 | my $Auto_Dir; |
20 | my $Module; |
21 | BEGIN { |
22 | # lib.pm is documented to only work with Unix filepaths. |
23 | @lib_dir = qw(stuff moo); |
24 | $Lib_Dir = join "/", @lib_dir; |
25 | $Arch_Dir = join "/", @lib_dir, $Config{archname}; |
26 | |
27 | # create the auto/ directory and a module |
28 | $Auto_Dir = File::Spec->catdir(@lib_dir, $Config{archname},'auto'); |
29 | $Module = File::Spec->catfile(@lib_dir, 'Yup.pm'); |
30 | |
31 | mkpath [$Auto_Dir]; |
32 | |
33 | open(MOD, ">$Module") || DIE $!; |
34 | print MOD <<'MODULE'; |
35 | package Yup; |
36 | $Plan = 9; |
37 | return '42'; |
38 | MODULE |
39 | |
40 | close MOD; |
41 | } |
42 | |
43 | END { |
44 | # cleanup the auto/ directory we created. |
45 | rmtree([$lib_dir[0]]); |
46 | } |
47 | |
48 | |
49 | use lib $Lib_Dir; |
50 | use lib $Lib_Dir; |
51 | |
52 | BEGIN { use_ok('Yup') } |
53 | |
54 | BEGIN { |
d5201bd2 |
55 | if ($^O eq 'MacOS') { |
56 | for ($Lib_Dir, $Arch_Dir) { |
57 | tr|/|:|; |
58 | $_ .= ":" unless /:$/; |
59 | $_ = ":$_" unless /^:/; # we know this path is relative |
60 | } |
61 | } |
e7bf5e49 |
62 | is( $INC[1], $Lib_Dir, 'lib adding at end of @INC' ); |
63 | print "# \@INC == @INC\n"; |
64 | is( $INC[0], $Arch_Dir, ' auto/ dir in front of that' ); |
65 | is( grep(/^\Q$Lib_Dir\E$/, @INC), 1, ' no duplicates' ); |
66 | |
67 | # Yes, %INC uses Unixy filepaths. |
d5201bd2 |
68 | # Not on Mac OS, it doesn't ... it never has, at least. |
69 | my $path = join("/",$Lib_Dir, 'Yup.pm'); |
70 | if ($^O eq 'MacOS') { |
71 | $path = $Lib_Dir . 'Yup.pm'; |
72 | } |
73 | is( $INC{'Yup.pm'}, $path, '%INC set properly' ); |
e7bf5e49 |
74 | |
75 | is( eval { do 'Yup.pm' }, 42, 'do() works' ); |
76 | ok( eval { require Yup; }, ' require()' ); |
77 | ok( eval "use Yup; 1;", ' use()' ); |
78 | is( $@, '' ); |
79 | |
80 | is_deeply(\@OrigINC, \@lib::ORIG_INC, '@lib::ORIG_INC' ); |
81 | } |
82 | |
83 | no lib $Lib_Dir; |
84 | |
57797241 |
85 | unlike( do { eval 'use lib $Config{installsitelib};'; $@ || '' }, |
86 | qr/::Config is read-only/, 'lib handles readonly stuff' ); |
87 | |
e7bf5e49 |
88 | BEGIN { |
89 | is( grep(/stuff/, @INC), 0, 'no lib' ); |
90 | ok( !do 'Yup.pm', ' do() effected' ); |
91 | } |