Moved bignum from lib/ to ext/
[p5sagit/p5-mst-13.2.git] / lib / lib.t
CommitLineData
e7bf5e49 1#!./perl -w
2
3BEGIN {
4 chdir 't';
6f03633b 5 unshift @INC, '..';
70f874d3 6 unshift @INC, '../lib';
e7bf5e49 7 @OrigINC = @INC;
8}
9
57797241 10use Test::More tests => 13;
e7bf5e49 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 {
55 is( $INC[1], $Lib_Dir, 'lib adding at end of @INC' );
56 print "# \@INC == @INC\n";
57 is( $INC[0], $Arch_Dir, ' auto/ dir in front of that' );
58 is( grep(/^\Q$Lib_Dir\E$/, @INC), 1, ' no duplicates' );
59
60 # Yes, %INC uses Unixy filepaths.
d5201bd2 61 # Not on Mac OS, it doesn't ... it never has, at least.
62 my $path = join("/",$Lib_Dir, 'Yup.pm');
d5201bd2 63 is( $INC{'Yup.pm'}, $path, '%INC set properly' );
e7bf5e49 64
65 is( eval { do 'Yup.pm' }, 42, 'do() works' );
66 ok( eval { require Yup; }, ' require()' );
67 ok( eval "use Yup; 1;", ' use()' );
68 is( $@, '' );
69
70 is_deeply(\@OrigINC, \@lib::ORIG_INC, '@lib::ORIG_INC' );
71}
72
73no lib $Lib_Dir;
74
57797241 75unlike( do { eval 'use lib $Config{installsitelib};'; $@ || '' },
76 qr/::Config is read-only/, 'lib handles readonly stuff' );
77
e7bf5e49 78BEGIN {
79 is( grep(/stuff/, @INC), 0, 'no lib' );
80 ok( !do 'Yup.pm', ' do() effected' );
81}