1*0Sstevel@tonic-gate#!./perl -w 2*0Sstevel@tonic-gate 3*0Sstevel@tonic-gateBEGIN { 4*0Sstevel@tonic-gate chdir 't'; 5*0Sstevel@tonic-gate @INC = '../lib'; 6*0Sstevel@tonic-gate @OrigINC = @INC; 7*0Sstevel@tonic-gate} 8*0Sstevel@tonic-gate 9*0Sstevel@tonic-gateuse Test::More tests => 13; 10*0Sstevel@tonic-gateuse Config; 11*0Sstevel@tonic-gateuse File::Spec; 12*0Sstevel@tonic-gateuse File::Path; 13*0Sstevel@tonic-gate 14*0Sstevel@tonic-gate#set up files and directories 15*0Sstevel@tonic-gatemy @lib_dir; 16*0Sstevel@tonic-gatemy $Lib_Dir; 17*0Sstevel@tonic-gatemy $Arch_Dir; 18*0Sstevel@tonic-gatemy $Auto_Dir; 19*0Sstevel@tonic-gatemy $Module; 20*0Sstevel@tonic-gateBEGIN { 21*0Sstevel@tonic-gate # lib.pm is documented to only work with Unix filepaths. 22*0Sstevel@tonic-gate @lib_dir = qw(stuff moo); 23*0Sstevel@tonic-gate $Lib_Dir = join "/", @lib_dir; 24*0Sstevel@tonic-gate $Arch_Dir = join "/", @lib_dir, $Config{archname}; 25*0Sstevel@tonic-gate 26*0Sstevel@tonic-gate # create the auto/ directory and a module 27*0Sstevel@tonic-gate $Auto_Dir = File::Spec->catdir(@lib_dir, $Config{archname},'auto'); 28*0Sstevel@tonic-gate $Module = File::Spec->catfile(@lib_dir, 'Yup.pm'); 29*0Sstevel@tonic-gate 30*0Sstevel@tonic-gate mkpath [$Auto_Dir]; 31*0Sstevel@tonic-gate 32*0Sstevel@tonic-gate open(MOD, ">$Module") || DIE $!; 33*0Sstevel@tonic-gate print MOD <<'MODULE'; 34*0Sstevel@tonic-gatepackage Yup; 35*0Sstevel@tonic-gate$Plan = 9; 36*0Sstevel@tonic-gatereturn '42'; 37*0Sstevel@tonic-gateMODULE 38*0Sstevel@tonic-gate 39*0Sstevel@tonic-gate close MOD; 40*0Sstevel@tonic-gate} 41*0Sstevel@tonic-gate 42*0Sstevel@tonic-gateEND { 43*0Sstevel@tonic-gate # cleanup the auto/ directory we created. 44*0Sstevel@tonic-gate rmtree([$lib_dir[0]]); 45*0Sstevel@tonic-gate} 46*0Sstevel@tonic-gate 47*0Sstevel@tonic-gate 48*0Sstevel@tonic-gateuse lib $Lib_Dir; 49*0Sstevel@tonic-gateuse lib $Lib_Dir; 50*0Sstevel@tonic-gate 51*0Sstevel@tonic-gateBEGIN { use_ok('Yup') } 52*0Sstevel@tonic-gate 53*0Sstevel@tonic-gateBEGIN { 54*0Sstevel@tonic-gate if ($^O eq 'MacOS') { 55*0Sstevel@tonic-gate for ($Lib_Dir, $Arch_Dir) { 56*0Sstevel@tonic-gate tr|/|:|; 57*0Sstevel@tonic-gate $_ .= ":" unless /:$/; 58*0Sstevel@tonic-gate $_ = ":$_" unless /^:/; # we know this path is relative 59*0Sstevel@tonic-gate } 60*0Sstevel@tonic-gate } 61*0Sstevel@tonic-gate is( $INC[1], $Lib_Dir, 'lib adding at end of @INC' ); 62*0Sstevel@tonic-gate print "# \@INC == @INC\n"; 63*0Sstevel@tonic-gate is( $INC[0], $Arch_Dir, ' auto/ dir in front of that' ); 64*0Sstevel@tonic-gate is( grep(/^\Q$Lib_Dir\E$/, @INC), 1, ' no duplicates' ); 65*0Sstevel@tonic-gate 66*0Sstevel@tonic-gate # Yes, %INC uses Unixy filepaths. 67*0Sstevel@tonic-gate # Not on Mac OS, it doesn't ... it never has, at least. 68*0Sstevel@tonic-gate my $path = join("/",$Lib_Dir, 'Yup.pm'); 69*0Sstevel@tonic-gate if ($^O eq 'MacOS') { 70*0Sstevel@tonic-gate $path = $Lib_Dir . 'Yup.pm'; 71*0Sstevel@tonic-gate } 72*0Sstevel@tonic-gate is( $INC{'Yup.pm'}, $path, '%INC set properly' ); 73*0Sstevel@tonic-gate 74*0Sstevel@tonic-gate is( eval { do 'Yup.pm' }, 42, 'do() works' ); 75*0Sstevel@tonic-gate ok( eval { require Yup; }, ' require()' ); 76*0Sstevel@tonic-gate ok( eval "use Yup; 1;", ' use()' ); 77*0Sstevel@tonic-gate is( $@, '' ); 78*0Sstevel@tonic-gate 79*0Sstevel@tonic-gate is_deeply(\@OrigINC, \@lib::ORIG_INC, '@lib::ORIG_INC' ); 80*0Sstevel@tonic-gate} 81*0Sstevel@tonic-gate 82*0Sstevel@tonic-gateno lib $Lib_Dir; 83*0Sstevel@tonic-gate 84*0Sstevel@tonic-gateunlike( do { eval 'use lib $Config{installsitelib};'; $@ || '' }, 85*0Sstevel@tonic-gate qr/::Config is read-only/, 'lib handles readonly stuff' ); 86*0Sstevel@tonic-gate 87*0Sstevel@tonic-gateBEGIN { 88*0Sstevel@tonic-gate is( grep(/stuff/, @INC), 0, 'no lib' ); 89*0Sstevel@tonic-gate ok( !do 'Yup.pm', ' do() effected' ); 90*0Sstevel@tonic-gate} 91