X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F90ensure_class_loaded.t;h=f14911dce80b0a81a5e47e3cc1cc2bcebe6c4df7;hb=67341081b1a57cc8549e51a8fb1b8cd4661543c5;hp=3fc828ecac6e2b8c5e7812a9cd8dfbc92fb83393;hpb=a63219bc9b7102be940ea56af8e6cd77960a1c63;p=dbsrgits%2FDBIx-Class.git diff --git a/t/90ensure_class_loaded.t b/t/90ensure_class_loaded.t index 3fc828e..f14911d 100644 --- a/t/90ensure_class_loaded.t +++ b/t/90ensure_class_loaded.t @@ -1,5 +1,5 @@ use strict; -use warnings; +use warnings; use Test::More; use lib qw(t/lib); @@ -13,7 +13,7 @@ BEGIN { my $schema = DBICTest->init_schema(); -plan tests => 20; +plan tests => 28; # Test ensure_class_found ok( $schema->ensure_class_found('DBIx::Class::Schema'), @@ -40,6 +40,50 @@ eval { $schema->load_optional_class('DBICTest::ErrorComponent') }; like( $@, qr/did not return a true value/, 'DBICTest::ErrorComponent threw ok' ); +# Simulate a PAR environment +{ + my @code; + local @INC = @INC; + unshift @INC, sub { + if ($_[1] eq 'VIRTUAL/PAR/PACKAGE.pm') { + return (sub { return 0 unless @code; $_ = shift @code; 1; } ); + } + else { + return (); + } + }; + + $retval = eval { $schema->load_optional_class('FAKE::PAR::PACKAGE') }; + ok( !$@, 'load_optional_class on a nonexistent PAR class did not throw' ); + ok( !$retval, 'nonexistent PAR package not loaded' ); + + + # simulate a class which does load but does not return true + @code = ( + q/package VIRTUAL::PAR::PACKAGE;/, + q/0;/, + ); + + $retval = eval { $schema->load_optional_class('VIRTUAL::PAR::PACKAGE') }; + ok( $@, 'load_optional_class of a no-true-returning PAR module did throw' ); + ok( !$retval, 'no-true-returning PAR package not loaded' ); + + # simulate a normal class (no one adjusted %INC so it will be tried again + @code = ( + q/package VIRTUAL::PAR::PACKAGE;/, + q/1;/, + ); + + $retval = eval { $schema->load_optional_class('VIRTUAL::PAR::PACKAGE') }; + ok( !$@, 'load_optional_class of a PAR module did not throw' ); + ok( $retval, 'PAR package "loaded"' ); + + # see if we can still load stuff with the coderef present + $retval = eval { $schema->load_optional_class('DBIx::Class::ResultClass::HashRefInflator') }; + ok( !$@, 'load_optional_class did not throw' ) || diag $@; + ok( $retval, 'DBIx::Class::ResultClass::HashRefInflator loaded' ); +} + # Test ensure_class_loaded ok( Class::Inspector->loaded('TestPackage::A'), 'anonymous package exists' ); eval { $schema->ensure_class_loaded('TestPackage::A'); };