This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Re: [ID 20020422.003] Suggestion in Perl 5.6.1 installation on AIX
[perl5.git] / lib / lib.t
CommitLineData
e7bf5e49
MS
1#!./perl -w
2
3BEGIN {
4 chdir 't';
5 @INC = '../lib';
6 @OrigINC = @INC;
7}
8
9use Test::More tests => 12;
10use Config;
11use File::Spec;
12use File::Path;
13
14#set up files and directories
15my @lib_dir;
16my $Lib_Dir;
17my $Arch_Dir;
18my $Auto_Dir;
19my $Module;
20BEGIN {
21 # lib.pm is documented to only work with Unix filepaths.
22 @lib_dir = qw(stuff moo);
23 $Lib_Dir = join "/", @lib_dir;
24 $Arch_Dir = join "/", @lib_dir, $Config{archname};
25
26 # create the auto/ directory and a module
27 $Auto_Dir = File::Spec->catdir(@lib_dir, $Config{archname},'auto');
28 $Module = File::Spec->catfile(@lib_dir, 'Yup.pm');
29
30 mkpath [$Auto_Dir];
31
32 open(MOD, ">$Module") || DIE $!;
33 print MOD <<'MODULE';
34package Yup;
35$Plan = 9;
36return '42';
37MODULE
38
39 close MOD;
40}
41
42END {
43 # cleanup the auto/ directory we created.
44 rmtree([$lib_dir[0]]);
45}
46
47
48use lib $Lib_Dir;
49use lib $Lib_Dir;
50
51BEGIN { use_ok('Yup') }
52
53BEGIN {
54 is( $INC[1], $Lib_Dir, 'lib adding at end of @INC' );
55 print "# \@INC == @INC\n";
56 is( $INC[0], $Arch_Dir, ' auto/ dir in front of that' );
57 is( grep(/^\Q$Lib_Dir\E$/, @INC), 1, ' no duplicates' );
58
59 # Yes, %INC uses Unixy filepaths.
60 is( $INC{'Yup.pm'}, join("/",$Lib_Dir, 'Yup.pm'), '%INC set properly' );
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
72BEGIN {
73 is( grep(/stuff/, @INC), 0, 'no lib' );
74 ok( !do 'Yup.pm', ' do() effected' );
75}