1 # Copyright (C) 2009, Jonathan "Duke" Leto <jonathan@leto.net>
5 say "Tapir version 0.01"
12 Tapir is a TAP test harness. There are different ways to run it, depending on
13 your preferences and build, but this should always work:
15 parrot t/harness.pir t/*.t
17 If you have created binary "fakecutable" (this requires a working compiler in
18 your PATH) then you can use Tapir like this:
22 Currently supported arguments:
23 -v Print the output of each test file
26 --version Print out the current Tapir version
29 --exec=program Use a given program to execute test scripts
30 i.e. ./tapir --exec=perl t/*.t to run Perl tests
40 .local pmc getopts, opts
41 load_bytecode "Getopt/Obj.pbc"
42 getopts = new ['Getopt';'Obj']
43 getopts."notOptStop"(1)
44 push getopts, "exec|e:s"
45 push getopts, "verbose|v"
46 push getopts, "version"
47 push getopts, "help|h"
48 opts = getopts."get_options"(argv)
52 .sub _find_max_file_length
61 if $I0 > numfiles goto loop_bottom
64 if $I1 <= maxlength goto loop_top
72 .param string filename
76 namelength = length filename
77 lengthdiff = maxlength - namelength
88 .local string exec, verbose
90 .local num start_time, end_time
93 $S0 = shift argv # get rid of harness.pir in the args list
96 if argc > 0 goto load_libs
100 load_bytecode 'lib/Tapir/Parser.pbc'
101 load_bytecode 'lib/Tapir/Stream.pbc'
104 # parse command line args
105 opts = _parse_opts(argv)
107 $S1 = opts["version"]
109 verbose = opts["verbose"]
111 unless $S2 goto check_version
115 unless $S1 goto make_parser
119 .local pmc tapir, klass
120 klass = newclass [ 'Tapir'; 'Parser' ]
121 tapir = klass.'new'()
123 .local pmc stream, qx_data
127 .local int success, exit_code
128 .local int total_files, failing_files, failing_tests, tests
129 .local int namelength
131 namelength = _find_max_file_length(argv)
139 unless file goto done
142 _print_elipses(file, namelength)
144 # we assume the test is PIR unless given an --exec flag
145 # how to do proper shebang-line detection?
146 .local string exec_cmd
148 unless exec goto run_cmd
151 qx_data = qx(exec_cmd,file)
153 exit_code = qx_data[1]
154 unless verbose goto parse
157 stream = tapir.'parse_tapstream'(output, exit_code)
158 success = stream.'is_pass'()
159 unless success goto fail
162 $I0 = stream.'total'() # includes todo tests
167 unless exit_code goto redo
168 # all tests passed but file had non-zero exit code
174 $I0 = stream.'get_fail'()
178 $S1 = stream.'total'()
182 $I1 = stream.'get_exit_code'()
183 unless $I1 goto newline
184 print ", exit code = "
194 if failing_files goto print_fail
211 $N1 = end_time - start_time
213 $P0 = new 'FixedPMCArray'
216 $S1 = sprintf "%.4f", $P0
219 $I0 = failing_files != 0
224 .param pmc command_and_args :slurpy
227 cmd = join ' ', command_and_args
230 pipe = new ['FileHandle']
231 pipe.'open'(cmd, 'rp')
232 unless pipe goto pipe_open_error
235 pipe.'encoding'('utf8')
236 output = pipe.'readall'()
239 .local pmc exit_status
240 $I0 = pipe.'exit_status'()
241 exit_status = box $I0
243 find_dynamic_lex $P0, '$!'
244 if null $P0 goto skip_exit_status
245 store_dynamic_lex '$!', exit_status
249 $P0 = new 'FixedPMCArray'
256 $S0 = 'Unable to execute "'
266 # vim: expandtab shiftwidth=4 ft=pir: