#![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::fs;
use std::path::PathBuf;
use std::process::Command;
#[test]
fn test_string_literal_enum_auto_convert() {
let _tmp = tempfile::tempdir().unwrap();
let temp_dir = _tmp.path();
let test_id = format!(
"wj_test_enum_{}_{}",
std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap()
.as_nanos(),
std::process::id()
);
let output_dir = temp_dir.join(&test_id);
fs::create_dir_all(&output_dir).unwrap();
let manifest_dir = env!("CARGO_MANIFEST_DIR");
let test_file = PathBuf::from(manifest_dir).join("tests/string_literal_enum_test.wj");
let wj_binary = env!("CARGO_BIN_EXE_wj");
let output = Command::new(wj_binary)
.args([
"build",
test_file.to_str().unwrap(),
"--output",
output_dir.to_str().unwrap(),
"--target",
"rust",
"--no-cargo",
])
.output()
.expect("Failed to run wj build");
if !output.status.success() {
let stderr = String::from_utf8_lossy(&output.stderr);
let stdout = String::from_utf8_lossy(&output.stdout);
panic!("wj build failed:\nSTDERR:\n{}\nSTDOUT:\n{}", stderr, stdout);
}
let generated_rs = output_dir.join("string_literal_enum_test.rs");
let generated_code = fs::read_to_string(&generated_rs)
.or_else(|_| {
fs::read_to_string(
output_dir
.join("wj")
.join("windjammer")
.join("tests")
.join("string_literal_enum_test.rs"),
)
})
.expect("Failed to read generated Rust file (tried both possible paths)");
println!("Generated code:\n{}", generated_code);
assert!(
generated_code.contains("\"Alice\".to_string()")
|| generated_code.contains("String::from(\"Alice\")"),
"Generated code should convert string literal to String"
);
}