Runs a single codegen test. This will generate bindings for `test` in the `language` specified. The test name is mangled by `args_kind` and the `args` are arguments to pass to the bindings generator.
(
&self,
language: &Language,
test: &Path,
args_kind: &str,
args: &[String],
config: &config::WitConfig,
)
| 621 | /// test name is mangled by `args_kind` and the `args` are arguments to pass |
| 622 | /// to the bindings generator. |
| 623 | fn codegen_test( |
| 624 | &self, |
| 625 | language: &Language, |
| 626 | test: &Path, |
| 627 | args_kind: &str, |
| 628 | args: &[String], |
| 629 | config: &config::WitConfig, |
| 630 | ) -> Result<()> { |
| 631 | let mut resolve = wit_parser::Resolve::default(); |
| 632 | let (pkg, _) = resolve.push_path(test).context("failed to load WIT")?; |
| 633 | let world = resolve |
| 634 | .select_world(&[pkg], None) |
| 635 | .or_else(|err| { |
| 636 | resolve |
| 637 | .select_world(&[pkg], Some("imports")) |
| 638 | .map_err(|_| err) |
| 639 | }) |
| 640 | .context("failed to select a world for bindings generation")?; |
| 641 | let world = resolve.worlds[world].name.clone(); |
| 642 | |
| 643 | let artifacts_dir = std::env::current_dir()? |
| 644 | .join(&self.opts.artifacts) |
| 645 | .join("codegen") |
| 646 | .join(language.to_string()) |
| 647 | .join(args_kind); |
| 648 | let _ = fs::remove_dir_all(&artifacts_dir); |
| 649 | let bindings_dir = artifacts_dir.join("bindings"); |
| 650 | let bindgen = Bindgen { |
| 651 | args: args.to_vec(), |
| 652 | wit_path: test.to_path_buf(), |
| 653 | world: world.clone(), |
| 654 | wit_config: config.clone(), |
| 655 | }; |
| 656 | language |
| 657 | .obj() |
| 658 | .generate_bindings(self, &bindgen, &bindings_dir) |
| 659 | .context("failed to generate bindings")?; |
| 660 | |
| 661 | language |
| 662 | .obj() |
| 663 | .verify( |
| 664 | self, |
| 665 | &Verify { |
| 666 | world: &world, |
| 667 | artifacts_dir: &artifacts_dir, |
| 668 | bindings_dir: &bindings_dir, |
| 669 | wit_test: test, |
| 670 | args: &bindgen.args, |
| 671 | }, |
| 672 | ) |
| 673 | .context("failed to verify generated bindings")?; |
| 674 | |
| 675 | Ok(()) |
| 676 | } |
| 677 | |
| 678 | /// Execute all `TestKind::Runtime` tests |
| 679 | fn run_runtime_tests(self: &Arc<Self>, tests: &HashMap<String, Test>) -> Result<()> { |
no test coverage detected