@@ -31,13 +31,14 @@ define table $report-functions :: <string-table>
31
31
32
32
define function parse-args
33
33
(args :: <sequence> ) => (parser :: <command-line-parser>)
34
- let parser = make (<command-line-parser>);
34
+ let parser = make (<command-line-parser>,
35
+ help: "Run tests." );
35
36
add-option(parser,
36
37
// TODO: When <choice-option> supports having an optional
37
38
// value then this can be made optional where no value
38
39
// means "failures".
39
40
make (<choice-option>,
40
- names: #( "debug" ) ,
41
+ names: "debug" ,
41
42
choices: #("no" , "crashes" , "failures" ),
42
43
default: "no" ,
43
44
variable: "WHAT" ,
@@ -51,16 +52,18 @@ define function parse-args
51
52
help: "Show output as the test run progresses: none|DEFAULT|verbose" ));
52
53
add-option(parser,
53
54
make (<choice-option>,
54
- names: #( "report" ) ,
55
+ names: "report" ,
55
56
choices: key-sequence ($report-functions),
56
57
default: "failures" ,
57
58
variable: "TYPE" ,
58
59
help: format-to-string("Final report to generate: %s" ,
59
60
join(sort (key-sequence ($report-functions)), "|" ))));
60
61
add-option(parser,
61
62
make (<choice-option>,
62
- names: #("order" ),
63
- choices: map (method (key) as-lowercase (as (<string> , key)) end ,
63
+ names: "order" ,
64
+ choices: map (method (key)
65
+ as-lowercase (as (<string> , key))
66
+ end ,
64
67
list ($source-order, $lexical-order, $random-order)),
65
68
default: as-lowercase (as (<string> , $default-order)),
66
69
help: "Order in which to run tests. Note that when suites are being used"
@@ -71,36 +74,37 @@ define function parse-args
71
74
// and we could use it here as the default location of the report file.
72
75
add-option(parser,
73
76
make (<parameter-option>,
74
- names: #( "report-file" ) ,
77
+ names: "report-file" ,
75
78
variable: "FILE" ,
76
79
help: "File in which to store the report." ));
77
80
78
81
add-option(parser,
79
82
make (<repeated-parameter-option>,
80
- names: #( "load" ) ,
83
+ names: "load" ,
81
84
variable: "FILE" ,
82
- help: "Load the given shared library file before searching for test suites. May be repeated." ));
85
+ help: "Load the given shared library file before searching for"
86
+ " test suites. May be repeated." ));
83
87
84
88
// TODO(cgay): Replace these 4 options with --skip and --match (or
85
89
// --include?). Because Dylan is a Lisp-1 suites, tests, and
86
90
// benchmarks share a common namespace and --skip and --match will
87
91
// be unambiguous.
88
92
add-option(parser,
89
93
make (<repeated-parameter-option>,
90
- names: #( "suite" ) ,
94
+ names: "suite" ,
91
95
help: "Run (or list) only these named suites. May be repeated." ));
92
96
add-option(parser,
93
97
make (<repeated-parameter-option>,
94
- names: #( "test" ) ,
98
+ names: "test" ,
95
99
help: "Run (or list) only these named tests. May be repeated." ));
96
100
add-option(parser,
97
101
make (<repeated-parameter-option>,
98
- names: #( "skip-suite" ) ,
102
+ names: "skip-suite" ,
99
103
variable: "SUITE" ,
100
104
help: "Skip these named suites. May be repeated." ));
101
105
add-option(parser,
102
106
make (<repeated-parameter-option>,
103
- names: #( "skip-test" ) ,
107
+ names: "skip-test" ,
104
108
variable: "TEST" ,
105
109
help: "Skip these named tests. May be repeated." ));
106
110
add-option(parser,
@@ -118,7 +122,12 @@ define function parse-args
118
122
" with '-', the test will only run if it does NOT have the tag."
119
123
" May be repeated. Ex: --tag=-slow,-benchmark means don't run"
120
124
" benchmarks or tests tagged as slow." ));
121
- parse-command-line(parser, args, description: "Run test suites." );
125
+ add-option(parser,
126
+ make (<keyed-option>,
127
+ names: #("options" , "O" ),
128
+ default: make (<string-table>),
129
+ help: "Key/value pairs that may be used to pass context to tests." ));
130
+ parse-command-line(parser, args);
122
131
parser
123
132
end function parse-args;
124
133
@@ -163,18 +172,8 @@ define function make-runner-from-command-line
163
172
report: report,
164
173
progress: if (progress = $none) #f else progress end ,
165
174
tags: parse-tags(get-option-value(parser, "tag" )),
166
- order: as (<symbol> , get-option-value(parser, "order" )));
167
-
168
- // Options seem useful, but why are they positional rather than --option?
169
- // i.e., what makes them so special?
170
- for (option in parser.positional-options)
171
- let (key, val) = apply (values , split(option, '=' , count: 2 ));
172
- if (~val)
173
- usage-error("%= is not a valid test run option; must be in key=value form." ,
174
- option);
175
- end ;
176
- runner.runner-options[key] := val;
177
- end for ;
175
+ order: as (<symbol> , get-option-value(parser, "order" )),
176
+ options: get-option-value(parser, "options" ));
178
177
179
178
// TODO(cgay): So...the --suite and --test options may specify
180
179
// something disjoint from `top`. This begs the question why do we
@@ -222,19 +221,15 @@ define function run-test-application
222
221
test-runner := runner;
223
222
let status = run-or-list-tests(suite, runner, reporter, parser);
224
223
exit-application(status);
225
- exception (error :: <help-requested>)
226
- format(*standard-output*, "%s" , error );
227
- exit-application(0 );
228
- exception (error :: <usage-error>)
229
- // The command-line-parser library prints this error itself (which is
230
- // probably a bug) so don't print it here.
231
- exit-application(2 );
224
+ exception (err :: <abort-command-error>)
225
+ format(*standard-error*, "%s" , err);
226
+ exit-application(err.exit-status);
232
227
exception (error :: <error> ,
233
228
test: method (cond)
234
229
test-runner & ~test-runner.debug-runner?
235
230
end )
236
231
format(*standard-error*, "Error: %s" , error );
237
- exit-application(2 );
232
+ exit-application(1 );
238
233
end ;
239
234
end function ;
240
235
0 commit comments