line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Unit::ITestRunner; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
20779
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
4
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
5
|
1
|
|
|
1
|
|
4
|
use base 'Test::Unit::TestRunner'; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
734
|
|
6
|
|
|
|
|
|
|
use Time::HiRes; |
7
|
|
|
|
|
|
|
our $VERSION = '0.05'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
my $ITESTRUNNER_TEST_WARNINGS = []; |
10
|
|
|
|
|
|
|
my $ITESTRUNNER_TEST_TIMINGS = []; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
BEGIN { |
13
|
|
|
|
|
|
|
$ENV{ITESTRUNNER_TEST_WARNINGS_COUNTER} = 0; |
14
|
|
|
|
|
|
|
$SIG{'__WARN__'} = sub { |
15
|
|
|
|
|
|
|
my $warning = shift; |
16
|
|
|
|
|
|
|
push(@{$ITESTRUNNER_TEST_WARNINGS}, $warning); |
17
|
|
|
|
|
|
|
$ENV{ITESTRUNNER_TEST_WARNINGS_COUNTER} ++; |
18
|
|
|
|
|
|
|
}; |
19
|
|
|
|
|
|
|
}; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub start |
22
|
|
|
|
|
|
|
{ |
23
|
|
|
|
|
|
|
my $self = shift; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# print startup warnings |
26
|
|
|
|
|
|
|
$self->_printWarnings; |
27
|
|
|
|
|
|
|
$ITESTRUNNER_TEST_WARNINGS = []; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
return $self->SUPER::start(@_); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub do_run |
33
|
|
|
|
|
|
|
{ |
34
|
|
|
|
|
|
|
my $self = shift; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# print test load warnings |
37
|
|
|
|
|
|
|
$self->_printWarnings; |
38
|
|
|
|
|
|
|
$ITESTRUNNER_TEST_WARNINGS = []; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
return $self->SUPER::do_run(@_); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub start_test |
44
|
|
|
|
|
|
|
{ |
45
|
|
|
|
|
|
|
my $self = shift; |
46
|
|
|
|
|
|
|
my ($test) = @_; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
$self->{current_test_started_at} = $self->_getHiResTime; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
$ITESTRUNNER_TEST_WARNINGS = []; |
51
|
|
|
|
|
|
|
my $testcase = ref($test); |
52
|
|
|
|
|
|
|
my $testname = $test->name; |
53
|
|
|
|
|
|
|
$self->_print("$testcase - $testname"); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub add_error |
58
|
|
|
|
|
|
|
{ |
59
|
|
|
|
|
|
|
my $self = shift; |
60
|
|
|
|
|
|
|
my ($test, $exception) = @_; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
$self->_printSpaces($test, '.'); |
63
|
|
|
|
|
|
|
$self->_colorPrint('bold red', "[ERROR]\n"); |
64
|
|
|
|
|
|
|
$self->_printWarnings; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub add_failure |
68
|
|
|
|
|
|
|
{ |
69
|
|
|
|
|
|
|
my $self = shift; |
70
|
|
|
|
|
|
|
my ($test, $exception) = @_; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
$self->_printSpaces($test, '.'); |
73
|
|
|
|
|
|
|
$self->_colorPrint('bold light_yellow', "[FAIL]\n"); |
74
|
|
|
|
|
|
|
$self->_printWarnings; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub add_pass |
78
|
|
|
|
|
|
|
{ |
79
|
|
|
|
|
|
|
my $self = shift; |
80
|
|
|
|
|
|
|
my ($test) = @_; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
$self->_printSpaces($test); |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
$self->_colorPrint('light_green', "[OK]"); |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
my $started_at = $self->{current_test_started_at}; |
87
|
|
|
|
|
|
|
my $time = $self->_getHiResTime - $started_at; |
88
|
|
|
|
|
|
|
$time = sprintf("%0.3f", $time); |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
my $testcase = ref($test); |
91
|
|
|
|
|
|
|
my $testname = $test->name; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
push(@{$ITESTRUNNER_TEST_TIMINGS}, { test => "$testcase - $testname", timing => $time}); |
94
|
|
|
|
|
|
|
$self->{current_test_started_at} = 0; |
95
|
|
|
|
|
|
|
my $time_warning = 0; |
96
|
|
|
|
|
|
|
$time_warning = 1 if $ENV{ITESTRUNNER_MAXTIME} && $time > $ENV{ITESTRUNNER_MAXTIME}; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
if ($time_warning) { |
99
|
|
|
|
|
|
|
$self->_colorPrint('bold red', " $time sec\n"); |
100
|
|
|
|
|
|
|
}else{ |
101
|
|
|
|
|
|
|
$self->_print(" $time sec\n"); |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
$self->_printWarnings; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub print_result |
107
|
|
|
|
|
|
|
{ |
108
|
|
|
|
|
|
|
my $self = shift; |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
my @results = $self->SUPER::print_result(@_); |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
if ($ENV{ITESTRUNNER_TEST_WARNINGS_COUNTER}) { |
113
|
|
|
|
|
|
|
$self->_colorPrint('bold light_blue', "Warnings: ". $ENV{ITESTRUNNER_TEST_WARNINGS_COUNTER} . "\n"); |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
return @results unless $ENV{ITESTRUNNER_SLOWTEST_TOP}; |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
$ITESTRUNNER_TEST_TIMINGS ||= []; |
120
|
|
|
|
|
|
|
my @slow_tests = sort {$b->{timing} <=> $a->{timing}} @{$ITESTRUNNER_TEST_TIMINGS}; |
121
|
|
|
|
|
|
|
print "\nSlow tests top:\n"; |
122
|
|
|
|
|
|
|
my $count = $ENV{ITESTRUNNER_SLOWTEST_TOP}; |
123
|
|
|
|
|
|
|
for my $slow_test(@slow_tests){ |
124
|
|
|
|
|
|
|
$count--; |
125
|
|
|
|
|
|
|
$self->_print($slow_test->{timing} . " sec\t". $slow_test->{test} . "\n"); |
126
|
|
|
|
|
|
|
last unless $count; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
return @results; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub _getHiResTime |
133
|
|
|
|
|
|
|
{ |
134
|
|
|
|
|
|
|
my $self = shift; |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
return Time::HiRes::time(); |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub _printSpaces |
140
|
|
|
|
|
|
|
{ |
141
|
|
|
|
|
|
|
my $self = shift; |
142
|
|
|
|
|
|
|
my ($test, $space) = @_; |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
$space ||= ' '; |
145
|
|
|
|
|
|
|
my $base = $ENV{ITESTRUNNER_WIDTH} || 120; |
146
|
|
|
|
|
|
|
my $testcase = ref($test); |
147
|
|
|
|
|
|
|
my $testname = $test->name; |
148
|
|
|
|
|
|
|
my $spaces = $base - length("$testcase - $testname"); |
149
|
|
|
|
|
|
|
$self->_print("$space" x $spaces); |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
sub _printWarnings |
153
|
|
|
|
|
|
|
{ |
154
|
|
|
|
|
|
|
my $self = shift; |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
return unless $ITESTRUNNER_TEST_WARNINGS && @{$ITESTRUNNER_TEST_WARNINGS}; |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
for my $warning(@{$ITESTRUNNER_TEST_WARNINGS}){ |
159
|
|
|
|
|
|
|
$self->_colorPrint('light_blue', "$warning\n"); |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
sub _colorPrint |
164
|
|
|
|
|
|
|
{ |
165
|
|
|
|
|
|
|
my $self = shift; |
166
|
|
|
|
|
|
|
my ($colors, $text) = @_; |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
$text = $self->_colorizeText($colors, $text) if $ENV{ITESTRUNNER_COLORIZE}; |
169
|
|
|
|
|
|
|
$self->_print($text); |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
sub _colorizeText |
173
|
|
|
|
|
|
|
{ |
174
|
|
|
|
|
|
|
my $self = shift; |
175
|
|
|
|
|
|
|
my ($colors, $text) = @_; |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
return $text unless $colors; |
178
|
|
|
|
|
|
|
for my $color(split /\s+/, $colors){ |
179
|
|
|
|
|
|
|
my $code = $self->_getColorCode($color); |
180
|
|
|
|
|
|
|
$text = "\e[${code}m$text"; |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
return $text . "\e[0m"; |
184
|
|
|
|
|
|
|
} |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
sub _getColorCode |
187
|
|
|
|
|
|
|
{ |
188
|
|
|
|
|
|
|
my $self = shift; |
189
|
|
|
|
|
|
|
my ($color) = @_; |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
return { |
192
|
|
|
|
|
|
|
bold => "1", |
193
|
|
|
|
|
|
|
red => "31", |
194
|
|
|
|
|
|
|
light_yellow => "93", |
195
|
|
|
|
|
|
|
light_green => "92", |
196
|
|
|
|
|
|
|
light_blue => "94", |
197
|
|
|
|
|
|
|
'reset' => "0", |
198
|
|
|
|
|
|
|
}->{$color}; |
199
|
|
|
|
|
|
|
} |
200
|
|
|
|
|
|
|
1; |
201
|
|
|
|
|
|
|
__END__ |