-
Notifications
You must be signed in to change notification settings - Fork 114
Expand file tree
/
Copy pathlib.rs
More file actions
71 lines (60 loc) · 2.15 KB
/
Copy pathlib.rs
File metadata and controls
71 lines (60 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#![allow(clippy::exit)]
use crate::testcase::collect_test_dirs;
use anyhow::Result;
use libtest_mimic::{Arguments, Trial};
use runner::Runner;
use std::process::ExitCode;
use std::sync::Arc;
use std::{
env, fs,
process::{self},
};
use tracing_subscriber::FmtSubscriber;
mod differ;
mod runner;
mod testcase;
pub fn run() -> Result<ExitCode> {
let subscriber = FmtSubscriber::builder()
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
.finish();
tracing::subscriber::set_global_default(subscriber).expect("Failed to set global subscriber");
let mut args = Arguments::from_args();
// If filters are provided that look like paths (contain '/'), convert them to test names
if let Some(filter) = &mut args.filter {
*filter = filter.replace('/', "::");
}
let tests = collect_tests()?;
Ok(libtest_mimic::run(&args, tests).exit_code())
}
fn collect_tests() -> Result<Vec<Trial>> {
// Find the manifest directory at compile time and locate tests in ../tests.
let manifest_dir = env!("CARGO_MANIFEST_DIR");
let base = std::path::Path::new(manifest_dir)
.join("../tests")
.canonicalize()
.expect("Failed to canonicalize tests directory");
tracing::debug!("Using tests directory: {}", base.display());
let output_dir = std::path::Path::new(manifest_dir).join("../tests/target/difftest");
fs::create_dir_all(&output_dir)?;
let output_dir = output_dir
.canonicalize()
.expect("Failed to canonicalize tests directory");
tracing::debug!("Using output directory: {}", output_dir.display());
let runner = Arc::new(Runner {
base_dir: base.clone(),
output_dir,
});
let test_cases = collect_test_dirs(&base).expect("Failed to collect test case directories");
if test_cases.is_empty() {
eprintln!("No valid tests found in {}", base.display());
process::exit(1);
}
let trails = test_cases
.into_iter()
.map(|case| {
let runner = runner.clone();
Trial::test(case.to_string(), move || Ok(runner.run_test_case(&case)?))
})
.collect();
Ok(trails)
}