/
harness
260 lines (183 loc) · 5.77 KB
/
harness
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
#!perl
# Copyright (C) 2001-2006, The Perl Foundation.
# $Id$
=head1 NAME
t/harness - Parrot Test Harness
=head1 SYNOPSIS
% perl t/harness [options] [testfiles]
=head1 DESCRIPTION
The short command line options are:
=over 4
=item C<-w>
Turn warnings on.
=item C<-g>
Run the C<CGoto> core.
=item C<-j>
Run with JIT enabled.
=item C<-C>
Run the C<CGP> core.
=item C<-S>
Run Switched.
=item C<-b>
Run bounds checking enabled.
=item C<-d>
Run with debugging enabled.
=item C<-f>
Run fast core.
=item C<-r>
compile to Parrot bytecode and then run the bytecode.
=item C<-O[012]>
Run optimized to the specified level.
=item C<-D[number]>
Pass the specified debug bits to the parrot interpreter. Note that
C<-D40> (fill I, N registers with garbage) is always enabled.
See 'parrot --help-debug' for available flags.
=back
There are also long command line options:
=over 4
=item C<--running-make-test>
Some test scripts run more quickly when this is set.
=item C<--gc-debug>
Invoke parrot with '--gc-debug'.
=item C<--html>
Emit a C<smoke.html> file instead of displaying results.
=back
=cut
use strict;
use warnings;
use lib qw( . lib ../lib ../../lib );
use Getopt::Std;
use Test::Harness();
use English qw( -no_match_vars );
use Parrot::Config qw/%PConfig/;
# handle the long options
$ENV{RUNNING_MAKE_TEST} = grep { $_ eq '--running-make-test' } @ARGV;
@ARGV = grep { $_ ne '--running-make-test' } @ARGV;
my $gc_debug = grep { $_ eq '--gc-debug' } @ARGV;
@ARGV = grep { $_ ne '--gc-debug' } @ARGV;
my $html = grep { $_ eq '--html' } @ARGV;
@ARGV = grep { $_ ne '--html' } @ARGV;
my $run_exec = grep { $_ eq '--run-exec' } @ARGV;
@ARGV = grep { $_ ne '--run-exec' } @ARGV;
# Suck the short options into the TEST_PROG_ARGS evar:
my %opts;
getopts('wgjPCSefbvdr?hO:D:', \%opts);
if ($opts{'?'} || $opts{h}) {
print <<"EOF";
perl t/harness [options] [testfiles]
-w ... warnings on
-g ... run CGoto
-j ... run JIT
-C ... run CGP
-S ... run Switched
-b ... run bounds checked
--run-exec ... run exec core
-f ... run fast core
-v ... run verbose
-d ... run debug
-r ... assemble to PBC run PBC
-O[012] ... optimize
-D[number] ... pass debug flags to parrot interpreter
--running-make-test
--gc-debug
--html
EOF
exit;
}
# add -D40; merge it with any existing -D argument
$opts{D} = sprintf( '%x', hex(40) | (exists $opts{D} ? hex($opts{D}) : 0));
my $args = join(' ', map { "-$_" } keys %opts );
$args =~ s/-O/-O$opts{O}/ if exists $opts{O};
$args =~ s/-D/-D$opts{D}/;
$args .= ' --gc-debug' if $gc_debug;
# XXX find better way for passing run_exec to Parrot::Test
$args .= ' --run-exec' if $run_exec;
$ENV{TEST_PROG_ARGS} = $args;
# Pass in a list of tests to run on the command line, else run all the tests.
my @default_tests = map {glob "t/$_/*.t"} qw(
configure compilers/imcc/* op pmc native_pbc dynpmc dynoplibs
compilers/past compilers/pge compilers/pge/p5regex compilers/pge/p6regex
compilers/tge compilers/json library examples run src tools perl doc stm
);
push @default_tests, 't/distro/manifest.t';
# collect the coding standard tests (that we want to run) together and
# append them to the list of default tests
my @coding_std_tests = map { "t/codingstd/$_" } qw(
c_code_coda.t
c_indent.t
cppcomments.t
cuddled_else.t
line_endings.t
tabs.t
trailing_space.t
);
push @default_tests, @coding_std_tests;
my @tests = @ARGV ? map { glob( $_ ) } @ARGV : @default_tests;
unless ($html) {
Test::Harness::runtests(@tests);
} else {
my @smoke_config_vars = qw(
osname archname cc build_dir cpuarch revision VERSION optimize DEVEL
);
eval {
require Test::TAP::HTMLMatrix;
require Test::TAP::Model::Visual;
};
die "You must have Test::TAP::HTMLMatrix installed.\n\n$EVAL_ERROR"
if $EVAL_ERROR;
## FIXME: ###
# This is a temporary solution until Test::TAP::Model version
# 0.05. At that point, this function should be removed, and the
# verbose line below should be uncommented.
{
no warnings qw/redefine once/;
*Test::TAP::Model::run_tests = sub {
my $self = shift;
$self->_init;
$self->{meat}{start_time} = time;
my %stats;
foreach my $file (@_) {
my $data;
print STDERR "- $file\n";
$data = $self->run_test($file);
$stats{tests} += $data->{results}{max};
$stats{ok} += $data->{results}{ok} || 0;
}
printf STDERR "%s OK from %s tests (%.2f%% ok)\n\n",
$stats{ok},
$stats{tests},
$stats{ok} / $stats{tests} * 100;
$self->{meat}{end_time} = time;
};
my $start = time();
my $model = Test::TAP::Model::Visual->new();
# $model->set_verbose();
$model->run_tests(@tests);
my $end = time();
my $duration = $end - $start;
my $v = Test::TAP::HTMLMatrix->new(
$model,
join("\n",
"duration: $duration",
"branch: unknown",
"harness_args: " . (($args) ? $args : "N/A"),
map { "$_: $PConfig{$_}" } sort @smoke_config_vars),
);
$v->has_inline_css(1); # no separate css file
open HTML, ">", "smoke.html";
print HTML $v->html;
close HTML;
print "smoke.html has been generated.\n";
}
}
=head1 HISTORY
Mike Lambert stole F<t/harness> for F<languages/perl6/t/harness>.
Leo Toetsch stole F<languages/perl6/t/harness> for F<imcc/t/harness>.
Bernhard Schmalhofer merged F<imcc/t/harness> back into F<t/harness>.
=cut
# Local Variables:
# mode: cperl
# cperl-indent-level: 4
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4: