diff options
| author | Nadrieril | 2019-03-15 12:48:11 +0100 | 
|---|---|---|
| committer | Nadrieril | 2019-03-15 12:48:11 +0100 | 
| commit | 199daae790b4447465b7739e6af8025f7276b59a (patch) | |
| tree | 5b9d70aac72be92a63c89c7236aa2b289ca4c680 /dhall/tests/macros.rs | |
| parent | b302b14d445c1f1ee5dc65983c642bd46db1abfe (diff) | |
Rework test harness
Diffstat (limited to '')
| -rw-r--r-- | dhall/tests/macros.rs | 84 | 
1 files changed, 30 insertions, 54 deletions
diff --git a/dhall/tests/macros.rs b/dhall/tests/macros.rs index 4109f84..b67f720 100644 --- a/dhall/tests/macros.rs +++ b/dhall/tests/macros.rs @@ -1,6 +1,5 @@  use pretty_assertions::assert_eq as assert_eq_pretty; -#[macro_export]  macro_rules! assert_eq_display {      ($left:expr, $right:expr) => {{          match (&$left, &$right) { @@ -19,40 +18,12 @@ right: `{}`"#,  }  #[macro_export] -macro_rules! run_spec_test { -    (normalization, $path:expr) => { -        let base_path = concat!("../dhall-lang/tests/", $path); -        run_test(base_path, Feature::Normalization, ExpectedResult::Success); -    }; -    (parser, $path:expr) => { -        let base_path = concat!("../dhall-lang/tests/", $path); -        run_test(base_path, Feature::Parser, ExpectedResult::Success); -    }; -    (parser_failure, $path:expr) => { -        let base_path = concat!("../dhall-lang/tests/", $path); -        run_test(base_path, Feature::Parser, ExpectedResult::Failure); -    }; -    (typecheck_success, $path:expr) => { -        let base_path = concat!("../dhall-lang/tests/", $path); -        run_test(base_path, Feature::Typecheck, ExpectedResult::Success); -    }; -    (typecheck_failure, $path:expr) => { -        let base_path = concat!("../dhall-lang/tests/", $path); -        run_test(base_path, Feature::Typecheck, ExpectedResult::Failure); -    }; -} - -#[macro_export]  macro_rules! make_spec_test {      ($type:ident, $name:ident, $path:expr) => {          #[test]          #[allow(non_snake_case)] -        #[allow(unused_variables)] -        #[allow(unused_imports)]          fn $name() {              use crate::macros::*; -            use dhall::*; -            use dhall_core::*;              use std::thread;              // The parser stack overflows even on small files @@ -60,7 +31,7 @@ macro_rules! make_spec_test {              thread::Builder::new()                  .stack_size(4 * 1024 * 1024)                  .spawn(move || { -                    run_spec_test!($type, $path); +                    run_test($path, Feature::$type);                  })                  .unwrap()                  .join() @@ -74,26 +45,32 @@ use dhall_core::*;  use std::path::PathBuf;  pub enum Feature { -    Parser, +    ParserSuccess, +    ParserFailure,      Normalization, -    Typecheck, -} - -pub enum ExpectedResult { -    Success, -    Failure, +    TypecheckSuccess, +    TypecheckFailure,  }  pub fn read_dhall_file<'i>(file_path: &str) -> Result<Expr<X, X>, DhallError> {      load_dhall_file(&PathBuf::from(file_path), true)  } -pub fn run_test(base_path: &str, feature: Feature, expected: ExpectedResult) { -    use self::{ExpectedResult, Feature}; -    match (feature, expected) { -        (Feature::Parser, ExpectedResult::Success) => { -            let expr_file_path = base_path.to_owned() + "A.dhall"; -            let expected_file_path = base_path.to_owned() + "B.dhallb"; +pub fn run_test(base_path: &str, feature: Feature) { +    use self::Feature::*; +    let base_path_prefix = match feature { +        ParserSuccess => "parser/success/", +        ParserFailure => "parser/failure/", +        Normalization => "normalization/success/", +        TypecheckSuccess => "typecheck/success/", +        TypecheckFailure => "typecheck/failure/", +    }; +    let base_path = +        "../dhall-lang/tests/".to_owned() + base_path_prefix + base_path; +    match feature { +        ParserSuccess => { +            let expr_file_path = base_path.clone() + "A.dhall"; +            let expected_file_path = base_path + "B.dhallb";              let expr = read_dhall_file(&expr_file_path)                  .map_err(|e| println!("{}", e))                  .unwrap(); @@ -108,17 +85,17 @@ pub fn run_test(base_path: &str, feature: Feature, expected: ExpectedResult) {              assert_eq_pretty!(expr, expected);          } -        (Feature::Parser, ExpectedResult::Failure) => { -            let file_path = base_path.to_owned() + ".dhall"; +        ParserFailure => { +            let file_path = base_path + ".dhall";              let err = read_dhall_file(&file_path).unwrap_err();              match err {                  DhallError::ParseError(_) => {}                  e => panic!("Expected parse error, got: {:?}", e),              }          } -        (Feature::Normalization, ExpectedResult::Success) => { -            let expr_file_path = base_path.to_owned() + "A.dhall"; -            let expected_file_path = base_path.to_owned() + "B.dhall"; +        Normalization => { +            let expr_file_path = base_path.clone() + "A.dhall"; +            let expected_file_path = base_path + "B.dhall";              let expr = read_dhall_file(&expr_file_path).unwrap();              let expected = read_dhall_file(&expected_file_path).unwrap(); @@ -127,18 +104,17 @@ pub fn run_test(base_path: &str, feature: Feature, expected: ExpectedResult) {                  normalize::<_, X, _>(&expected)              );          } -        (Feature::Typecheck, ExpectedResult::Failure) => { -            let file_path = base_path.to_owned() + ".dhall"; +        TypecheckFailure => { +            let file_path = base_path + ".dhall";              let expr = read_dhall_file(&file_path).unwrap();              typecheck::type_of(&expr).unwrap_err();          } -        (Feature::Typecheck, ExpectedResult::Success) => { -            let expr_file_path = base_path.to_owned() + "A.dhall"; -            let expected_file_path = base_path.to_owned() + "B.dhall"; +        TypecheckSuccess => { +            let expr_file_path = base_path.clone() + "A.dhall"; +            let expected_file_path = base_path + "B.dhall";              let expr = read_dhall_file(&expr_file_path).unwrap();              let expected = read_dhall_file(&expected_file_path).unwrap();              typecheck::type_of(&Expr::Annot(bx(expr), bx(expected))).unwrap();          } -        _ => unimplemented!(),      }  }  | 
