#![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;
#[path = "common/test_utils.rs"]
mod test_utils;
#[test]
#[cfg_attr(tarpaulin, ignore)]
fn test_single_file_creates_bin_target() {
let temp_dir = tempfile::tempdir().expect("Failed to create temp dir");
let output_dir = temp_dir.path();
let wj_code = r#"
fn main() {
println!("Hello, world!")
}
"#;
let input_file = temp_dir.path().join("hello.wj");
std::fs::write(&input_file, wj_code).expect("Failed to write input file");
println!("🔨 Compiling hello.wj...");
let output = Command::new(test_utils::wj_binary())
.arg("build")
.arg(&input_file)
.arg("--output")
.arg(output_dir)
.arg("--no-cargo")
.output()
.expect("Failed to execute wj compiler");
if !output.status.success() {
eprintln!("❌ Compilation failed!");
eprintln!("stdout: {}", String::from_utf8_lossy(&output.stdout));
eprintln!("stderr: {}", String::from_utf8_lossy(&output.stderr));
panic!("hello.wj compilation failed");
}
println!("✅ Compilation succeeded");
let hello_rs = output_dir.join("hello.rs");
assert!(
hello_rs.exists(),
"Expected hello.rs to exist at {:?}, but it doesn't!\nFiles in output_dir: {:?}",
hello_rs,
std::fs::read_dir(output_dir)
.unwrap()
.filter_map(|e| e.ok())
.map(|e| e.file_name())
.collect::<Vec<_>>()
);
let cargo_toml = output_dir.join("Cargo.toml");
assert!(
cargo_toml.exists(),
"Expected Cargo.toml to exist at {:?}",
cargo_toml
);
let cargo_toml_content =
std::fs::read_to_string(&cargo_toml).expect("Failed to read Cargo.toml");
assert!(
cargo_toml_content.contains("[[bin]]"),
"Cargo.toml should contain [[bin]] section, got:\n{}",
cargo_toml_content
);
assert!(
cargo_toml_content.contains("name = \"hello\""),
"Cargo.toml should contain bin name, got:\n{}",
cargo_toml_content
);
assert!(
cargo_toml_content.contains("path = \"hello.rs\""),
"Cargo.toml should contain bin path, got:\n{}",
cargo_toml_content
);
println!("✅ Cargo.toml has correct [[bin]] section");
}