Loads a test from `dir` using the `wit` file in the directory specified. Returns a list of components that were found within this directory.
(
&self,
wit: &Path,
dir: &Path,
)
| 354 | /// |
| 355 | /// Returns a list of components that were found within this directory. |
| 356 | fn load_runtime_test( |
| 357 | &self, |
| 358 | wit: &Path, |
| 359 | dir: &Path, |
| 360 | ) -> Result<(config::WitConfig, Vec<Component>)> { |
| 361 | let mut resolve = wit_parser::Resolve::default(); |
| 362 | |
| 363 | let wit_path = if dir.join("deps").exists() { dir } else { wit }; |
| 364 | let (pkg, _files) = resolve.push_path(wit_path).context(format!( |
| 365 | "failed to load `test.wit` in test directory: {:?}", |
| 366 | &wit |
| 367 | ))?; |
| 368 | let resolve = Arc::new(resolve); |
| 369 | |
| 370 | let wit_contents = std::fs::read_to_string(wit)?; |
| 371 | let wit_config: config::WitConfig = config::parse_test_config(&wit_contents, "//@") |
| 372 | .context("failed to parse WIT test config")?; |
| 373 | |
| 374 | let mut worlds = Vec::new(); |
| 375 | |
| 376 | let mut push_world = |kind: Kind, name: &str| -> Result<()> { |
| 377 | let world = resolve.select_world(&[pkg], Some(name)).with_context(|| { |
| 378 | format!("failed to find expected `{name}` world to generate bindings") |
| 379 | })?; |
| 380 | worlds.push((world, kind)); |
| 381 | Ok(()) |
| 382 | }; |
| 383 | push_world(Kind::Runner, wit_config.runner_world())?; |
| 384 | for world in wit_config.dependency_worlds() { |
| 385 | push_world(Kind::Test, &world)?; |
| 386 | } |
| 387 | |
| 388 | let mut components = Vec::new(); |
| 389 | let mut any_runner = false; |
| 390 | let mut any_test = false; |
| 391 | |
| 392 | for entry in dir.read_dir().context("failed to read test directory")? { |
| 393 | let entry = entry.context("failed to read test directory entry")?; |
| 394 | let path = entry.path(); |
| 395 | |
| 396 | let Some(name) = path.file_name().and_then(|s| s.to_str()) else { |
| 397 | continue; |
| 398 | }; |
| 399 | if name == "test.wit" { |
| 400 | continue; |
| 401 | } |
| 402 | |
| 403 | let Some((world, kind)) = worlds |
| 404 | .iter() |
| 405 | .find(|(world, _kind)| name.starts_with(&resolve.worlds[*world].name)) |
| 406 | else { |
| 407 | log::debug!("skipping file {name:?}"); |
| 408 | continue; |
| 409 | }; |
| 410 | match kind { |
| 411 | Kind::Runner => any_runner = true, |
| 412 | Kind::Test => any_test = true, |
| 413 | } |
no test coverage detected