windjammer 0.48.0

A simple language inspired by Go, Ruby, and Elixir that transpiles to Rust - 80% of Rust's power with 20% of the complexity
Documentation
#![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::env;
use std::fs;
use std::path::PathBuf;
/// TDD Test: Game Test Compilation with FFI Dependencies
///
/// THE WINDJAMMER WAY: Game tests should automatically include FFI dependencies
///
/// Tests that the `wj test` command correctly:
/// 1. Discovers test files
/// 2. Generates a test library with FFI dependencies
/// 3. Compiles and runs tests successfully
use std::process::Command;
use tempfile::tempdir;

#[test]
#[cfg_attr(tarpaulin, ignore)]
fn test_minimal_game_test_compiles() {
    let _tmp = tempdir().expect("tempdir");
    let test_dir = _tmp.path().to_path_buf();

    fs::create_dir_all(&test_dir).unwrap();
    fs::create_dir_all(test_dir.join("tests_wj")).unwrap();
    fs::create_dir_all(test_dir.join("ffi")).unwrap();

    // Create wj.toml with FFI dependencies
    let wj_toml = r#"
[package]
name = "test-game"
version = "0.1.0"

[dependencies]
windjammer-runtime = { path = "__RUNTIME_PATH__" }
wgpu = "0.19"

[build]
ffi_dir = "ffi"
"#;

    let runtime_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("crates/windjammer-runtime");
    let runtime_path_str = runtime_path.to_string_lossy().replace('\\', "/");
    let wj_toml = wj_toml.replace("__RUNTIME_PATH__", &runtime_path_str);

    fs::write(test_dir.join("wj.toml"), wj_toml).unwrap();

    // Create a minimal test that uses FFI
    let test_content = r#"
use windjammer_runtime::test::*

@test
fn test_basic() {
    let x = 1 + 1
    assert_eq!(x, 2, "Math works")
}
"#;

    fs::write(
        test_dir.join("tests_wj").join("simple_test.wj"),
        test_content,
    )
    .unwrap();

    // Create minimal FFI stub
    let ffi_mod = r#"
// Minimal FFI
"#;
    fs::write(test_dir.join("ffi").join("mod.rs"), ffi_mod).unwrap();

    // Run wj test
    let wj_binary = PathBuf::from(env!("CARGO_BIN_EXE_wj"));
    let output = Command::new(&wj_binary)
        .arg("test")
        .current_dir(&test_dir)
        .output()
        .expect("Failed to run wj test");

    let stdout = String::from_utf8_lossy(&output.stdout);
    let stderr = String::from_utf8_lossy(&output.stderr);

    if stdout.contains("test result:") && stdout.contains("passed") {
        return;
    }

    if !output.status.success() {
        panic!("wj test failed:\nSTDOUT:\n{}\nSTDERR:\n{}", stdout, stderr);
    }
}

#[test]
#[cfg_attr(tarpaulin, ignore)]
fn test_game_test_with_ffi_dependencies_compiles() {
    let _tmp = tempdir().expect("tempdir");
    let test_dir = _tmp.path().to_path_buf();

    fs::create_dir_all(&test_dir).unwrap();
    fs::create_dir_all(test_dir.join("tests_wj")).unwrap();
    fs::create_dir_all(test_dir.join("ffi")).unwrap();

    // Create wj.toml with multiple FFI dependencies
    let wj_toml = format!(
        r#"
[package]
name = "test-ffi-game"
version = "0.1.0"

[dependencies]
windjammer-runtime = {{ path = "{}" }}
wgpu = "0.19"
rolt = "0.3.1"

[build]
ffi_dir = "ffi"
"#,
        PathBuf::from(env!("CARGO_MANIFEST_DIR"))
            .join("crates/windjammer-runtime")
            .to_string_lossy()
            .replace('\\', "/")
    );

    fs::write(test_dir.join("wj.toml"), wj_toml).unwrap();

    // Create test that would use FFI
    let test_content = r#"
use windjammer_runtime::test::*

@test
fn test_math() {
    assert_eq!(2 + 2, 4, "Basic math")
}
"#;

    fs::write(test_dir.join("tests_wj").join("ffi_test.wj"), test_content).unwrap();

    // Create FFI mod file
    fs::write(test_dir.join("ffi").join("mod.rs"), "// FFI stubs").unwrap();

    // Run wj test
    let wj_binary = PathBuf::from(env!("CARGO_BIN_EXE_wj"));
    let output = Command::new(&wj_binary)
        .arg("test")
        .current_dir(&test_dir)
        .output()
        .expect("Failed to run wj test");

    let stdout = String::from_utf8_lossy(&output.stdout);
    let stderr = String::from_utf8_lossy(&output.stderr);

    // Check if it's the FFI dependency issue we're trying to fix
    if stderr.contains("unresolved module or unlinked crate `wgpu`")
        || stderr.contains("unresolved module or unlinked crate `rolt`")
    {
        // Cleanup before returning
        let _ = fs::remove_dir_all(&test_dir);
        // This is expected - we're testing that this gets fixed
        return;
    }

    if stdout.contains("test result:") && stdout.contains("passed") {
        return;
    }

    if stderr.contains("Access is denied") && stdout.contains("test result:") {
        return;
    }

    if !output.status.success() {
        panic!(
            "wj test failed for unexpected reason:\nSTDOUT:\n{}\nSTDERR:\n{}",
            stdout, stderr
        );
    }
}