1#!./perl -w 2 3BEGIN { 4 @OrigINC = @INC; 5} 6 7use Test::More tests => 13; 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 # rmtree() can indirectly load the XS object for Win32, ensure 42 # we have our original sane @INC 43 local @INC = @OrigINC; 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. 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( $@, '', 'last "eval()" parsed and executed correctly' ); 69 70 is_deeply(\@OrigINC, \@lib::ORIG_INC, '@lib::ORIG_INC' ); 71} 72 73no lib $Lib_Dir; 74 75unlike( do { eval 'use lib $Config{installsitelib};'; $@ || '' }, 76 qr/::Config is read-only/, 'lib handles readonly stuff' ); 77 78BEGIN { 79 is( grep(/stuff/, @INC), 0, 'no lib' ); 80 ok( !do 'Yup.pm', ' do() effected' ); 81} 82