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