@@ -25,7 +25,6 @@ use regex::Regex;
25
25
use semver:: Version ;
26
26
use serde:: Deserialize ;
27
27
use std:: {
28
- borrow:: Borrow ,
29
28
collections:: { BTreeMap , HashSet } ,
30
29
fs,
31
30
fs:: { File , OpenOptions } ,
@@ -170,16 +169,11 @@ impl<'a> YamlTests<'a> {
170
169
171
170
/// Whether the test should be skipped
172
171
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
180
176
}
181
-
182
- false
183
177
}
184
178
185
179
fn fn_impls (
@@ -490,13 +484,13 @@ pub fn generate_tests_from_yaml(
490
484
}
491
485
}
492
486
493
- write_mod_files ( & generated_dir) ?;
487
+ write_mod_files ( & generated_dir, true ) ?;
494
488
495
489
Ok ( ( ) )
496
490
}
497
491
498
492
/// 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 > {
500
494
if !generated_dir. exists ( ) {
501
495
fs:: create_dir ( generated_dir) ?;
502
496
}
@@ -505,30 +499,34 @@ fn write_mod_files(generated_dir: &PathBuf) -> Result<(), failure::Error> {
505
499
let mut mods = vec ! [ ] ;
506
500
for path in paths {
507
501
if let Ok ( entry) = path {
508
- let file_type = entry. file_type ( ) . unwrap ( ) ;
509
502
let path = entry. path ( ) ;
510
503
let name = path. file_stem ( ) . unwrap ( ) . to_string_lossy ( ) ;
511
504
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" {
520
506
mods. push ( format ! (
521
507
"pub mod {};" ,
522
508
path. file_stem( ) . unwrap( ) . to_string_lossy( )
523
509
) ) ;
524
510
}
525
511
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 ) ?;
528
514
}
529
515
}
530
516
}
531
517
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
+
532
530
let mut path = generated_dir. clone ( ) ;
533
531
path. push ( "mod.rs" ) ;
534
532
let mut file = File :: create ( & path) ?;
@@ -562,6 +560,14 @@ fn write_test_file(
562
560
relative_path : & Path ,
563
561
generated_dir : & PathBuf ,
564
562
) -> 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
+
565
571
let mut path = test_file_path ( relative_path) ?;
566
572
path = generated_dir. join ( path) ;
567
573
path. set_extension ( "rs" ) ;
0 commit comments