@@ -30,11 +30,7 @@ pub(crate) fn parse_args() -> Result<Command, ErrorString> {
30
30
cmd => cmd,
31
31
} ) ,
32
32
Some ( "runner" ) => parse_runner_args ( args) ,
33
- Some ( "tester" ) => parse_runner_args ( args) . map ( |cmd| match cmd {
34
- Command :: Runner ( args) => Command :: Tester ( TesterArgs :: from ( args) ) ,
35
- Command :: RunnerHelp => Command :: TesterHelp ,
36
- other => other,
37
- } ) ,
33
+ Some ( "tester" ) => parse_tester_args ( args) ,
38
34
Some ( "--help" ) | Some ( "-h" ) => Ok ( Command :: Help ) ,
39
35
Some ( "--version" ) => Ok ( Command :: Version ) ,
40
36
_ => Ok ( Command :: NoSubcommand ) ,
@@ -252,7 +248,7 @@ where
252
248
Ok ( Command :: Runner ( RunnerArgs {
253
249
executable,
254
250
run_command,
255
- run_args : run_args ,
251
+ run_args,
256
252
} ) )
257
253
}
258
254
@@ -263,17 +259,59 @@ pub struct RunnerArgs {
263
259
pub run_args : Option < Vec < String > > ,
264
260
}
265
261
262
+ fn parse_tester_args < A > ( args : A ) -> Result < Command , ErrorString >
263
+ where
264
+ A : Iterator < Item = String > ,
265
+ {
266
+ let mut arg_iter = args. into_iter ( ) . fuse ( ) ;
267
+ let test_path = PathBuf :: from (
268
+ arg_iter
269
+ . next ( )
270
+ . ok_or ( "excepted path to test source file as first argument" ) ?,
271
+ )
272
+ . canonicalize ( )
273
+ . map_err ( |err| format ! ( "Failed to canonicalize test path: {}" , err) ) ?;
274
+ let mut run_command = None ;
275
+ let mut target = None ;
276
+
277
+ loop {
278
+ match arg_iter. next ( ) . as_ref ( ) . map ( |s| s. as_str ( ) ) {
279
+ Some ( "--command" ) => {
280
+ let old = mem:: replace ( & mut run_command, Some ( arg_iter. collect ( ) ) ) ;
281
+ if !old. is_none ( ) {
282
+ Err ( "multiple `--command` arguments" ) ?;
283
+ }
284
+ break ;
285
+ }
286
+ Some ( "--target" ) => {
287
+ let old = mem:: replace ( & mut target, arg_iter. next ( ) ) ;
288
+ if !old. is_none ( ) {
289
+ Err ( "multiple `--target` arguments" ) ?;
290
+ }
291
+ break ;
292
+ }
293
+ Some ( "--help" ) | Some ( "-h" ) => {
294
+ return Ok ( Command :: TesterHelp ) ;
295
+ }
296
+ Some ( "--version" ) => {
297
+ return Ok ( Command :: Version ) ;
298
+ }
299
+ None => break ,
300
+ Some ( arg) => Err ( format ! ( "unexpected argument `{}`" , arg) ) ?,
301
+ }
302
+ }
303
+
304
+ Ok ( Command :: Tester ( TesterArgs {
305
+ test_path,
306
+ run_command,
307
+ target,
308
+ } ) )
309
+ }
310
+
266
311
#[ derive( Debug , Clone ) ]
267
312
pub struct TesterArgs {
268
313
pub test_path : PathBuf ,
269
314
pub run_command : Option < Vec < String > > ,
315
+ pub target : Option < String > ,
270
316
}
271
317
272
- impl From < RunnerArgs > for TesterArgs {
273
- fn from ( args : RunnerArgs ) -> Self {
274
- Self {
275
- test_path : args. executable ,
276
- run_command : args. run_command ,
277
- }
278
- }
279
- }
0 commit comments