Commit | Line | Data |
d9183506 |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
ae29b412 |
6 | use Test::More tests => 18; |
7 | use Class::MOP; |
d9183506 |
8 | |
9 | use lib "t/lib"; |
10 | |
11 | BEGIN { use_ok("Catalyst::Utils") }; |
12 | |
13 | { |
14 | package This::Module::Is::Not::In::Inc::But::Does::Exist; |
15 | sub moose {}; |
16 | } |
17 | |
18 | my $warnings = 0; |
ae29b412 |
19 | $SIG{__WARN__} = sub { |
20 | return if $_[0] =~ /Subroutine (?:un|re|)initialize redefined at .*C3\.pm/; |
21 | $warnings++; |
22 | }; |
d9183506 |
23 | |
ae29b412 |
24 | ok( !Class::MOP::is_class_loaded("TestApp::View::Dump"), "component not yet loaded" ); |
d9183506 |
25 | |
26 | Catalyst::Utils::ensure_class_loaded("TestApp::View::Dump"); |
27 | |
ae29b412 |
28 | ok( Class::MOP::is_class_loaded("TestApp::View::Dump"), "loaded ok" ); |
d9183506 |
29 | is( $warnings, 0, "no warnings emitted" ); |
30 | |
31 | $warnings = 0; |
32 | |
33 | Catalyst::Utils::ensure_class_loaded("TestApp::View::Dump"); |
34 | is( $warnings, 0, "calling again doesn't reaload" ); |
35 | |
ae29b412 |
36 | ok( !Class::MOP::is_class_loaded("TestApp::View::Dump::Request"), "component not yet loaded" ); |
d9183506 |
37 | |
38 | Catalyst::Utils::ensure_class_loaded("TestApp::View::Dump::Request"); |
ae29b412 |
39 | ok( Class::MOP::is_class_loaded("TestApp::View::Dump::Request"), "loaded ok" ); |
d9183506 |
40 | |
41 | is( $warnings, 0, "calling again doesn't reaload" ); |
42 | |
43 | undef $@; |
44 | eval { Catalyst::Utils::ensure_class_loaded("This::Module::Is::Probably::Not::There") }; |
45 | ok( $@, "doesn't defatalize" ); |
46 | like( $@, qr/There\.pm.*\@INC/, "error looks right" ); |
47 | |
7a1958eb |
48 | undef $@; |
49 | eval { Catalyst::Utils::ensure_class_loaded("__PACKAGE__") }; |
50 | ok( $@, "doesn't defatalize" ); |
51 | like( $@, qr/__PACKAGE__\.pm.*\@INC/, "errors sanely on __PACKAGE__.pm" ); |
52 | |
d9183506 |
53 | $@ = "foo"; |
54 | Catalyst::Utils::ensure_class_loaded("TestApp::View::Dump::Response"); |
55 | is( $@, "foo", '$@ is untouched' ); |
56 | |
57 | undef $@; |
58 | eval { Catalyst::Utils::ensure_class_loaded("This::Module::Is::Not::In::Inc::But::Does::Exist") }; |
59 | ok( !$@, "no error when loading non existent .pm that *does* have a symbol table entry" ); |
60 | |
59ede84e |
61 | undef $@; |
62 | eval { Catalyst::Utils::ensure_class_loaded('Silly::File::.#Name') }; |
63 | like($@, qr/Malformed class Name/, 'errored when attempting to load a file beginning with a .'); |
64 | |
65 | undef $@; |
66 | eval { Catalyst::Utils::ensure_class_loaded('Silly::File::Name.pm') }; |
67 | like($@, qr/Malformed class Name/, 'errored sanely when given a classname ending in .pm'); |
68 | |
ae29b412 |
69 | undef $@; |
70 | $warnings = 0; |
71 | Catalyst::Utils::ensure_class_loaded("NullPackage"); |
72 | is( $warnings, 1, 'Loading a package which defines no symbols warns'); |
73 | is( $@, undef, '$@ still undef' ); |
74 | |