Skip to content

Commit 943e9df

Browse files
authored
Merge pull request #146 from cgay/new-cli
Update for recent command-line-parser changes
2 parents 4f1d1c5 + 87d6aef commit 943e9df

File tree

1 file changed

+28
-33
lines changed

1 file changed

+28
-33
lines changed

command-line.dylan

Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,14 @@ define table $report-functions :: <string-table>
3131

3232
define function parse-args
3333
(args :: <sequence>) => (parser :: <command-line-parser>)
34-
let parser = make(<command-line-parser>);
34+
let parser = make(<command-line-parser>,
35+
help: "Run tests.");
3536
add-option(parser,
3637
// TODO: When <choice-option> supports having an optional
3738
// value then this can be made optional where no value
3839
// means "failures".
3940
make(<choice-option>,
40-
names: #("debug"),
41+
names: "debug",
4142
choices: #("no", "crashes", "failures"),
4243
default: "no",
4344
variable: "WHAT",
@@ -51,16 +52,18 @@ define function parse-args
5152
help: "Show output as the test run progresses: none|DEFAULT|verbose"));
5253
add-option(parser,
5354
make(<choice-option>,
54-
names: #("report"),
55+
names: "report",
5556
choices: key-sequence($report-functions),
5657
default: "failures",
5758
variable: "TYPE",
5859
help: format-to-string("Final report to generate: %s",
5960
join(sort(key-sequence($report-functions)), "|"))));
6061
add-option(parser,
6162
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,
6467
list($source-order, $lexical-order, $random-order)),
6568
default: as-lowercase(as(<string>, $default-order)),
6669
help: "Order in which to run tests. Note that when suites are being used"
@@ -71,36 +74,37 @@ define function parse-args
7174
// and we could use it here as the default location of the report file.
7275
add-option(parser,
7376
make(<parameter-option>,
74-
names: #("report-file"),
77+
names: "report-file",
7578
variable: "FILE",
7679
help: "File in which to store the report."));
7780

7881
add-option(parser,
7982
make(<repeated-parameter-option>,
80-
names: #("load"),
83+
names: "load",
8184
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."));
8387

8488
// TODO(cgay): Replace these 4 options with --skip and --match (or
8589
// --include?). Because Dylan is a Lisp-1 suites, tests, and
8690
// benchmarks share a common namespace and --skip and --match will
8791
// be unambiguous.
8892
add-option(parser,
8993
make(<repeated-parameter-option>,
90-
names: #("suite"),
94+
names: "suite",
9195
help: "Run (or list) only these named suites. May be repeated."));
9296
add-option(parser,
9397
make(<repeated-parameter-option>,
94-
names: #("test"),
98+
names: "test",
9599
help: "Run (or list) only these named tests. May be repeated."));
96100
add-option(parser,
97101
make(<repeated-parameter-option>,
98-
names: #("skip-suite"),
102+
names: "skip-suite",
99103
variable: "SUITE",
100104
help: "Skip these named suites. May be repeated."));
101105
add-option(parser,
102106
make(<repeated-parameter-option>,
103-
names: #("skip-test"),
107+
names: "skip-test",
104108
variable: "TEST",
105109
help: "Skip these named tests. May be repeated."));
106110
add-option(parser,
@@ -118,7 +122,12 @@ define function parse-args
118122
" with '-', the test will only run if it does NOT have the tag."
119123
" May be repeated. Ex: --tag=-slow,-benchmark means don't run"
120124
" 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);
122131
parser
123132
end function parse-args;
124133

@@ -163,18 +172,8 @@ define function make-runner-from-command-line
163172
report: report,
164173
progress: if (progress = $none) #f else progress end,
165174
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"));
178177

179178
// TODO(cgay): So...the --suite and --test options may specify
180179
// something disjoint from `top`. This begs the question why do we
@@ -222,19 +221,15 @@ define function run-test-application
222221
test-runner := runner;
223222
let status = run-or-list-tests(suite, runner, reporter, parser);
224223
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);
232227
exception (error :: <error>,
233228
test: method (cond)
234229
test-runner & ~test-runner.debug-runner?
235230
end)
236231
format(*standard-error*, "Error: %s", error);
237-
exit-application(2);
232+
exit-application(1);
238233
end;
239234
end function;
240235

0 commit comments

Comments
 (0)