#![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 tempfile::TempDir;
#[test]
#[cfg_attr(tarpaulin, ignore)]
fn test_multi_file_no_inline_modules() {
let temp_dir = TempDir::new().unwrap();
let src_dir = temp_dir.path().join("src");
fs::create_dir(&src_dir).unwrap();
fs::write(
src_dir.join("math.wj"),
r#"
pub struct Vec2 {
pub x: f32,
pub y: f32,
}
impl Vec2 {
pub fn new(x: f32, y: f32) -> Vec2 {
Vec2 { x, y }
}
}
"#,
)
.unwrap();
fs::write(
src_dir.join("physics.wj"),
r#"
use math::Vec2
pub struct PhysicsBody {
pub position: Vec2,
}
"#,
)
.unwrap();
let output_dir = temp_dir.path().join("build");
let wj_compiler = PathBuf::from(env!("CARGO_BIN_EXE_wj"));
let status = std::process::Command::new(&wj_compiler)
.args([
"build",
src_dir.to_str().unwrap(),
"--output",
output_dir.to_str().unwrap(),
"--no-cargo",
])
.status()
.unwrap();
assert!(status.success(), "Compilation failed");
let physics_rs = fs::read_to_string(output_dir.join("physics.rs")).unwrap();
assert!(
!physics_rs.contains("pub mod math {"),
"Generated code should not inline module definitions!\nGenerated code:\n{}",
physics_rs
);
assert!(
physics_rs.contains("use crate::math::Vec2") || physics_rs.contains("use super::math"),
"Generated code should have proper imports!\nGenerated code:\n{}",
physics_rs
);
assert!(
physics_rs.contains("pub struct PhysicsBody"),
"Generated code should contain the actual struct!\nGenerated code:\n{}",
physics_rs
);
}