| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# Base class for Test::Mini test cases. |
|
2
|
|
|
|
|
|
|
# |
|
3
|
|
|
|
|
|
|
# @see Test::Mini::Runner |
|
4
|
|
|
|
|
|
|
package Test::Mini::TestCase; |
|
5
|
4
|
|
|
4
|
|
1850
|
use strict; |
|
|
4
|
|
|
|
|
14
|
|
|
|
4
|
|
|
|
|
143
|
|
|
6
|
4
|
|
|
4
|
|
21
|
use warnings; |
|
|
4
|
|
|
|
|
7
|
|
|
|
4
|
|
|
|
|
141
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
4
|
|
|
4
|
|
1563
|
use Test::Mini; |
|
|
4
|
|
|
|
|
9
|
|
|
|
4
|
|
|
|
|
190
|
|
|
9
|
4
|
|
|
4
|
|
3970
|
use Exception::Class; |
|
|
4
|
|
|
|
|
54619
|
|
|
|
4
|
|
|
|
|
26
|
|
|
10
|
4
|
|
|
4
|
|
3230
|
use Test::Mini::Assertions; |
|
|
4
|
|
|
|
|
16
|
|
|
|
4
|
|
|
|
|
32
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# Constructor. |
|
13
|
|
|
|
|
|
|
# |
|
14
|
|
|
|
|
|
|
# @private |
|
15
|
|
|
|
|
|
|
# @param [Hash] %args Initial state for the new instance. |
|
16
|
|
|
|
|
|
|
# @option %args name The specific test this instance should run. |
|
17
|
|
|
|
|
|
|
sub new { |
|
18
|
54
|
|
|
54
|
1
|
165
|
my ($class, %args) = @_; |
|
19
|
54
|
|
|
|
|
350
|
return bless { %args, passed => 0 }, $class; |
|
20
|
|
|
|
|
|
|
} |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# Test setup behavior, automatically invoked prior to each test. Intended to |
|
23
|
|
|
|
|
|
|
# be overridden by subclasses. |
|
24
|
|
|
|
|
|
|
# |
|
25
|
|
|
|
|
|
|
# @example |
|
26
|
|
|
|
|
|
|
# package TestSomething; |
|
27
|
|
|
|
|
|
|
# use base 'Test::Mini::TestCase'; |
|
28
|
|
|
|
|
|
|
# |
|
29
|
|
|
|
|
|
|
# use Something; |
|
30
|
|
|
|
|
|
|
# |
|
31
|
|
|
|
|
|
|
# sub setup { $obj = Something->new(); } |
|
32
|
|
|
|
|
|
|
# |
|
33
|
|
|
|
|
|
|
# sub test_can_foo { |
|
34
|
|
|
|
|
|
|
# assert_can($obj, 'foo'); |
|
35
|
|
|
|
|
|
|
# } |
|
36
|
|
|
|
|
|
|
# |
|
37
|
|
|
|
|
|
|
# @see #teardown |
|
38
|
|
|
|
|
|
|
sub setup { |
|
39
|
36
|
|
|
36
|
1
|
69
|
my ($self) = @_; |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# Test teardown behavior, automatically invoked following each test. Intended |
|
43
|
|
|
|
|
|
|
# to be overridden by subclasses. |
|
44
|
|
|
|
|
|
|
# |
|
45
|
|
|
|
|
|
|
# @example |
|
46
|
|
|
|
|
|
|
# package Test; |
|
47
|
|
|
|
|
|
|
# use base 'Test::Mini::TestCase'; |
|
48
|
|
|
|
|
|
|
# |
|
49
|
|
|
|
|
|
|
# sub teardown { unlink 'foo.bar' } |
|
50
|
|
|
|
|
|
|
# |
|
51
|
|
|
|
|
|
|
# sub test_touching_files { |
|
52
|
|
|
|
|
|
|
# `touch foo.bar`; |
|
53
|
|
|
|
|
|
|
# assert(-f 'foo.bar'); |
|
54
|
|
|
|
|
|
|
# } |
|
55
|
|
|
|
|
|
|
# |
|
56
|
|
|
|
|
|
|
# @see #setup |
|
57
|
|
|
|
|
|
|
sub teardown { |
|
58
|
54
|
|
|
54
|
1
|
109
|
my ($self) = @_; |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# Runs the test specified at construction time. This method is responsible |
|
62
|
|
|
|
|
|
|
# for invoking the setup and teardown advice for the method, in addition to |
|
63
|
|
|
|
|
|
|
# ensuring that any fatal errors encountered by the program are suitably |
|
64
|
|
|
|
|
|
|
# handled. Appropriate diagnostic information should be sent to the supplied |
|
65
|
|
|
|
|
|
|
# +$runner+. |
|
66
|
|
|
|
|
|
|
# |
|
67
|
|
|
|
|
|
|
# @private |
|
68
|
|
|
|
|
|
|
# @param [Test::Mini::Runner] $runner |
|
69
|
|
|
|
|
|
|
# @return The number of assertions called by this test. |
|
70
|
|
|
|
|
|
|
sub run { |
|
71
|
54
|
|
|
54
|
1
|
85
|
my ($self, $runner) = @_; |
|
72
|
54
|
|
|
|
|
59
|
my $e; |
|
73
|
54
|
|
|
|
|
144
|
my $test = $self->{name}; |
|
74
|
|
|
|
|
|
|
|
|
75
|
54
|
|
|
|
|
88
|
eval { |
|
76
|
|
|
|
|
|
|
local $SIG{__DIE__} = sub { |
|
77
|
|
|
|
|
|
|
# Package declaration for isolating the callstack. |
|
78
|
|
|
|
|
|
|
# @api private |
|
79
|
|
|
|
|
|
|
package Test::Mini::SIGDIE; |
|
80
|
|
|
|
|
|
|
|
|
81
|
21
|
100
|
|
21
|
|
3841
|
die $_[0] if UNIVERSAL::isa($_[0], 'Test::Mini::Exception'); |
|
82
|
|
|
|
|
|
|
|
|
83
|
17
|
|
|
|
|
288
|
(my $msg = "@_") =~ s/ at .*? line \d+\.\n$//; |
|
84
|
17
|
|
|
|
|
199
|
my $error = Test::Mini::Exception->new( |
|
85
|
|
|
|
|
|
|
message => "$msg\n", |
|
86
|
|
|
|
|
|
|
ignore_package => [qw/ Test::Mini::SIGDIE Carp /], |
|
87
|
|
|
|
|
|
|
); |
|
88
|
|
|
|
|
|
|
|
|
89
|
17
|
|
|
|
|
13858
|
my $me = $error->trace->frame(0); |
|
90
|
17
|
50
|
|
|
|
16764
|
if ($me->{subroutine} eq 'Test::Mini::TestCase::__ANON__') { |
|
91
|
17
|
|
|
|
|
322
|
$me->{subroutine} = 'die'; |
|
92
|
17
|
|
|
|
|
51
|
$me->{args} = [ $msg ]; |
|
93
|
|
|
|
|
|
|
} |
|
94
|
|
|
|
|
|
|
|
|
95
|
17
|
|
|
|
|
186
|
die $error; |
|
96
|
54
|
|
|
|
|
410
|
}; |
|
97
|
|
|
|
|
|
|
|
|
98
|
54
|
|
|
|
|
259
|
$self->setup(); |
|
99
|
54
|
|
|
|
|
253
|
$self->$test(); |
|
100
|
49
|
|
|
|
|
228
|
$self->{passed} = 1; |
|
101
|
|
|
|
|
|
|
|
|
102
|
49
|
100
|
|
|
|
153
|
die 'No assertions called' unless count_assertions(); |
|
103
|
|
|
|
|
|
|
}; |
|
104
|
|
|
|
|
|
|
|
|
105
|
54
|
100
|
|
|
|
578
|
if ($e = Exception::Class->caught()) { |
|
106
|
6
|
|
|
|
|
383
|
$self->{passed} = 0; |
|
107
|
|
|
|
|
|
|
|
|
108
|
6
|
100
|
|
|
|
20
|
if ($e = Exception::Class->caught('Test::Mini::Exception::Skip')) { |
|
|
|
100
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
109
|
1
|
|
|
|
|
21
|
$runner->skip(ref $self, $test, $e); |
|
110
|
|
|
|
|
|
|
} |
|
111
|
|
|
|
|
|
|
elsif ($e = Exception::Class->caught('Test::Mini::Exception::Assert')) { |
|
112
|
3
|
|
|
|
|
100
|
$runner->fail(ref $self, $test, $e); |
|
113
|
|
|
|
|
|
|
} |
|
114
|
|
|
|
|
|
|
elsif ($e = Exception::Class->caught('Test::Mini::Exception')) { |
|
115
|
2
|
|
|
|
|
86
|
$runner->error(ref $self, $test, $e); |
|
116
|
|
|
|
|
|
|
} |
|
117
|
|
|
|
|
|
|
} |
|
118
|
|
|
|
|
|
|
|
|
119
|
54
|
|
|
|
|
339
|
eval { |
|
120
|
54
|
|
|
|
|
241
|
$self->teardown(); |
|
121
|
54
|
100
|
|
|
|
355
|
$runner->pass(ref $self, $self->{name}) if $self->{passed}; |
|
122
|
|
|
|
|
|
|
}; |
|
123
|
54
|
50
|
|
|
|
338
|
if ($e = Exception::Class->caught()) { |
|
124
|
0
|
|
|
|
|
0
|
$runner->error(ref $self, $test, $e); |
|
125
|
|
|
|
|
|
|
} |
|
126
|
|
|
|
|
|
|
|
|
127
|
54
|
|
|
|
|
668
|
return reset_assertions(); |
|
128
|
|
|
|
|
|
|
} |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
1; |