From: Shawn M Moore Date: Tue, 10 Jun 2008 05:01:20 +0000 (+0000) Subject: Some tests from Mouse for load_class and is_class_loaded X-Git-Tag: 0_64~29 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3f7759c160390e2f0a77a3d78323ff00992f5977;p=gitmo%2FClass-MOP.git Some tests from Mouse for load_class and is_class_loaded --- diff --git a/Changes b/Changes index bce3555..1553392 100644 --- 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 index 0000000..561c15f --- /dev/null +++ b/t/083_load_class.t @@ -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 index 0000000..8d0e1e7 --- /dev/null +++ b/t/lib/SyntaxError.pm @@ -0,0 +1,11 @@ +#!/usr/bin/env perl +package SyntaxError; +use strict; +use warnings; + +# this syntax error is intentional! + + { + +1; +