1#!/usr/bin/perl -w 2 3use strict; 4 5####################################################################### 6 7sub array_diff { 8 my ( $got, $expected ) = @_; 9 push @$got, ( '(missing)' ) x ( @$expected - @$got ) if @$got < @$expected; 10 push @$expected, ( '(should not exist)' ) x ( @$got - @$expected ) if @$got > @$expected; 11 join "\n ", ' All differences:', ( 12 map +( "got [$_] " . $got->[$_], 'expected'.(' ' x length).$expected->[$_] ), 13 grep $got->[$_] ne $expected->[$_], 14 0 .. $#$got 15 ); 16} 17 18####################################################################### 19 20use Test::More tests => 8; # some extra tests in t/lib/BaseInc* 21 22use lib 't/lib', sub {()}; 23 24# make it look like an older perl 25BEGIN { push @INC, '.' if $INC[-1] ne '.' } 26 27BEGIN { 28 my $x = sub { CORE::require $_[0] }; 29 my $y = sub { &$x }; 30 my $z = sub { &$y }; 31 *CORE::GLOBAL::require = $z; 32} 33 34my @expected; BEGIN { @expected = @INC } 35 36use base 'BaseIncMandatory'; 37 38BEGIN { 39 @t::lib::Dummy::ISA = (); # make it look like an optional load 40 my $success = eval q{use base 't::lib::Dummy'}, my $err = $@; 41 ok !$success, 'loading optional modules from . using base.pm fails'; 42 is_deeply \@INC, \@expected, '... without changes to @INC' 43 or diag array_diff [@INC], [@expected]; 44 like $err, qr!Base class package "t::lib::Dummy" is not empty but "t/lib/Dummy\.pm" exists in the current directory\.!, 45 '... and the proper error message'; 46} 47 48BEGIN { @BaseIncOptional::ISA = () } # make it look like an optional load 49use base 'BaseIncOptional'; 50 51BEGIN { 52 @expected = ( 't/lib/on-head', @expected, 't/lib/on-tail' ); 53 is_deeply \@INC, \@expected, 'modules loaded by base can extend @INC at both ends' 54 or diag array_diff [@INC], [@expected]; 55} 56