This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Perl_hv_placeholders_get() actually takes a const HV *hv.
[perl5.git] / lib / lib.t
CommitLineData
e7bf5e49
MS
1#!./perl -w
2
3BEGIN {
4 chdir 't';
6f03633b 5 unshift @INC, '..';
70f874d3 6 unshift @INC, '../lib';
e7bf5e49
MS
7 @OrigINC = @INC;
8}
9
57797241 10use Test::More tests => 13;
e7bf5e49
MS
11use Config;
12use File::Spec;
13use File::Path;
14
15#set up files and directories
16my @lib_dir;
17my $Lib_Dir;
18my $Arch_Dir;
19my $Auto_Dir;
20my $Module;
21BEGIN {
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';
35package Yup;
36$Plan = 9;
37return '42';
38MODULE
39
40 close MOD;
41}
42
43END {
44 # cleanup the auto/ directory we created.
45 rmtree([$lib_dir[0]]);
46}
47
48
49use lib $Lib_Dir;
50use lib $Lib_Dir;
51
52BEGIN { use_ok('Yup') }
53
54BEGIN {
d5201bd2
JH
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
MS
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
JH
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
MS
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
83no lib $Lib_Dir;
84
57797241
AB
85unlike( do { eval 'use lib $Config{installsitelib};'; $@ || '' },
86 qr/::Config is read-only/, 'lib handles readonly stuff' );
87
e7bf5e49
MS
88BEGIN {
89 is( grep(/stuff/, @INC), 0, 'no lib' );
90 ok( !do 'Yup.pm', ' do() effected' );
91}