@@ -20,15 +20,24 @@ use snapbox::IntoData;
20
20
#[ derive( Debug ) ]
21
21
pub ( crate ) struct Runner {
22
22
cases : Vec < Case > ,
23
+ fail_on_unresolved_bin : bool ,
23
24
}
24
25
25
26
impl Runner {
26
27
pub ( crate ) fn new ( ) -> Self {
27
28
Self {
28
29
cases : Default :: default ( ) ,
30
+ fail_on_unresolved_bin : false ,
29
31
}
30
32
}
31
33
34
+ /// Set the rule value for `fail_on_unresolved_bin`
35
+ pub ( crate ) fn fail_on_unresolved_bin ( mut self , fail : bool ) -> Self {
36
+ self . fail_on_unresolved_bin = fail;
37
+
38
+ self
39
+ }
40
+
32
41
pub ( crate ) fn case ( & mut self , case : Case ) {
33
42
self . cases . push ( case) ;
34
43
}
@@ -49,7 +58,7 @@ impl Runner {
49
58
. cases
50
59
. par_iter ( )
51
60
. flat_map ( |c| {
52
- let results = c. run ( mode, bins, substitutions) ;
61
+ let results = c. run ( mode, bins, substitutions, self . fail_on_unresolved_bin ) ;
53
62
54
63
let stderr = stderr ( ) ;
55
64
let mut stderr = stderr. lock ( ) ;
@@ -159,6 +168,7 @@ impl Case {
159
168
mode : & Mode ,
160
169
bins : & crate :: BinRegistry ,
161
170
substitutions : & snapbox:: Redactions ,
171
+ fail_on_unresolved_bin : bool ,
162
172
) -> Vec < Result < Output , Output > > {
163
173
if self . expected == Some ( crate :: schema:: CommandStatus :: Skipped ) {
164
174
let output = Output :: sequence ( self . path . clone ( ) ) ;
@@ -235,7 +245,13 @@ impl Case {
235
245
step. expected_status = Some ( crate :: schema:: CommandStatus :: Skipped ) ;
236
246
}
237
247
238
- let step_status = self . run_step ( step, cwd. as_deref ( ) , bins, & substitutions) ;
248
+ let step_status = self . run_step (
249
+ step,
250
+ cwd. as_deref ( ) ,
251
+ bins,
252
+ & substitutions,
253
+ fail_on_unresolved_bin,
254
+ ) ;
239
255
if fs_context. is_mutable ( ) && step_status. is_err ( ) && * mode == Mode :: Fail {
240
256
prior_step_failed = true ;
241
257
}
@@ -324,6 +340,7 @@ impl Case {
324
340
cwd : Option < & std:: path:: Path > ,
325
341
bins : & crate :: BinRegistry ,
326
342
substitutions : & snapbox:: Redactions ,
343
+ fail_on_unresolved_bin : bool ,
327
344
) -> Result < Output , Output > {
328
345
let output = if let Some ( id) = step. id . clone ( ) {
329
346
Output :: step ( self . path . clone ( ) , id)
@@ -355,10 +372,14 @@ impl Case {
355
372
356
373
match & step. bin {
357
374
Some ( crate :: schema:: Bin :: Path ( _) ) => { }
358
- Some ( crate :: schema:: Bin :: Name ( _name ) ) => {
375
+ Some ( crate :: schema:: Bin :: Name ( name ) ) => {
359
376
// Unhandled by resolve
360
- snapbox:: debug!( "bin={:?} not found" , _name ) ;
377
+ snapbox:: debug!( "bin={:?} not found" , name ) ;
361
378
assert_eq ! ( output. spawn. status, SpawnStatus :: Skipped ) ;
379
+
380
+ if fail_on_unresolved_bin {
381
+ return Err ( output. error ( format ! ( "bin={name:?} not found" ) . into ( ) ) ) ;
382
+ }
362
383
return Ok ( output) ;
363
384
}
364
385
Some ( crate :: schema:: Bin :: Error ( _) ) => { }
@@ -367,6 +388,9 @@ impl Case {
367
388
Some ( crate :: schema:: Bin :: Ignore ) => {
368
389
// Unhandled by resolve
369
390
assert_eq ! ( output. spawn. status, SpawnStatus :: Skipped ) ;
391
+ if fail_on_unresolved_bin {
392
+ return Err ( output. error ( "bin not found" . into ( ) ) ) ;
393
+ }
370
394
return Ok ( output) ;
371
395
}
372
396
}
0 commit comments