@@ -20,15 +20,24 @@ use snapbox::IntoData;
2020#[ derive( Debug ) ]
2121pub ( crate ) struct Runner {
2222 cases : Vec < Case > ,
23+ fail_on_unresolved_bin : bool ,
2324}
2425
2526impl Runner {
2627 pub ( crate ) fn new ( ) -> Self {
2728 Self {
2829 cases : Default :: default ( ) ,
30+ fail_on_unresolved_bin : false ,
2931 }
3032 }
3133
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+
3241 pub ( crate ) fn case ( & mut self , case : Case ) {
3342 self . cases . push ( case) ;
3443 }
@@ -49,7 +58,7 @@ impl Runner {
4958 . cases
5059 . par_iter ( )
5160 . flat_map ( |c| {
52- let results = c. run ( mode, bins, substitutions) ;
61+ let results = c. run ( mode, bins, substitutions, self . fail_on_unresolved_bin ) ;
5362
5463 let stderr = stderr ( ) ;
5564 let mut stderr = stderr. lock ( ) ;
@@ -159,6 +168,7 @@ impl Case {
159168 mode : & Mode ,
160169 bins : & crate :: BinRegistry ,
161170 substitutions : & snapbox:: Redactions ,
171+ fail_on_unresolved_bin : bool ,
162172 ) -> Vec < Result < Output , Output > > {
163173 if self . expected == Some ( crate :: schema:: CommandStatus :: Skipped ) {
164174 let output = Output :: sequence ( self . path . clone ( ) ) ;
@@ -235,7 +245,13 @@ impl Case {
235245 step. expected_status = Some ( crate :: schema:: CommandStatus :: Skipped ) ;
236246 }
237247
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+ ) ;
239255 if fs_context. is_mutable ( ) && step_status. is_err ( ) && * mode == Mode :: Fail {
240256 prior_step_failed = true ;
241257 }
@@ -324,6 +340,7 @@ impl Case {
324340 cwd : Option < & std:: path:: Path > ,
325341 bins : & crate :: BinRegistry ,
326342 substitutions : & snapbox:: Redactions ,
343+ fail_on_unresolved_bin : bool ,
327344 ) -> Result < Output , Output > {
328345 let output = if let Some ( id) = step. id . clone ( ) {
329346 Output :: step ( self . path . clone ( ) , id)
@@ -355,10 +372,14 @@ impl Case {
355372
356373 match & step. bin {
357374 Some ( crate :: schema:: Bin :: Path ( _) ) => { }
358- Some ( crate :: schema:: Bin :: Name ( _name ) ) => {
375+ Some ( crate :: schema:: Bin :: Name ( name ) ) => {
359376 // Unhandled by resolve
360- snapbox:: debug!( "bin={:?} not found" , _name ) ;
377+ snapbox:: debug!( "bin={:?} not found" , name ) ;
361378 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+ }
362383 return Ok ( output) ;
363384 }
364385 Some ( crate :: schema:: Bin :: Error ( _) ) => { }
@@ -367,6 +388,9 @@ impl Case {
367388 Some ( crate :: schema:: Bin :: Ignore ) => {
368389 // Unhandled by resolve
369390 assert_eq ! ( output. spawn. status, SpawnStatus :: Skipped ) ;
391+ if fail_on_unresolved_bin {
392+ return Err ( output. error ( "bin not found" . into ( ) ) ) ;
393+ }
370394 return Ok ( output) ;
371395 }
372396 }
0 commit comments