1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
use strict;
use warnings;
use Test::Fatal;
use Test::More 0.88;
use lib 't/lib';
use Test::Class::Load 'load_first_existing_class';
is(
load_first_existing_class(
'Class::Load::Nonexistent', 'Class::Load::OK'
),
'Class::Load::OK',
'load_first_existing_class ignore nonexistent class'
);
is(
load_first_existing_class(
'Class::Load::Nonexistent', 'Class::Load::OK'
),
'Class::Load::OK',
'load_first_existing_class ignore nonexistent class - works when good class is already loaded'
);
like(
exception {
load_first_existing_class( 'Foo', 'bad name' );
},
qr/^\Q`bad name' is not a module name/,
'load_first_existing_class balks on bad class name'
);
like(
exception {
load_first_existing_class( 'Class::Load::Nonexistent', 'Class::Load::Nonexistent2' );
},
qr/^\QCan't locate Class::Load::Nonexistent or Class::Load::Nonexistent2 in \E\@INC/,
'load_first_existing_class throws an error when no classes can be loaded'
);
like(
exception {
load_first_existing_class(
'Class::Load::Nonexistent',
'Class::Load::Nonexistent2',
'Class::Load::Nonexistent3'
);
},
qr/^\QCan't locate Class::Load::Nonexistent, Class::Load::Nonexistent2, or Class::Load::Nonexistent3 in \E\@INC/,
'load_first_existing_class throws an error when no classes can be loaded'
);
like(
exception {
load_first_existing_class( 'Class::Load::Nonexistent' );
},
qr/^\QCan't locate Class::Load::Nonexistent in \E\@INC/,
'load_first_existing_class throws an error when given one class which it cannot load'
);
like(
exception {
load_first_existing_class(
'Class::Load::VersionCheck', { -version => 43 },
'Class::Load::VersionCheck2', { -version => 43 },
);
},
qr/^\QCan't locate Class::Load::VersionCheck (version >= 43) or Class::Load::VersionCheck2 (version >= 43) in \E\@INC/,
'load_first_existing_class throws an error when given multiple classes which it cannot load because of version checks'
);
like(
exception {
load_first_existing_class(
'Class::Load::VersionCheck', { -version => 43 },
'Class::Load::VersionCheck2', { -version => 43 },
'Class::Load::Nonexistent'
);
},
qr/^\QCan't locate Class::Load::VersionCheck (version >= 43), Class::Load::VersionCheck2 (version >= 43), or Class::Load::Nonexistent in \E\@INC/,
'load_first_existing_class throws an error when given multiple classes which it cannot load, some because of version checks'
);
like(
exception {
load_first_existing_class( 'Class::Load::VersionCheck', {-version => 43} );
},
qr/^\QCan't locate Class::Load::VersionCheck (version >= 43) in \E\@INC/,
'load_first_existing_class throws an error when given one class which it cannot load because of version checks'
);
like(
exception {
load_first_existing_class(
'Class::Load::VersionCheck2', { -version => 43 },
'Class::Load::SyntaxError', { -version => 43 },
'Class::Load::Nonexistent'
);
},
qr/^\QCouldn't load class (Class::Load::SyntaxError) because: Missing right curly or square bracket/,
'load_first_existing_class throws an error when a class fails to load because of a syntax error'
);
is(
load_first_existing_class(
'Class::Load::VersionCheck', { -version => 43 },
'Class::Load::VersionCheck2', { -version => 43 },
'Class::Load::OK'
),
'Class::Load::OK',
'load_first_existing_class returns loadable class when two classes fail version checks'
);
is(
load_first_existing_class(
'Class::Load::VersionCheck', { -version => 43 },
'Class::Load::VersionCheck2', { -version => 41 },
'Class::Load::OK'
),
'Class::Load::VersionCheck2',
'load_first_existing_class returns loadable class when a class passes the version check'
);
done_testing;
|