This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Upgrade initialization code in vms/vms.c.
[perl5.git] / dist / lib / t / 01lib.t
CommitLineData
e7bf5e49
MS
1#!./perl -w
2
3BEGIN {
e7bf5e49
MS
4 @OrigINC = @INC;
5}
6
57797241 7use Test::More tests => 13;
e7bf5e49
MS
8use Config;
9use File::Spec;
10use File::Path;
11
12#set up files and directories
13my @lib_dir;
14my $Lib_Dir;
15my $Arch_Dir;
16my $Auto_Dir;
17my $Module;
18BEGIN {
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';
32package Yup;
33$Plan = 9;
34return '42';
35MODULE
36
37 close MOD;
38}
39
40END {
41 # cleanup the auto/ directory we created.
42 rmtree([$lib_dir[0]]);
43}
44
45
46use lib $Lib_Dir;
47use lib $Lib_Dir;
48
49BEGIN { use_ok('Yup') }
50
51BEGIN {
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
JH
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
MS
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
70no lib $Lib_Dir;
71
57797241
AB
72unlike( do { eval 'use lib $Config{installsitelib};'; $@ || '' },
73 qr/::Config is read-only/, 'lib handles readonly stuff' );
74
e7bf5e49
MS
75BEGIN {
76 is( grep(/stuff/, @INC), 0, 'no lib' );
77 ok( !do 'Yup.pm', ' do() effected' );
78}