1*0Sstevel@tonic-gate#!./perl -Tw 2*0Sstevel@tonic-gate 3*0Sstevel@tonic-gateBEGIN { 4*0Sstevel@tonic-gate chdir 't' if -d 't'; 5*0Sstevel@tonic-gate @INC = '../lib'; 6*0Sstevel@tonic-gate} 7*0Sstevel@tonic-gate 8*0Sstevel@tonic-gateuse strict; 9*0Sstevel@tonic-gateuse File::Spec; 10*0Sstevel@tonic-gatemy($blib, $blib_arch, $blib_lib, @blib_dirs); 11*0Sstevel@tonic-gate 12*0Sstevel@tonic-gatesub _cleanup { 13*0Sstevel@tonic-gate rmdir foreach reverse (@_); 14*0Sstevel@tonic-gate unlink "stderr" unless $^O eq 'MacOS'; 15*0Sstevel@tonic-gate} 16*0Sstevel@tonic-gate 17*0Sstevel@tonic-gatesub _mkdirs { 18*0Sstevel@tonic-gate for my $dir (@_) { 19*0Sstevel@tonic-gate next if -d $dir; 20*0Sstevel@tonic-gate mkdir $dir or die "Can't mkdir $dir: $!" if ! -d $dir; 21*0Sstevel@tonic-gate } 22*0Sstevel@tonic-gate} 23*0Sstevel@tonic-gate 24*0Sstevel@tonic-gate 25*0Sstevel@tonic-gateBEGIN { 26*0Sstevel@tonic-gate if ($^O eq 'MacOS') 27*0Sstevel@tonic-gate { 28*0Sstevel@tonic-gate $MacPerl::Architecture = $MacPerl::Architecture; # shhhhh 29*0Sstevel@tonic-gate $blib = ":blib:"; 30*0Sstevel@tonic-gate $blib_lib = ":blib:lib:"; 31*0Sstevel@tonic-gate $blib_arch = ":blib:lib:$MacPerl::Architecture:"; 32*0Sstevel@tonic-gate @blib_dirs = ($blib, $blib_lib, $blib_arch); # order 33*0Sstevel@tonic-gate } 34*0Sstevel@tonic-gate else 35*0Sstevel@tonic-gate { 36*0Sstevel@tonic-gate $blib = "blib"; 37*0Sstevel@tonic-gate $blib_arch = "blib/arch"; 38*0Sstevel@tonic-gate $blib_lib = "blib/lib"; 39*0Sstevel@tonic-gate @blib_dirs = ($blib, $blib_arch, $blib_lib); 40*0Sstevel@tonic-gate } 41*0Sstevel@tonic-gate _cleanup( @blib_dirs ); 42*0Sstevel@tonic-gate} 43*0Sstevel@tonic-gate 44*0Sstevel@tonic-gateuse Test::More tests => 7; 45*0Sstevel@tonic-gate 46*0Sstevel@tonic-gateeval 'use blib;'; 47*0Sstevel@tonic-gateok( $@ =~ /Cannot find blib/, 'Fails if blib directory not found' ); 48*0Sstevel@tonic-gate 49*0Sstevel@tonic-gate_mkdirs( @blib_dirs ); 50*0Sstevel@tonic-gate 51*0Sstevel@tonic-gate{ 52*0Sstevel@tonic-gate my $warnings = ''; 53*0Sstevel@tonic-gate local $SIG{__WARN__} = sub { $warnings = join '', @_ }; 54*0Sstevel@tonic-gate use_ok('blib'); 55*0Sstevel@tonic-gate is( $warnings, '', 'use blib is nice and quiet' ); 56*0Sstevel@tonic-gate} 57*0Sstevel@tonic-gate 58*0Sstevel@tonic-gateis( @INC, 3, '@INC now has 3 elements' ); 59*0Sstevel@tonic-gateis( $INC[2], '../lib', 'blib added to the front of @INC' ); 60*0Sstevel@tonic-gate 61*0Sstevel@tonic-gateif ($^O eq 'VMS') { 62*0Sstevel@tonic-gate # Unix syntax is accepted going in but it's not what comes out 63*0Sstevel@tonic-gate # So we don't use catdir above 64*0Sstevel@tonic-gate $blib_arch = 'blib.arch]'; 65*0Sstevel@tonic-gate $blib_lib = 'blib.lib]'; 66*0Sstevel@tonic-gate} 67*0Sstevel@tonic-gateelsif ($^O ne 'MacOS') 68*0Sstevel@tonic-gate{ 69*0Sstevel@tonic-gate $blib_arch = File::Spec->catdir("blib","arch"); 70*0Sstevel@tonic-gate $blib_lib = File::Spec->catdir("blib","lib"); 71*0Sstevel@tonic-gate} 72*0Sstevel@tonic-gate 73*0Sstevel@tonic-gate 74*0Sstevel@tonic-gateok( grep(m|\Q$blib_lib\E$|, @INC[0,1]) == 1, " $blib_lib in \@INC"); 75*0Sstevel@tonic-gateok( grep(m|\Q$blib_arch\E$|, @INC[0,1]) == 1, " $blib_arch in \@INC"); 76*0Sstevel@tonic-gate 77*0Sstevel@tonic-gateEND { _cleanup( @blib_dirs ); } 78