//! Emits the Rust client crate, drops a consumer into its `tests/`, and runs //! `cargo test` inside it. The consumer names every generated module path and //! calls every generated function, so the emitted crate has to compile against //! the real `mizan-rust` kernel before its serde round-trips are asserted. mod harness; use std::path::PathBuf; use mizan_codegen::config::{Config, RustKernelSpec}; use mizan_codegen::emit::CodegenTarget; use mizan_codegen::emit::rust::RustCrate; fn crate_config() -> Config { let kernel = harness::manifest_dir().join("../../frontends/mizan-rust"); assert!( kernel.join("Cargo.toml").is_file(), "the generated crate depends on the kernel at {}", kernel.display(), ); Config { rust_kernel: Some(RustKernelSpec::Path { path: kernel.display().to_string() }), rust_crate_name: "fixture_client".to_string(), ..harness::config_for("rust") } } /// Build artifacts live outside the scratch root so a rerun reuses the /// compiled kernel and its dependency tree instead of rebuilding them. fn shared_target_dir() -> PathBuf { harness::manifest_dir().join("target/toolchain-cargo") } #[test] fn generated_crate_compiles_and_its_tests_pass() { let root = harness::scratch_root("rust"); let ir = harness::load_ir("afi_ir.kdl"); harness::write_emitted(&root, &RustCrate.emit(&ir, &crate_config())); harness::copy_fixture("rust_driver.rs", &root.join("tests/driver.rs")); let cargo = harness::resolve_on_path("cargo"); let target_dir = shared_target_dir(); harness::run_tool( &cargo, &["test"], &root, &[("CARGO_TARGET_DIR", target_dir.as_path())], "the emitted Rust client crate does not build or its consumer tests fail", ); }