From 36070e6c285ecb96fad56470261c66b082685e56 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Mon, 11 Nov 2019 09:57:29 +0000 Subject: Generate import tests automatically --- dhall/build.rs | 42 +++++++++++++++++++++++++++++++++++++++++ dhall/src/lib.rs | 1 - dhall/src/phase/resolve.rs | 47 ---------------------------------------------- dhall/src/tests.rs | 31 +++++++++++++++--------------- 4 files changed, 57 insertions(+), 64 deletions(-) (limited to 'dhall') diff --git a/dhall/build.rs b/dhall/build.rs index b7ed6ca..c7d339c 100644 --- a/dhall/build.rs +++ b/dhall/build.rs @@ -238,6 +238,48 @@ fn main() -> std::io::Result<()> { }, )?; + make_test_module( + &mut file, + TestFeature { + module_name: "import_success", + directory: spec_tests_dir.join("import/success/"), + variant: "ImportSuccess", + path_filter: |path: &str| { + false + || path == "alternativeEnvNatural" + || path == "alternativeEnvSimple" + || path == "alternativeHashMismatch" + || path == "asLocation" + || path == "asText" + || path == "customHeaders" + || path == "hashFromCache" + || path == "headerForwarding" + || path == "noHeaderForwarding" + }, + input_type: FileType::Text, + output_type: Some(FileType::Text), + }, + )?; + + make_test_module( + &mut file, + TestFeature { + module_name: "import_failure", + directory: spec_tests_dir.join("import/failure/"), + variant: "ImportFailure", + path_filter: |path: &str| { + false + || path == "alternativeEnv" + || path == "alternativeEnvMissing" + || path == "hashMismatch" + || path == "missing" + || path == "referentiallyInsane" + }, + input_type: FileType::Text, + output_type: None, + }, + )?; + make_test_module( &mut file, TestFeature { diff --git a/dhall/src/lib.rs b/dhall/src/lib.rs index 0a430e4..9656612 100644 --- a/dhall/src/lib.rs +++ b/dhall/src/lib.rs @@ -11,7 +11,6 @@ clippy::ptr_arg )] -#[macro_use] mod tests; pub mod core; diff --git a/dhall/src/phase/resolve.rs b/dhall/src/phase/resolve.rs index c5f2ac8..c302bfa 100644 --- a/dhall/src/phase/resolve.rs +++ b/dhall/src/phase/resolve.rs @@ -178,50 +178,3 @@ impl Canonicalize for ImportLocation { } } } - -#[cfg(test)] -#[rustfmt::skip] -mod spec_tests { - macro_rules! import_success { - ($name:ident, $path:expr) => { - make_spec_test!( - ImportSuccess( - &("../dhall-lang/tests/import/success/".to_owned() + $path + "A.dhall"), - &("../dhall-lang/tests/import/success/".to_owned() + $path + "B.dhall") - ), - $name - ); - }; - } - - // macro_rules! import_failure { - // ($name:ident, $path:expr) => { - // make_spec_test!( - // ImportFailure(&("../dhall-lang/tests/import/failure/".to_owned() + $path + ".dhall")), - // $name - // ); - // }; - // } - - // import_success!(success_alternativeEnvNatural, "alternativeEnvNatural"); - // import_success!(success_alternativeEnvSimple, "alternativeEnvSimple"); - // import_success!(success_alternativeHashMismatch, "alternativeHashMismatch"); - import_success!(success_alternativeNatural, "alternativeNatural"); - import_success!(success_alternativeParseError, "alternativeParseError"); - import_success!(success_alternativeTypeError, "alternativeTypeError"); - // import_success!(success_asLocation, "asLocation"); - // import_success!(success_asText, "asText"); - // import_success!(success_customHeaders, "customHeaders"); - import_success!(success_fieldOrder, "fieldOrder"); - // note: this one needs special setup with env variables - // import_success!(success_hashFromCache, "hashFromCache"); - // import_success!(success_headerForwarding, "headerForwarding"); - // import_success!(success_nestedHash, "nestedHash"); - // import_success!(success_noHeaderForwarding, "noHeaderForwarding"); - // import_failure!(failure_alternativeEnv, "alternativeEnv"); - // import_failure!(failure_alternativeEnvMissing, "alternativeEnvMissing"); - // import_failure!(failure_cycle, "cycle"); - // import_failure!(failure_hashMismatch, "hashMismatch"); - // import_failure!(failure_missing, "missing"); - // import_failure!(failure_referentiallyInsane, "referentiallyInsane"); -} diff --git a/dhall/src/tests.rs b/dhall/src/tests.rs index 80994d1..b98489f 100644 --- a/dhall/src/tests.rs +++ b/dhall/src/tests.rs @@ -20,22 +20,6 @@ right: `{}`"#, }}; } -#[macro_export] -macro_rules! make_spec_test { - ($type:expr, $name:ident) => { - #[test] - #[allow(non_snake_case)] - fn $name() { - use crate::tests::Test::*; - use crate::tests::*; - match run_test_stringy_error($type) { - Ok(_) => {} - Err(s) => panic!(s), - } - } - }; -} - use std::fs::File; use std::io::Read; use std::path::PathBuf; @@ -200,6 +184,21 @@ pub fn run_test(test: Test<'_>) -> Result<()> { #[cfg(test)] mod spec { + macro_rules! make_spec_test { + ($type:expr, $name:ident) => { + #[test] + #[allow(non_snake_case)] + fn $name() { + use crate::tests::Test::*; + use crate::tests::*; + match run_test_stringy_error($type) { + Ok(_) => {} + Err(s) => panic!(s), + } + } + }; + } + // See build.rs include!(concat!(env!("OUT_DIR"), "/spec_tests.rs")); } -- cgit v1.2.3