/
prove.pir
235 lines (204 loc) · 5.32 KB
/
prove.pir
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
# Copyright (C) 2010, Parrot Foundation.
=head1 NAME
Prove
=head1 DESCRIPTION
Prove is a PIR-based TAP (Test Anything Protocol) Harness
It eats test output (i.e. is a TAP consumer) and tells humans if the
test suite passed, and if not, which kind of pretty colors of smoke
came out. It is mostly equivalent to 'prove' from Perl 5.
=head1 SYNOPSIS
parrot-prove t/*.t
=head2 OPTIONS
Usage:
parrot-prove [OPTIONS] <files>
=head3 Boolean options
-v, --verbose Print all test lines.
-s, --shuffle Run the tests in random order.
-f, --failures Show failed tests.
-o, --comments Show comments.
--ignore-exit Ignore exit status from test scripts.
-m, --merge Merge test scripts' STDERR with their STDOUT.
--reverse Run the tests in reverse order.
-q, --quiet Suppress some test output while running tests.
-Q, --QUIET Only print summary results.
--directives Only show results with TODO or SKIP directives.
--normalize Normalize TAP output in verbose output
-h, --help Display this help
-V, --version Display the version
=head3 Options that take arguments
-e, --exec Interpreter to run the tests ('' for compiled
tests.)
-a, --archive Store the resulting TAP in an archive file.
=cut
.sub 'main' :main
.param pmc argv
$S0 = shift argv
.local int argc
argc = elements argv
if argc > 0 goto L1
help()
end
L1:
.local pmc opts
opts = _parse_opts(argv)
$S0 = opts['help']
unless $S0 goto L2
help()
end
L2:
$S0 = opts['version']
unless $S0 goto L3
version()
end
L3:
.tailcall do(opts, argv)
.end
.sub 'version' :anon
say "Prove 0.1.0"
.end
.sub 'help' :anon
say <<"HELP"
parrot-prove [options] [files]
Boolean options:
-v, --verbose Print all test lines.
-s, --shuffle Run the tests in random order.
-f, --failures Show failed tests.
-o, --comments Show comments.
--ignore-exit Ignore exit status from test scripts.
-m, --merge Merge test scripts' STDERR with their STDOUT.
--reverse Run the tests in reverse order.
-q, --quiet Suppress some test output while running tests.
-Q, --QUIET Only print summary results.
--directives Only show results with TODO or SKIP directives.
--normalize Normalize TAP output in verbose output
-h, --help Display this help
-V, --version Display the version
Options that take arguments:
-e, --exec Interpreter to run the tests ('' for compiled
tests.)
-a, --archive Store the resulting TAP in an archive file.
HELP
.end
.sub '_parse_opts' :anon
.param pmc argv
load_bytecode 'Getopt/Obj.pbc'
$P0 = new ['Getopt';'Obj']
$P0.'notOptStop'(1)
push $P0, 'exec|e:s'
push $P0, 'archive|a:s'
push $P0, 'verbose|v'
push $P0, 'quiet|q'
push $P0, 'QUIET|Q'
push $P0, 'normalize'
push $P0, 'failures|f'
push $P0, 'comments|o'
push $P0, 'directives'
push $P0, 'ignore-exit'
push $P0, 'reverse'
push $P0, 'merge|m'
push $P0, 'shuffle|s'
push $P0, 'version|V'
push $P0, 'help|h'
$P1 = $P0.'get_options'(argv)
.return ($P1)
.end
.sub 'do' :anon
.param pmc opts
.param pmc files
load_bytecode 'TAP/Harness.pbc'
.local pmc harness, aggregate
$I0 = exists opts['archive']
if $I0 goto L1
harness = new ['TAP';'Harness']
goto L2
L1:
harness = new ['TAP';'Harness';'Archive']
$S0 = opts['archive']
harness.'archive'($S0)
L2:
harness.'process_args'(opts)
$P0 = _get_tests(opts, files)
aggregate = harness.'runtests'($P0)
$I0 = aggregate.'has_errors'()
exit $I0
.end
.sub '_get_tests' :anon
.param pmc opts
.param pmc files
.local int nb
nb = elements files
# currently, FixedStringArray hasn't the method sort.
# see GH #384
$P0 = new 'FixedPMCArray'
set $P0, nb
$I0 = 0
$P1 = iter files
L1:
unless $P1 goto L2
$S0 = shift $P1
$P2 = split "\\", $S0
$S0 = join "/", $P2
$P2 = box $S0
$P0[$I0] = $P2
inc $I0
goto L1
L2:
$I0 = exists opts['shuffle']
unless $I0 goto L3
$P0 = _shuffle($P0)
goto L4
L3:
$P0.'sort'()
$I0 = exists opts['reverse']
unless $I0 goto L4
$P0 = _reverse($P0)
L4:
.return ($P0)
.end
.sub '_reverse' :anon
.param pmc array
.local int nb
nb = elements array
$P0 = new 'FixedPMCArray'
set $P0, nb
$I0 = 0
$I1 = nb - 1
L1:
unless $I0 < nb goto L2
$P1 = array[$I0]
$P0[$I1] = $P1
inc $I0
dec $I1
goto L1
L2:
.return ($P0)
.end
.sub '_shuffle' :anon
.param pmc array
load_bytecode 'Math/Rand.pbc'
.local pmc rand
rand = get_global [ 'Math'; 'Rand' ], 'rand'
.local pmc srand
srand = get_global [ 'Math'; 'Rand' ], 'srand'
$I0 = time
srand($I0)
.local int i, j
i = elements array
L1:
unless i > 0 goto L2
$I0 = rand()
j = $I0 % i
dec i
$P1 = array[i]
$P2 = array[j]
array[i] = $P2
array[j] = $P1
goto L1
L2:
.return (array)
.end
# Local Variables:
# mode: pir
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4 ft=pir: