#![cfg(any(
not(any(
feature = "parser_tests",
feature = "analyzer_tests",
feature = "codegen_tests",
feature = "interpreter_tests",
feature = "conformance_tests",
feature = "integration_tests",
)),
feature = "parser_tests",
))]
use std::env;
use std::fs;
use std::path::PathBuf;
#[test]
#[cfg_attr(tarpaulin, ignore)]
fn test_test_cases_decorator_parses() {
let _tmp = tempfile::tempdir().unwrap();
let test_dir = _tmp.path().join(format!(
"wj_test_cases_{}_{}",
std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap()
.as_nanos(),
std::process::id()
));
fs::create_dir_all(&test_dir).unwrap();
let test_content = r#"
use windjammer_runtime::test::*
@test_cases([
[5, 5],
[10, 10]
])
fn test_capacity(capacity: i32, expected: i32) {
assert_eq!(capacity, expected, "Should match")
}
"#;
fs::write(test_dir.join("test_cases.wj"), test_content).unwrap();
let wj_binary = PathBuf::from(env!("CARGO_BIN_EXE_wj"));
let output = std::process::Command::new(&wj_binary)
.arg("build")
.arg("--no-cargo")
.arg(test_dir.join("test_cases.wj"))
.output()
.expect("Failed to run wj build");
let stderr = String::from_utf8_lossy(&output.stderr);
let stdout = String::from_utf8_lossy(&output.stdout);
if stderr.contains("Expected pattern, got Assign")
|| stdout.contains("Expected pattern, got Assign")
{
panic!(
"Parser error 'Expected pattern, got Assign' occurred:\nSTDOUT:\n{}\nSTDERR:\n{}",
stdout, stderr
);
}
}
#[test]
#[cfg_attr(tarpaulin, ignore)]
fn test_simple_test_decorator_works() {
let _tmp2 = tempfile::tempdir().unwrap();
let test_dir = _tmp2.path().join(format!(
"wj_simple_test_{}_{}",
std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap()
.as_nanos(),
std::process::id()
));
fs::create_dir_all(&test_dir).unwrap();
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("simple_test.wj"), test_content).unwrap();
let wj_binary = PathBuf::from(env!("CARGO_BIN_EXE_wj"));
let output = std::process::Command::new(&wj_binary)
.arg("build")
.arg("--no-cargo")
.arg(test_dir.join("simple_test.wj"))
.output()
.expect("Failed to run wj build");
let stderr = String::from_utf8_lossy(&output.stderr);
let stdout = String::from_utf8_lossy(&output.stdout);
assert!(
!stderr.contains("Expected pattern") && !stdout.contains("Expected pattern"),
"Should not have parser errors for simple @test decorator:\nSTDOUT:\n{}\nSTDERR:\n{}",
stdout,
stderr
);
}