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