Moved bignum from lib/ to ext/
[p5sagit/p5-mst-13.2.git] / lib / lib.t
1 #!./perl -w
2
3 BEGIN {
4     chdir 't';
5     unshift @INC, '..';
6     unshift @INC, '../lib';
7     @OrigINC = @INC;
8 }
9
10 use Test::More tests => 13;
11 use Config;
12 use File::Spec;
13 use File::Path;
14
15 #set up files and directories
16 my @lib_dir;
17 my $Lib_Dir;
18 my $Arch_Dir;
19 my $Auto_Dir;
20 my $Module;
21 BEGIN {
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';
35 package Yup;
36 $Plan = 9;
37 return '42';
38 MODULE
39
40     close MOD;
41 }
42
43 END {
44     # cleanup the auto/ directory we created.
45     rmtree([$lib_dir[0]]);
46 }
47
48
49 use lib $Lib_Dir;
50 use lib $Lib_Dir;
51
52 BEGIN { use_ok('Yup') }
53
54 BEGIN {
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.
61     # Not on Mac OS, it doesn't ... it never has, at least.
62     my $path = join("/",$Lib_Dir, 'Yup.pm');
63     is( $INC{'Yup.pm'}, $path,    '%INC set properly' );
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
73 no lib $Lib_Dir;
74
75 unlike( do { eval 'use lib $Config{installsitelib};'; $@ || '' },
76         qr/::Config is read-only/, 'lib handles readonly stuff' );
77
78 BEGIN {
79     is( grep(/stuff/, @INC), 0, 'no lib' );
80     ok( !do 'Yup.pm',           '   do() effected' );
81 }