@@ -25,7 +25,6 @@ use regex::Regex;
2525use semver:: Version ;
2626use serde:: Deserialize ;
2727use std:: {
28- borrow:: Borrow ,
2928 collections:: { BTreeMap , HashSet } ,
3029 fs,
3130 fs:: { File , OpenOptions } ,
@@ -170,16 +169,11 @@ impl<'a> YamlTests<'a> {
170169
171170 /// Whether the test should be skipped
172171 fn skip_test ( & self , name : & str ) -> bool {
173- if self . skip . tests . contains_key ( self . path . as_str ( ) ) {
174- let tests = self . skip . tests . get ( self . path . as_str ( ) ) ;
175-
176- return match tests {
177- Some ( t) => t. contains ( name. to_string ( ) . borrow ( ) ) ,
178- None => true ,
179- } ;
172+ if let Some ( tests) = self . skip . tests . get ( & self . path ) {
173+ tests. iter ( ) . any ( |n| n == name || n == "*" )
174+ } else {
175+ false
180176 }
181-
182- false
183177 }
184178
185179 fn fn_impls (
@@ -490,13 +484,13 @@ pub fn generate_tests_from_yaml(
490484 }
491485 }
492486
493- write_mod_files ( & generated_dir) ?;
487+ write_mod_files ( & generated_dir, true ) ?;
494488
495489 Ok ( ( ) )
496490}
497491
498492/// Writes a mod.rs file in each generated directory
499- fn write_mod_files ( generated_dir : & PathBuf ) -> Result < ( ) , failure:: Error > {
493+ fn write_mod_files ( generated_dir : & PathBuf , toplevel : bool ) -> Result < ( ) , failure:: Error > {
500494 if !generated_dir. exists ( ) {
501495 fs:: create_dir ( generated_dir) ?;
502496 }
@@ -505,30 +499,34 @@ fn write_mod_files(generated_dir: &PathBuf) -> Result<(), failure::Error> {
505499 let mut mods = vec ! [ ] ;
506500 for path in paths {
507501 if let Ok ( entry) = path {
508- let file_type = entry. file_type ( ) . unwrap ( ) ;
509502 let path = entry. path ( ) ;
510503 let name = path. file_stem ( ) . unwrap ( ) . to_string_lossy ( ) ;
511504
512- let is_tests_common_dir =
513- name. as_ref ( ) == "common" && path. parent ( ) . unwrap ( ) . file_name ( ) . unwrap ( ) == "tests" ;
514-
515- if name. as_ref ( ) != "mod" {
516- if is_tests_common_dir {
517- mods. push ( "#[macro_use]" . to_string ( ) ) ;
518- }
519-
505+ if name != "mod" {
520506 mods. push ( format ! (
521507 "pub mod {};" ,
522508 path. file_stem( ) . unwrap( ) . to_string_lossy( )
523509 ) ) ;
524510 }
525511
526- if file_type . is_dir ( ) && !is_tests_common_dir {
527- write_mod_files ( & entry. path ( ) ) ?;
512+ if path . is_dir ( ) && !( toplevel && name == "common" ) {
513+ write_mod_files ( & entry. path ( ) , false ) ?;
528514 }
529515 }
530516 }
531517
518+ // Make sure we have a stable output
519+ mods. sort ( ) ;
520+
521+ if toplevel {
522+ // The "common" module must appear first so that its macros are parsed before the
523+ // compiler visits other modules, otherwise we'll have "macro not found" errors.
524+ mods. retain ( |name| name != "pub mod common;" ) ;
525+ mods. insert ( 0 , "#[macro_use]" . into ( ) ) ;
526+ mods. insert ( 1 , "pub mod common;" . into ( ) ) ;
527+ mods. insert ( 2 , "" . into ( ) ) ;
528+ }
529+
532530 let mut path = generated_dir. clone ( ) ;
533531 path. push ( "mod.rs" ) ;
534532 let mut file = File :: create ( & path) ?;
@@ -562,6 +560,14 @@ fn write_test_file(
562560 relative_path : & Path ,
563561 generated_dir : & PathBuf ,
564562) -> Result < ( ) , failure:: Error > {
563+ if test. skip_test ( "*" ) {
564+ info ! (
565+ r#"skipping all tests in {} because it's included in skip.yml"# ,
566+ test. path,
567+ ) ;
568+ return Ok ( ( ) ) ;
569+ }
570+
565571 let mut path = test_file_path ( relative_path) ?;
566572 path = generated_dir. join ( path) ;
567573 path. set_extension ( "rs" ) ;
0 commit comments