summaryrefslogtreecommitdiff
path: root/t/013-errors.t
blob: 38fd4a19d3a6fe223a83184493aa211524d89c60 (plain)
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::More 0.88;

use lib 't/lib';
use Test::Class::Load ':all';

my $file = __FILE__;

{
# line 1
    eval { load_class('Class::NonExistent') };
    my $e = $@;

    unlike(
        $e,
        qr/at .+Load\.pm line \d+/,
        'load_class exception does not refer to Class::Load internals'
    );

    unlike(
        $e,
        qr/at .+Runtime\.pm line \d+/,
        'load_class exception does not refer to Module::Runtime internals'
    );

    like(
        $e,
        qr/Can't locate [^\n]+ at \Q$file\E line 1/,
        'error appears from the spot that called load_class'
    );
}

{
    my ( $ok, $e ) = try_load_class('Class::NonExistent::Take2');

    unlike(
        $e,
        qr/at .+Load\.pm line \d+/,
        'try_load_class exception does not refer to Class::Load internals'
    );

    unlike(
        $e,
        qr/at .+Runtime\.pm line \d+/,
        'try_load_class exception does not refer to Module::Runtime internals'
    );
}

{
# line 2
    eval { load_first_existing_class('Class::NonExistent::Take3') };
    my $e = $@;

    unlike(
        $e,
        qr/at .+Load\.pm line \d+/,
        'load_first_existing_class exception does not refer to Class::Load internals'
    );

    unlike(
        $e,
        qr/at .+Runtime\.pm line \d+/,
        'load_first_existing_class exception does not refer to Module::Runtime internals'
    );

    like(
        $e,
        qr/Can't locate [^\n]+ at \Q$file\E line 2/,
        'error appears from the spot that called load_first_existing_class'
    );
}

{
# line 3
    eval { load_first_existing_class('Class::Load::SyntaxError') };
    my $e = $@;

    unlike(
        $e,
        qr/at .+Load\.pm line \d+/,
        'load_first_existing_class exception does not refer to Class::Load internals'
    );

    unlike(
        $e,
        qr/at .+Runtime\.pm line \d+/,
        'load_first_existing_class exception does not refer to Module::Runtime internals'
    );

    like(
        $e,
        qr/Compilation failed .+? at \Q$file\E line 3/s,
        'error appears from the spot that called load_first_existing_class'
    );
}

{
# line 4
    eval { load_optional_class('Class::Load::SyntaxError') };
    my $e = $@;

    unlike(
        $e,
        qr/at .+Load\.pm line \d+/,
        'load_optional_class exception does not refer to Class::Load internals'
    );

    unlike(
        $e,
        qr/at .+Runtime\.pm line \d+/,
        'load_optional_class exception does not refer to Module::Runtime internals'
    );

    like(
        $e,
        qr/Compilation failed .+? at \Q$file\E line 4/s,
        'error appears from the spot that called load_optional_class'
    );
}

done_testing();