diff --git a/Cargo.lock b/Cargo.lock index 3d600240..24df6660 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -130,6 +130,16 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "dyntest" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "829631f0607b7cf07af83ed53c58c8d1e0682663c6c92f737d9cc22d056736df" +dependencies = [ + "globset", + "walkdir", +] + [[package]] name = "encode_unicode" version = "0.3.6" @@ -168,6 +178,7 @@ dependencies = [ "TSPL", "cc", "clap", + "dyntest", "highlight_error", "insta", "num_cpus", diff --git a/Cargo.toml b/Cargo.toml index ff616da2..45198344 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,3 +29,8 @@ cuda = [] [dev-dependencies] insta = { version = "1.39.0", features = ["glob"] } +dyntest = "0.1.2" + +[[test]] +name = "run" +harness = false diff --git a/tests/run.rs b/tests/run.rs index baf805bc..6fbd2f72 100644 --- a/tests/run.rs +++ b/tests/run.rs @@ -1,34 +1,33 @@ use hvm::ast::Tree; use insta::assert_snapshot; +use dyntest::{dyntest, DynTester}; use TSPL::Parser; -use std::{ - collections::HashMap, error::Error, ffi::OsStr, fs, io::Read, path::{Path, PathBuf}, process::{Command, Stdio} -}; +use std::{collections::HashMap, error::Error, ffi::OsStr, fs, io::Read, path::Path, process::{Command, Stdio}}; -#[test] -fn test_run_programs() { - test_dir(&manifest_relative("tests/programs/")); -} - -#[test] -fn test_run_examples() { - test_dir(&manifest_relative("examples/")); -} - -fn test_dir(dir: &Path) { - insta::glob!(dir, "**/*.hvm", test_file) -} +dyntest!(test); -fn manifest_relative(sub: &str) -> PathBuf { - format!("{}/{}", env!("CARGO_MANIFEST_DIR"), sub).into() +fn test(t: &mut DynTester) { + for (name, path) in t.glob("{examples,tests/programs}/**/*.hvm") { + let test = t.test(name.clone(), { + let path = path.clone(); + move || { + let mut settings = insta::Settings::new(); + settings.set_prepend_module_to_snapshot(false); + settings.set_input_file(&path); + settings.set_snapshot_suffix(name); + settings.bind(|| { + test_run(&path); + }) + } + }); + if fs::read_to_string(path).unwrap().contains("@test-skip = 1") { + test.ignore(true); + } + } } -fn test_file(path: &Path) { - if fs::read_to_string(path).unwrap().contains("@test-skip = 1") { - println!("skipping {path:?}"); - return; - } +fn test_run(path: &Path) { println!("testing {path:?}..."); let rust_output = execute_hvm(&["run".as_ref(), path.as_os_str()]).unwrap(); assert_snapshot!(rust_output); diff --git a/tests/snapshots/run__file@sort_bitonic__main.hvm.snap b/tests/snapshots/run@examples::sort_bitonic::main.snap similarity index 100% rename from tests/snapshots/run__file@sort_bitonic__main.hvm.snap rename to tests/snapshots/run@examples::sort_bitonic::main.snap diff --git a/tests/snapshots/run__file@sort_radix__main.hvm.snap b/tests/snapshots/run@examples::sort_radix::main.snap similarity index 100% rename from tests/snapshots/run__file@sort_radix__main.hvm.snap rename to tests/snapshots/run@examples::sort_radix::main.snap diff --git a/tests/snapshots/run__file@stress__main.hvm.snap b/tests/snapshots/run@examples::stress::main.snap similarity index 100% rename from tests/snapshots/run__file@stress__main.hvm.snap rename to tests/snapshots/run@examples::stress::main.snap diff --git a/tests/snapshots/run__file@sum_rec__main.hvm.snap b/tests/snapshots/run@examples::sum_rec::main.snap similarity index 100% rename from tests/snapshots/run__file@sum_rec__main.hvm.snap rename to tests/snapshots/run@examples::sum_rec::main.snap diff --git a/tests/snapshots/run__file@sum_tree__main.hvm.snap b/tests/snapshots/run@examples::sum_tree::main.snap similarity index 100% rename from tests/snapshots/run__file@sum_tree__main.hvm.snap rename to tests/snapshots/run@examples::sum_tree::main.snap diff --git a/tests/snapshots/run__file@tuples__tuples.hvm.snap b/tests/snapshots/run@examples::tuples::tuples.snap similarity index 100% rename from tests/snapshots/run__file@tuples__tuples.hvm.snap rename to tests/snapshots/run@examples::tuples::tuples.snap diff --git a/tests/snapshots/run__file@empty.hvm.snap b/tests/snapshots/run@tests::programs::empty.snap similarity index 100% rename from tests/snapshots/run__file@empty.hvm.snap rename to tests/snapshots/run@tests::programs::empty.snap diff --git a/tests/snapshots/run__file@f24.hvm.snap b/tests/snapshots/run@tests::programs::f24.snap similarity index 100% rename from tests/snapshots/run__file@f24.hvm.snap rename to tests/snapshots/run@tests::programs::f24.snap diff --git a/tests/snapshots/run__file@i24.hvm.snap b/tests/snapshots/run@tests::programs::i24.snap similarity index 100% rename from tests/snapshots/run__file@i24.hvm.snap rename to tests/snapshots/run@tests::programs::i24.snap diff --git a/tests/snapshots/run__file@u24.hvm.snap b/tests/snapshots/run@tests::programs::u24.snap similarity index 100% rename from tests/snapshots/run__file@u24.hvm.snap rename to tests/snapshots/run@tests::programs::u24.snap