diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1bc6fa1..bad92ee 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,6 +16,9 @@ jobs: - uses: actions/checkout@v6 - uses: dtolnay/rust-toolchain@stable - uses: Swatinem/rust-cache@v2 + - uses: mlugg/setup-zig@v2 + with: + version: "0.15.2" - run: cargo fmt --check - run: cargo build - run: cargo test diff --git a/src/commands/build.rs b/src/commands/build.rs index 4b6a6cf..43fd53d 100644 --- a/src/commands/build.rs +++ b/src/commands/build.rs @@ -4,6 +4,7 @@ use std::process::Command; pub fn run(input_path: &str, ast: &crate::parser::Program, opt_level: Option<&str>) { let (stem, zig_path) = emit_zig(input_path, ast); + std::fs::create_dir_all("zyre-out").unwrap(); let exe_path = if cfg!(windows) { format!("zyre-out/{}.exe", stem) } else { diff --git a/tests/examples.rs b/tests/examples.rs new file mode 100644 index 0000000..dbfe5b9 --- /dev/null +++ b/tests/examples.rs @@ -0,0 +1,29 @@ +use std::process::Command; + +fn run_example(path: &std::path::Path) { + let bin = env!("CARGO_BIN_EXE_zyre"); + let out = Command::new(bin) + .args(["run", &path.to_string_lossy()]) + .stdout(std::process::Stdio::piped()) + .stderr(std::process::Stdio::piped()) + .output() + .unwrap_or_else(|e| panic!("failed to spawn zyre for {}: {}", path.display(), e)); + assert!( + out.status.success(), + "{} exited with non-zero status", + path.display() + ); +} + +#[test] +fn test_examples() { + let examples = std::fs::read_dir("examples") + .expect("examples/ directory not found") + .filter_map(|e| e.ok()) + .filter(|e| e.path().extension().map(|x| x == "zy").unwrap_or(false)) + .map(|e| e.path()); + + for path in examples { + run_example(&path); + } +}