diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index a11bc97d..89ce51f1 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -2,6 +2,4 @@ ### Checklist -- [ ] If this PR adds or changes a language feature, it is used in - `examples/kitchen_sink.simf`, and `test-data/kitchen_sink.json` is - regenerated. +- [ ] New or changed language features are used in `fixtures/kitchen_sink.simf` (see its header). diff --git a/examples/array_fold_2n.simf b/fixtures/array_fold_2n.simf similarity index 100% rename from examples/array_fold_2n.simf rename to fixtures/array_fold_2n.simf diff --git a/examples/kitchen_sink.args b/fixtures/kitchen_sink.args similarity index 100% rename from examples/kitchen_sink.args rename to fixtures/kitchen_sink.args diff --git a/examples/kitchen_sink.simf b/fixtures/kitchen_sink.simf similarity index 95% rename from examples/kitchen_sink.simf rename to fixtures/kitchen_sink.simf index 0d3b9ecc..29a83209 100644 --- a/examples/kitchen_sink.simf +++ b/fixtures/kitchen_sink.simf @@ -8,9 +8,14 @@ simc ">=0.8.0"; * the `kitchen_sink` regression test. * * This program is not a meaningful contract. When adding a language feature, - * extend this file and regenerate `test-data/kitchen_sink.json`. + * extend this file and regenerate `test-data/kitchen_sink.json`, adding a `-Z` + * flag for any new unstable feature: * - * Requires -Z imports -Z enums -Z raw_hash. + * simc fixtures/kitchen_sink.simf -a fixtures/kitchen_sink.args \ + * -w fixtures/kitchen_sink.wit -Z imports -Z enums -Z raw_hash \ + * --debug --json | jq '{program, witness}' > test-data/kitchen_sink.json + * + * `--debug` is needed because the regression test compiles with debug symbols. */ // Type aliases, both of custom types and of builtin aliases diff --git a/examples/kitchen_sink.wit b/fixtures/kitchen_sink.wit similarity index 100% rename from examples/kitchen_sink.wit rename to fixtures/kitchen_sink.wit diff --git a/src/lib.rs b/src/lib.rs index 7bc750db..8046d7ca 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1129,7 +1129,7 @@ pub(crate) mod tests { #[test] fn regression_153() { - TestCase::program_file("./examples/array_fold_2n.simf") + TestCase::program_file("./fixtures/array_fold_2n.simf") .with_witness_values(WitnessValues::default()) .assert_run_success(); } @@ -1192,11 +1192,11 @@ pub(crate) mod tests { #[cfg(feature = "serde")] fn kitchen_sink() { TestCase::template_file_with_unstable( - "./examples/kitchen_sink.simf", + "./fixtures/kitchen_sink.simf", UnstableFeatures::all(), ) - .with_argument_file("./examples/kitchen_sink.args") - .with_witness_file("./examples/kitchen_sink.wit") + .with_argument_file("./fixtures/kitchen_sink.args") + .with_witness_file("./fixtures/kitchen_sink.wit") .assert_run_success(); } @@ -1586,6 +1586,11 @@ fn main() { } fn regression_test_with_features(name: &str, features: crate::UnstableFeatures) { + regression_test_in("./examples", name, features); + } + + /// Compare the encoding of `/.simf` with `test-data/.json`. + fn regression_test_in(dir: &str, name: &str, features: crate::UnstableFeatures) { let program = serde_json::from_str::( std::fs::read_to_string(format!("./test-data/{}.json", name)) .unwrap() @@ -1593,11 +1598,9 @@ fn main() { ) .unwrap(); - let template = TestCase::template_file_with_unstable( - format!("./examples/{}.simf", name), - features, - ); - let arguments_path = format!("./examples/{}.args", name); + let template = + TestCase::template_file_with_unstable(format!("{dir}/{name}.simf"), features); + let arguments_path = format!("{dir}/{name}.args"); let test_case = if std::path::Path::new(&arguments_path).exists() { template.with_argument_file(arguments_path) } else { @@ -1606,7 +1609,7 @@ fn main() { match program.witness { Some(wit) => { let (new_program, new_witness) = test_case - .with_witness_file(format!("./examples/{}.wit", name)) + .with_witness_file(format!("{dir}/{name}.wit")) .get_encoding_with_witness(); assert_eq!( program.program, new_program, @@ -1630,7 +1633,11 @@ fn main() { #[test] fn array_fold_2n_regression() { - regression_test("array_fold_2n"); + regression_test_in( + "./fixtures", + "array_fold_2n", + crate::UnstableFeatures::none(), + ); } #[test] @@ -1670,7 +1677,7 @@ fn main() { #[test] fn kitchen_sink_regression() { - regression_test_with_features("kitchen_sink", crate::UnstableFeatures::all()); + regression_test_in("./fixtures", "kitchen_sink", crate::UnstableFeatures::all()); } #[test] diff --git a/tests/lex_lossless_coverage.rs b/tests/lex_lossless_coverage.rs index 954ae5e2..618df806 100644 --- a/tests/lex_lossless_coverage.rs +++ b/tests/lex_lossless_coverage.rs @@ -61,7 +61,7 @@ mod lossless_test { } test_lex_coverage! { - array_fold_2n_lossless: "array_fold_2n.simf", + array_fold_2n_lossless: "../fixtures/array_fold_2n.simf", array_fold_lossless: "array_fold.simf", cat_lossless: "cat.simf", ctv_lossless: "ctv.simf",