X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F90ensure_class_loaded.t;h=3fc828ecac6e2b8c5e7812a9cd8dfbc92fb83393;hb=a63219bc9b7102be940ea56af8e6cd77960a1c63;hp=672450b1af0a0b79cd5cde2c0696fc863474915a;hpb=efe6365bc168c25205c527e0e088bd7229a3575b;p=dbsrgits%2FDBIx-Class.git diff --git a/t/90ensure_class_loaded.t b/t/90ensure_class_loaded.t index 672450b..3fc828e 100644 --- a/t/90ensure_class_loaded.t +++ b/t/90ensure_class_loaded.t @@ -13,7 +13,7 @@ BEGIN { my $schema = DBICTest->init_schema(); -plan tests => 17; +plan tests => 20; # Test ensure_class_found ok( $schema->ensure_class_found('DBIx::Class::Schema'), @@ -37,7 +37,8 @@ $retval = eval { $schema->load_optional_class('DBICTest::OptionalComponent') }; ok( !$@, 'load_optional_class on an existing class did not throw' ); ok( $retval, 'DBICTest::OptionalComponent loaded' ); eval { $schema->load_optional_class('DBICTest::ErrorComponent') }; -like( $@, qr/did not return a true value/, 'DBICTest::ErrorComponent threw ok' ); +like( $@, qr/did not return a true value/, + 'DBICTest::ErrorComponent threw ok' ); # Test ensure_class_loaded ok( Class::Inspector->loaded('TestPackage::A'), 'anonymous package exists' ); @@ -53,4 +54,34 @@ ok( !$@, 'ensure_class_loaded detected an existing but non-loaded class' ); ok( Class::Inspector->loaded('DBICTest::FakeComponent'), 'DBICTest::FakeComponent now loaded' ); +{ + # Squash warnings about syntax errors in SytaxErrorComponent.pm + local $SIG{__WARN__} = sub { + my $warning = shift; + warn $warning unless ( + $warning =~ /String found where operator expected/ or + $warning =~ /Missing operator before/ + ); + }; + + eval { $schema->ensure_class_loaded('DBICTest::SyntaxErrorComponent1') }; + like( $@, qr/syntax error/, + 'ensure_class_loaded(DBICTest::SyntaxErrorComponent1) threw ok' ); + eval { $schema->load_optional_class('DBICTest::SyntaxErrorComponent2') }; + like( $@, qr/syntax error/, + 'load_optional_class(DBICTest::SyntaxErrorComponent2) threw ok' ); +} + + +eval { + package Fake::ResultSet; + + use base 'DBIx::Class::ResultSet'; + + __PACKAGE__->load_components('+DBICTest::SyntaxErrorComponent3'); +}; + +# Make sure the errors in components of resultset classes are reported right. +like($@, qr!\Qsyntax error at t/lib/DBICTest/SyntaxErrorComponent3.pm!, "Errors from RS components reported right"); + 1;