line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# This is a makeover of Test::Harness to allow its tests |
2
|
|
|
|
|
|
|
# to be retrofitted as unit tests. |
3
|
|
|
|
|
|
|
package Test::Unit::UnitHarness; |
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
192
|
BEGIN {require 5.002;} |
6
|
2
|
|
|
2
|
|
10
|
use base qw(Test::Unit::Runner Test::Unit::Test Exporter); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
255
|
|
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
11
|
use Config; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
87
|
|
9
|
2
|
|
|
2
|
|
9
|
use Carp; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
129
|
|
10
|
2
|
|
|
2
|
|
11
|
use Class::Inner; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
41
|
|
11
|
2
|
|
|
2
|
|
10
|
use FileHandle; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
15
|
|
12
|
|
|
|
|
|
|
|
13
|
2
|
|
|
2
|
|
813
|
use Test::Unit::Debug qw(debug); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
89
|
|
14
|
2
|
|
|
2
|
|
11
|
use Test::Unit::TestCase; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
47
|
|
15
|
2
|
|
|
2
|
|
16
|
use Test::Unit::Exception; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
18
|
|
16
|
|
|
|
|
|
|
|
17
|
2
|
|
|
2
|
|
101
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
81
|
|
18
|
|
|
|
|
|
|
|
19
|
2
|
|
|
|
|
2289
|
use vars qw($VERSION $verbose $switches $have_devel_corestack $curtest |
20
|
2
|
|
|
2
|
|
9
|
@EXPORT @EXPORT_OK); |
|
2
|
|
|
|
|
3
|
|
21
|
|
|
|
|
|
|
$have_devel_corestack = 0; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
$VERSION = "1.1502"; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
@EXPORT = qw(&runtests); |
26
|
|
|
|
|
|
|
@EXPORT_OK = qw($verbose $switches); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
$verbose = 0; |
29
|
|
|
|
|
|
|
$switches = "-w"; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# class and object methods |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub new { |
34
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
35
|
0
|
|
|
|
|
|
my ($name) = @_; |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
my @_Tests = (); |
38
|
0
|
|
|
|
|
|
my $self = { |
39
|
|
|
|
|
|
|
_Tests => \@_Tests, |
40
|
|
|
|
|
|
|
_Name => $name, |
41
|
|
|
|
|
|
|
_Names => [], |
42
|
|
|
|
|
|
|
}; |
43
|
0
|
|
|
|
|
|
bless $self, $class; |
44
|
0
|
|
|
|
|
|
debug(ref($self) . "::new($name) called\n"); |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
return $self; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub run { |
50
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
51
|
0
|
|
|
|
|
|
my $result = shift; |
52
|
0
|
|
|
|
|
|
my $test = $self->{_Name}; |
53
|
0
|
|
|
|
|
|
my $fh = new FileHandle; |
54
|
0
|
|
|
|
|
|
my $next = 1; |
55
|
0
|
|
|
|
|
|
my $max = 0; |
56
|
0
|
|
|
|
|
|
my $message = ""; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# pass -I flags to children |
59
|
0
|
|
|
|
|
|
my $old5lib = $ENV{PERL5LIB}; |
60
|
0
|
|
|
|
|
|
local($ENV{'PERL5LIB'}) = join($Config{path_sep}, @INC); |
61
|
|
|
|
|
|
|
|
62
|
0
|
0
|
|
|
|
|
if ($^O eq 'VMS') { $switches =~ s/-(\S*[A-Z]\S*)/"-$1"/g } |
|
0
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
|
64
|
0
|
0
|
|
|
|
|
$fh->open($test) or print "can't open $test. $!\n"; |
65
|
0
|
|
|
|
|
|
my $first = <$fh>; |
66
|
0
|
|
|
|
|
|
my $s = $switches; |
67
|
0
|
0
|
|
|
|
|
$s .= q[ "-T"] if $first =~ /^#!.*\bperl.*-\w*T/; |
68
|
0
|
0
|
|
|
|
|
$fh->close or print "can't close $test. $!\n"; |
69
|
0
|
|
|
|
|
|
my $cmd = "$^X $s $test|"; |
70
|
0
|
0
|
|
|
|
|
$cmd = "MCR $cmd" if $^O eq 'VMS'; |
71
|
0
|
0
|
|
|
|
|
$fh->open($cmd) or print "can't run $test. $!\n"; |
72
|
0
|
|
|
|
|
|
for my $line (<$fh>) { |
73
|
0
|
0
|
|
|
|
|
print $line if $verbose; |
74
|
|
|
|
|
|
|
|
75
|
0
|
0
|
0
|
|
|
|
if ($line =~ /^1\.\.([0-9]+)/) { |
|
|
0
|
|
|
|
|
|
76
|
|
|
|
|
|
|
# Not supported in Result - It's needed!!! |
77
|
|
|
|
|
|
|
#$result->plan($1); |
78
|
0
|
|
|
|
|
|
$next = 1; |
79
|
0
|
|
|
|
|
|
$max = $1; |
80
|
0
|
|
|
|
|
|
$message = ""; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
elsif ($max && $line =~ /^(not\s+)?ok\b/) { |
83
|
0
|
|
|
|
|
|
my $this = $next; |
84
|
0
|
0
|
|
|
|
|
if ($line =~ /^not ok\s*(\d*)/) { |
|
|
0
|
|
|
|
|
|
85
|
0
|
0
|
|
|
|
|
$this = $1 if $1 > 0; |
86
|
0
|
|
|
|
|
|
my $testcase = new Test::Unit::TestCase("$test case $this"); |
87
|
0
|
|
|
|
|
|
$result->start_test($testcase); |
88
|
0
|
|
|
|
|
|
$result->add_failure( |
89
|
|
|
|
|
|
|
Test::Unit::UnitHarness::TestCase->new("$test case $this"), |
90
|
|
|
|
|
|
|
Test::Unit::UnitHarness::Exception->new($message) |
91
|
|
|
|
|
|
|
); |
92
|
0
|
|
|
|
|
|
$result->end_test($testcase); |
93
|
0
|
|
|
|
|
|
$message = ""; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
elsif ($line =~ /^ok\s*(\d*)/) { |
96
|
0
|
0
|
|
|
|
|
$this = $1 if $1; |
97
|
0
|
|
|
|
|
|
my $testcase = |
98
|
|
|
|
|
|
|
Test::Unit::UnitHarness::TestCase->new("$test case $this"); |
99
|
0
|
|
|
|
|
|
$result->start_test($testcase); |
100
|
0
|
|
|
|
|
|
$result->add_pass($testcase); |
101
|
0
|
|
|
|
|
|
$result->end_test($testcase); |
102
|
0
|
|
|
|
|
|
$message = ""; |
103
|
|
|
|
|
|
|
} |
104
|
0
|
|
|
|
|
|
$next++; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
else { |
107
|
|
|
|
|
|
|
# this is the message, not the medium... |
108
|
|
|
|
|
|
|
# this wasnt part of the Test::Harness protocol, so it |
109
|
|
|
|
|
|
|
# must be output from the program. Collect this, it might |
110
|
|
|
|
|
|
|
# prove useful! |
111
|
0
|
|
|
|
|
|
$message .= $line; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
} |
114
|
0
|
|
|
|
|
|
$fh->close; # must close to reap child resource values |
115
|
0
|
0
|
|
|
|
|
if ($^O eq 'VMS') { |
116
|
0
|
0
|
|
|
|
|
if (defined $old5lib) { |
117
|
0
|
|
|
|
|
|
$ENV{PERL5LIB} = $old5lib; |
118
|
|
|
|
|
|
|
} else { |
119
|
0
|
|
|
|
|
|
delete $ENV{PERL5LIB}; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub name { |
125
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
126
|
0
|
|
|
|
|
|
return $self->{_Name}; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub names { |
130
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
131
|
0
|
|
|
|
|
|
return $self->{_Names}; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
sub add_test { |
135
|
0
|
|
|
0
|
0
|
|
croak "This is suite is not mutable."; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
sub add_test_method { |
139
|
0
|
|
|
0
|
0
|
|
croak "This suite is not mutable."; |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
sub count_test_cases { |
143
|
0
|
|
|
0
|
0
|
|
return 0; |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
sub to_string { |
147
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
148
|
0
|
|
|
|
|
|
return $self->{_Name}; |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub warning { |
152
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
153
|
0
|
|
|
|
|
|
my ($message) = @_; |
154
|
|
|
|
|
|
|
return Class::Inner->new( |
155
|
|
|
|
|
|
|
parent => 'Test::Unit::TestCase', |
156
|
0
|
|
|
0
|
|
|
methods => { run_test => sub { (shift)->fail($message) } }, |
157
|
0
|
|
|
|
|
|
args => ['warning'], |
158
|
|
|
|
|
|
|
); |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
package Test::Unit::UnitHarness::TestCase; |
162
|
2
|
|
|
2
|
|
11
|
use base qw(Test::Unit::TestCase); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
263
|
|
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
sub run_test { |
165
|
0
|
|
|
0
|
|
|
my $self = shift; |
166
|
0
|
|
|
|
|
|
my $class = ref($self); |
167
|
0
|
|
|
|
|
|
my $method = $self->name(); |
168
|
0
|
|
|
|
|
|
$self->fail("This test is not restartable"); |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
package Test::Unit::UnitHarness::Exception; |
172
|
2
|
|
|
2
|
|
11
|
use base qw(Test::Unit::Exception); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
130
|
|
173
|
2
|
|
|
2
|
|
9
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
279
|
|
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
sub new { |
176
|
0
|
|
|
0
|
|
|
my $class = shift; |
177
|
0
|
|
|
|
|
|
my ($message) = @_; |
178
|
0
|
|
|
|
|
|
my $stacktrace = ''; |
179
|
|
|
|
|
|
|
|
180
|
0
|
0
|
|
|
|
|
$message = '' unless defined($message); |
181
|
0
|
|
|
|
|
|
$stacktrace = $class . ": Output from external test\n" |
182
|
|
|
|
|
|
|
. $message . "\n"; |
183
|
|
|
|
|
|
|
|
184
|
0
|
|
|
|
|
|
bless { stacktrace => $stacktrace }, $class; |
185
|
|
|
|
|
|
|
} |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
sub stacktrace { |
188
|
0
|
|
|
0
|
|
|
my $self = shift; |
189
|
0
|
|
|
|
|
|
return $self->{stacktrace}; |
190
|
|
|
|
|
|
|
} |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
1; |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
__END__ |