@@ -3,28 +3,57 @@ pub mod config;
3
3
use anyhow:: Context as _;
4
4
use std:: path:: { Path , PathBuf } ;
5
5
6
+ /// Configuration for how tests are run.
7
+ pub struct Config {
8
+ version : String ,
9
+ ignored : Vec < String > ,
10
+ }
11
+
12
+ impl Config {
13
+ /// Create a new configuration
14
+ ///
15
+ /// The version is either 'canary' or a release tag like 'v0.1.0'.
16
+ pub fn new ( version : impl Into < String > ) -> Self {
17
+ Self {
18
+ version : version. into ( ) ,
19
+ ignored : Vec :: new ( ) ,
20
+ }
21
+ }
22
+
23
+ /// Ignore a test by name
24
+ pub fn ignore ( mut self , name : impl Into < String > ) -> Self {
25
+ self . ignored . push ( name. into ( ) ) ;
26
+ self
27
+ }
28
+
29
+ /// Ignore multiple tests by name
30
+ pub fn ignore_many ( mut self , names : impl IntoIterator < Item = impl Into < String > > ) -> Self {
31
+ self . ignored . extend ( names. into_iter ( ) . map ( Into :: into) ) ;
32
+ self
33
+ }
34
+ }
35
+
6
36
/// Run the conformance tests
7
- ///
8
- /// The version is either 'canary' or a release tag like 'v0.1.0'.
9
37
pub fn run_tests (
10
- version : & str ,
38
+ config : Config ,
11
39
run : impl Fn ( Test ) -> anyhow:: Result < ( ) > + Send + Clone + ' static ,
12
40
) -> anyhow:: Result < ( ) > {
13
- let tests_dir = download_tests ( version) ?;
14
- run_tests_from ( tests_dir, run)
41
+ let tests_dir = download_tests ( & config . version ) ?;
42
+ run_tests_from ( tests_dir, config , run)
15
43
}
16
44
17
45
/// Run the conformance tests located in the given directory
18
46
pub fn run_tests_from (
19
47
tests_dir : impl AsRef < Path > ,
48
+ config : Config ,
20
49
run : impl Fn ( Test ) -> anyhow:: Result < ( ) > + Send + Clone + ' static ,
21
50
) -> anyhow:: Result < ( ) > {
22
51
let trials = tests_iter ( tests_dir) ?
23
52
. map ( |test| {
24
53
let run = run. clone ( ) ;
25
- libtest_mimic :: Trial :: test ( test . name . clone ( ) , move || {
26
- Ok ( run ( test) . map_err ( FullError :: from) ?)
27
- } )
54
+ let name = test. name . clone ( ) ;
55
+ libtest_mimic :: Trial :: test ( & name , move || Ok ( run ( test) . map_err ( FullError :: from) ?) )
56
+ . with_ignored_flag ( config . ignored . contains ( & name ) )
28
57
} )
29
58
. collect ( ) ;
30
59
libtest_mimic:: run ( & Default :: default ( ) , trials) . exit ( ) ;
0 commit comments