allow safe overriding of immutable_trait
[gitmo/Class-MOP.git] / t / 083_load_class.t
index d68166e..22a10af 100644 (file)
@@ -1,7 +1,6 @@
-#!/usr/bin/env perl
 use strict;
 use warnings;
-use Test::More tests => 28;
+use Test::More tests => 34;
 use Test::Exception;
 
 require Class::MOP;
@@ -52,6 +51,15 @@ throws_ok {
 qr/Missing right curly/;
 
 throws_ok {
+    delete $INC{'SyntaxError.pm'};
+    Class::MOP::load_first_existing_class(
+        'FakeClassOhNo', 'SyntaxError', 'Class'
+    );
+}
+qr/Missing right curly/,
+    'load_first_existing_class does not pass over an existing (bad) module';
+
+throws_ok {
     Class::MOP::load_class('This::Does::Not::Exist');
 }
 qr/Could not load class \(This::Does::Not::Exist\) because :/,
@@ -83,4 +91,35 @@ throws_ok {
     Class::MOP::load_first_existing_class("Does::Not::Exist", "Also::Does::Not::Exist")
 } qr/Could not load class \(Does::Not::Exist.*Could not load class \(Also::Does::Not::Exist/s, 'Multiple non-existant classes cause exception';
 
+{
+    sub whatever {
+        TestClassLoaded::this_method_does_not_even_exist();
+    }
+
+    ok( ! Class::MOP::is_class_loaded('TestClassLoaded'),
+        'the mere mention of TestClassLoaded in the whatever sub does not make us think it has been loaded' );
+}
+
+{
+    require TestClassLoaded::Sub;
+    ok( ! Class::MOP::is_class_loaded('TestClassLoaded'),
+        'requiring TestClassLoaded::Sub does not make us think TestClassLoaded is loaded' );
+}
 
+{
+    require TestClassLoaded;
+    ok( Class::MOP::is_class_loaded('TestClassLoaded'),
+        'We see that TestClassLoaded is loaded after requiring it (it has methods but no $VERSION or @ISA)' );
+}
+
+{
+    require TestClassLoaded2;
+    ok( Class::MOP::is_class_loaded('TestClassLoaded2'),
+        'We see that TestClassLoaded2 is loaded after requiring it (it has a $VERSION but no methods or @ISA)' );
+}
+
+{
+    require TestClassLoaded3;
+    ok( Class::MOP::is_class_loaded('TestClassLoaded3'),
+        'We see that TestClassLoaded3 is loaded after requiring it (it has an @ISA but no methods or $VERSION)' );
+}