#![cfg(any(
not(any(
feature = "parser_tests",
feature = "analyzer_tests",
feature = "codegen_tests",
feature = "interpreter_tests",
feature = "conformance_tests",
feature = "integration_tests",
)),
feature = "integration_tests",
))]
use std::fs;
use std::path::PathBuf;
use std::process::Command;
#[test]
#[cfg_attr(tarpaulin, ignore)]
fn test_inline_mod_with_extern_fn_generates_correct_code() {
let wj_compiler = PathBuf::from(env!("CARGO_BIN_EXE_wj"));
let wj_file = "tests/inline_mod_extern_fn_test.wj";
let output = Command::new(&wj_compiler)
.arg("build")
.arg(wj_file)
.arg("--output")
.arg("./build")
.arg("--no-cargo")
.output()
.expect("Failed to run wj compiler");
assert!(
output.status.success(),
"Compilation failed: {}",
String::from_utf8_lossy(&output.stderr)
);
let rs_filename = std::path::Path::new(wj_file)
.file_name()
.unwrap()
.to_str()
.unwrap()
.replace(".wj", ".rs");
let generated_rust =
fs::read_to_string(format!("./build/{}", rs_filename)).unwrap_or_else(|_| {
panic!(
"Failed to read generated Rust file: ./build/{}",
rs_filename
)
});
assert!(
generated_rust.contains("extern \"C\""),
"Expected extern \"C\" block in generated code:\n{}",
generated_rust
);
assert!(
generated_rust.contains("pub fn my_extern_function"),
"Expected extern function declaration in generated code:\n{}",
generated_rust
);
assert!(
!generated_rust.contains("// TODO: Inline module support"),
"Should not have TODO comment for inline module - should generate extern block instead:\n{}",
generated_rust
);
println!("✓ inline_mod_extern_fn test passed");
}