1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
use std::fs;
use std::path::{Path, PathBuf};
use std::process::Command;
/// Test that all .lua and .p8lua files can be loaded and run (with a timeout)
#[test]
fn test_run_lua_files() {
let mut test_files = Vec::new();
// Find all .lua and .p8lua files in examples/ and tests/ directories
//
let dir_path = Path::new(env!("CARGO_MANIFEST_DIR")).join("tests");
find_lua_files(&dir_path, &mut test_files);
find_lua_files(&dir_path.join("tiled"), &mut test_files);
if test_files.is_empty() {
panic!("No .lua or .p8lua files found to test");
}
// Run each file
for file in test_files {
// Run with --pause flag to prevent the app from running indefinitely
// Note: The app will still try to create a window, but with --pause it should
// pause immediately. In headless CI environments, this might fail if no display
// is available, but the test will at least verify the file can be loaded and parsed.
let mut command = Command::new("cargo");
command
.args(&[
// "n9",
"run",
"--",
"check",
file.to_str().expect("path should be valid UTF-8"),
])
.current_dir(env!("CARGO_MANIFEST_DIR"))
// .env("NANO9_ASSETS", Path::new(env!("CARGO_MANIFEST_DIR")).join("tests"))
;
// println!("The command {command:?}");
let output = command.output().expect("Failed to execute cargo run");
// Check if the command succeeded (exit code 0)
// We expect it to succeed in loading, even if it pauses
if !output.status.success() {
let stderr = String::from_utf8_lossy(&output.stderr);
let stdout = String::from_utf8_lossy(&output.stdout);
panic!(
"Failed to run {} with exit code {:?}.\nSTDERR:\n{}\nSTDOUT:\n{}",
file.display(),
output.status.code(),
stderr,
stdout,
);
}
}
}
fn find_lua_files(dir: &Path, files: &mut Vec<PathBuf>) {
let root = Path::new(env!("CARGO_MANIFEST_DIR"));
if !dir.exists() {
return;
}
if let Ok(entries) = fs::read_dir(&dir) {
for entry in entries.flatten() {
let path = entry.path();
if !path.is_dir()
&& let Some(ext) = path.extension()
{
if ext == "lua" || ext == "p8lua" || ext == "p8" {
files.push(path.strip_prefix(root).unwrap().to_path_buf());
}
}
}
}
}