#![cfg(any(
not(any(
feature = "parser_tests",
feature = "analyzer_tests",
feature = "codegen_tests",
feature = "interpreter_tests",
feature = "conformance_tests",
feature = "integration_tests",
)),
feature = "analyzer_tests",
))]
use std::process::Command;
use tempfile::TempDir;
#[test]
#[cfg_attr(tarpaulin, ignore)]
fn test_explicit_string_parameter_stays_owned() {
let temp_dir = TempDir::new().expect("Failed to create temp dir");
let output_dir = temp_dir.path();
let wj_code = r#"
extern fn consume_string(s: String) -> i64 {}
pub struct Loader {}
impl Loader {
// CRITICAL: path is explicitly declared as string (owned)
pub fn load(path: string) -> i64 {
consume_string(path) // Should pass string directly
}
}
"#;
let wj_file = output_dir.join("test.wj");
std::fs::write(&wj_file, wj_code).expect("Failed to write test file");
let compile_result = Command::new(env!("CARGO_BIN_EXE_wj"))
.arg("build")
.arg(&wj_file)
.arg("--output")
.arg(output_dir)
.arg("--no-cargo")
.output()
.expect("Failed to run compiler");
assert!(
compile_result.status.success(),
"Compilation failed:\nstdout: {}\nstderr: {}",
String::from_utf8_lossy(&compile_result.stdout),
String::from_utf8_lossy(&compile_result.stderr)
);
let generated_rust =
std::fs::read_to_string(output_dir.join("test.rs")).expect("Failed to read generated Rust");
let sig_ok = generated_rust.contains("pub fn load(path: String)")
|| generated_rust.contains("pub fn load(path: &str");
assert!(
sig_ok,
"Expected load(path: String) or load(path: &str) with proper conversion. Got:\n{}",
generated_rust
);
assert!(
generated_rust.contains("consume_string") || generated_rust.contains("string_to_ffi"),
"FFI should consume a string. Generated:\n{}",
generated_rust
);
}