Skip to content

Commit 4312195

Browse files
authored
Merge pull request #35 from fermyon/skippable-tests
Add ability to ignore tests
2 parents 7e5fd4f + 3e8ed61 commit 4312195

File tree

1 file changed

+37
-8
lines changed
  • crates/conformance-tests/src

1 file changed

+37
-8
lines changed

crates/conformance-tests/src/lib.rs

+37-8
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,57 @@ pub mod config;
33
use anyhow::Context as _;
44
use std::path::{Path, PathBuf};
55

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+
636
/// Run the conformance tests
7-
///
8-
/// The version is either 'canary' or a release tag like 'v0.1.0'.
937
pub fn run_tests(
10-
version: &str,
38+
config: Config,
1139
run: impl Fn(Test) -> anyhow::Result<()> + Send + Clone + 'static,
1240
) -> 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)
1543
}
1644

1745
/// Run the conformance tests located in the given directory
1846
pub fn run_tests_from(
1947
tests_dir: impl AsRef<Path>,
48+
config: Config,
2049
run: impl Fn(Test) -> anyhow::Result<()> + Send + Clone + 'static,
2150
) -> anyhow::Result<()> {
2251
let trials = tests_iter(tests_dir)?
2352
.map(|test| {
2453
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))
2857
})
2958
.collect();
3059
libtest_mimic::run(&Default::default(), trials).exit();

0 commit comments

Comments
 (0)