Some tests from Mouse for load_class and is_class_loaded
Shawn M Moore [Tue, 10 Jun 2008 05:01:20 +0000 (05:01 +0000)]
Changes
t/083_load_class.t [new file with mode: 0644]
t/lib/SyntaxError.pm [new file with mode: 0644]

diff --git a/Changes b/Changes
index bce3555..1553392 100644 (file)
--- a/Changes
+++ b/Changes
@@ -22,6 +22,8 @@ Revision history for Perl extension Class-MOP.
       - nonsensical (undef, empty, reference) class
         names now throw a more direct error in
         load_class (Sartak)
+        - tests for this and other aspects of
+          load_class (Sartak)
     
     * Class::MOP
       Class::MOP::Class      
diff --git a/t/083_load_class.t b/t/083_load_class.t
new file mode 100644 (file)
index 0000000..561c15f
--- /dev/null
@@ -0,0 +1,35 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More tests => 11;
+use Test::Exception;
+
+require Class::MOP;
+use lib 't/lib';
+
+ok(!Class::MOP::is_class_loaded(), "is_class_loaded with no argument returns false");
+ok(!Class::MOP::is_class_loaded(''), "can't load the empty class");
+ok(!Class::MOP::is_class_loaded(\"foo"), "can't load a class name reference??");
+
+throws_ok { Class::MOP::load_class()       } qr/Invalid class name \(undef\)/;
+throws_ok { Class::MOP::load_class('')     } qr/Invalid class name \(\)/;
+throws_ok { Class::MOP::load_class(\"foo") } qr/Invalid class name \(SCALAR\(\w+\)\)/;
+
+ok(Class::MOP::load_class('BinaryTree'));
+can_ok('BinaryTree' => 'traverse');
+
+do {
+    package Class;
+    sub method {}
+};
+
+ok(Class::MOP::load_class('Class'), "this should not die!");
+
+throws_ok {
+    Class::MOP::load_class('FakeClassOhNo');
+} qr/Can't locate /;
+
+throws_ok {
+    Class::MOP::load_class('SyntaxError');
+} qr/Missing right curly/;
+
diff --git a/t/lib/SyntaxError.pm b/t/lib/SyntaxError.pm
new file mode 100644 (file)
index 0000000..8d0e1e7
--- /dev/null
@@ -0,0 +1,11 @@
+#!/usr/bin/env perl
+package SyntaxError;
+use strict;
+use warnings;
+
+# this syntax error is intentional!
+
+    {
+
+1;
+