Compare commits

...

1 Commits

View File

@ -2,13 +2,9 @@
//!
//! Use the `KCL_SAMPLES_ONLY=gear` environment variable to run only a subset of
//! the samples, in this case, all those that start with "gear".
use std::{
collections::HashMap,
path::{Path, PathBuf},
};
use std::path::{Path, PathBuf};
use fnv::FnvHashSet;
use tokio::task::JoinSet;
use super::Test;
@ -66,32 +62,10 @@ async fn kcl_test_execute() {
assert!(!tests.is_empty(), "No KCL samples found");
// Note: This is unordered.
let mut tasks = JoinSet::new();
// Mapping from task ID to test index.
let mut id_to_index = HashMap::new();
// Spawn a task for each test.
for (index, test) in tests.iter().cloned().enumerate() {
let handle = tasks.spawn(async move {
super::execute_test(&test, true).await;
});
id_to_index.insert(handle.id(), index);
for test in &tests {
super::execute_test(test, true).await;
}
// Join all the tasks and collect the failures. We cannot just join_all
// because insta's error messages don't clearly indicate which test failed.
let mut failed = vec![None; tests.len()];
while let Some(result) = tasks.join_next().await {
let Err(err) = result else {
continue;
};
// When there's an error, store the test name and error message.
let index = *id_to_index.get(&err.id()).unwrap();
failed[index] = Some(format!("{}: {err}", &tests[index].name));
}
let failed = failed.into_iter().flatten().collect::<Vec<_>>();
assert!(failed.is_empty(), "Failed tests: {}", failed.join("\n"));
// Ensure that inputs aren't missing.
let input_names = FnvHashSet::from_iter(tests.iter().map(|t| t.name.clone()));
let missing = expected_outputs