pub mod assertions;
pub mod fixtures;
#[allow(dead_code)]
pub fn is_ci() -> bool {
std::env::var("CI").is_ok() || std::env::var("GITHUB_ACTIONS").is_ok()
}
#[allow(dead_code)]
pub fn has_required_wasm_tools() -> bool {
which::which("wasm-bindgen").is_ok()
}
#[allow(dead_code)]
pub fn setup_test_project(name: &str) -> anyhow::Result<std::path::PathBuf> {
let temp_dir = tempfile::tempdir()?;
let project_path = temp_dir.path().to_path_buf();
std::fs::create_dir_all(project_path.join("src"))?;
std::fs::write(
project_path.join("Cargo.toml"),
format!(
r#"
[package]
name = "{}"
version = "0.1.0"
edition = "2021"
[lib]
crate-type = ["cdylib"]
"#,
name
),
)?;
std::fs::write(
project_path.join("src/lib.rs"),
r#"
#[no_mangle]
pub extern "C" fn add(a: i32, b: i32) -> i32 {
a + b
}
#[no_mangle]
pub extern "C" fn multiply(a: i32, b: i32) -> i32 {
a * b
}
"#,
)?;
std::mem::forget(temp_dir);
Ok(project_path)
}
#[macro_export]
macro_rules! require_wasm_tools {
() => {
if !$crate::common::has_required_wasm_tools() {
if $crate::common::is_ci() {
panic!("Required WASM tools missing in CI! Install wasm-bindgen-cli");
} else {
eprintln!("⚠️ Skipping test: wasm-bindgen-cli not found in PATH");
eprintln!(" Install with: cargo install wasm-bindgen-cli");
return Ok(());
}
}
};
}