summaryrefslogtreecommitdiff
path: root/dhall
diff options
context:
space:
mode:
authorNadrieril2019-08-07 21:57:51 +0200
committerNadrieril2019-08-07 21:57:51 +0200
commita01cf8ad53a3839d13aa99a589ba0f2aa796d511 (patch)
treeb3f636de15e3c593a010d2099289434165cd303a /dhall
parent6654d441e5741013a8618907773ac54101e3fdf2 (diff)
Remove an annoying redundancy in the test harness
Diffstat (limited to '')
-rw-r--r--dhall/build.rs65
-rw-r--r--dhall/src/phase/resolve.rs4
-rw-r--r--dhall/src/tests.rs14
3 files changed, 33 insertions, 50 deletions
diff --git a/dhall/build.rs b/dhall/build.rs
index 1da06ca..3d4611e 100644
--- a/dhall/build.rs
+++ b/dhall/build.rs
@@ -41,29 +41,37 @@ fn dhall_files_in_dir<'a>(
fn make_test_module(
w: &mut impl Write, // Where to output the generated code
mod_name: &str, // Name of the module, used in the output of `cargo test`
- dir: &Path, // Directory containing the tests files
+ subdir: &str, // Directory containing the tests files
feature: &str, // Relevant variant of `dhall::tests::Feature`
mut exclude: impl FnMut(&str) -> bool, // Given a file name, whether to exclude it
) -> std::io::Result<()> {
+ let all_tests_dir = Path::new("../dhall-lang/tests/");
+ let tests_dir = all_tests_dir.join(subdir);
writeln!(w, "mod {} {{", mod_name)?;
- for (name, path) in dhall_files_in_dir(&dir.join("success/"), true) {
+ for (name, path) in dhall_files_in_dir(&tests_dir.join("success/"), true) {
if exclude(&("success/".to_owned() + &path)) {
continue;
}
writeln!(
w,
- r#"make_spec_test!({}, Success, success_{}, "success/{}");"#,
- feature, name, path
+ r#"make_spec_test!({}, Success, success_{}, "{}/success/{}");"#,
+ feature,
+ name,
+ tests_dir.to_string_lossy(),
+ path
)?;
}
- for (name, path) in dhall_files_in_dir(&dir.join("failure/"), false) {
+ for (name, path) in dhall_files_in_dir(&tests_dir.join("failure/"), false) {
if exclude(&("failure/".to_owned() + &path)) {
continue;
}
writeln!(
w,
- r#"make_spec_test!({}, Failure, failure_{}, "failure/{}");"#,
- feature, name, path
+ r#"make_spec_test!({}, Failure, failure_{}, "{}/failure/{}");"#,
+ feature,
+ name,
+ tests_dir.to_string_lossy(),
+ path
)?;
}
writeln!(w, "}}")?;
@@ -71,26 +79,20 @@ fn make_test_module(
}
fn main() -> std::io::Result<()> {
- // Tries to detect when the submodule gets updated; doesn't really work.
+ // Tries to detect when the submodule gets updated.
// To force regeneration of the test list, just `touch dhall-lang/.git`
println!("cargo:rerun-if-changed=../dhall-lang/.git");
println!(
"cargo:rerun-if-changed=../.git/modules/dhall-lang/refs/heads/master"
);
let out_dir = env::var("OUT_DIR").unwrap();
- let tests_dir = Path::new("../dhall-lang/tests/");
let parser_tests_path = Path::new(&out_dir).join("spec_tests.rs");
let mut file = File::create(parser_tests_path)?;
- make_test_module(
- &mut file,
- "parse",
- &tests_dir.join("parser/"),
- "Parser",
- |path| {
- // Too slow in debug mode
- path == "success/largeExpression"
+ make_test_module(&mut file, "parse", "parser/", "Parser", |path| {
+ // Too slow in debug mode
+ path == "success/largeExpression"
// TODO: Inline headers
|| path == "success/unit/import/parenthesizeUsing"
|| path == "success/unit/import/inlineUsing"
@@ -106,17 +108,11 @@ fn main() -> std::io::Result<()> {
|| path == "success/unit/import/urls/emptyPathSegment"
// TODO: toMap
|| path == "success/toMap"
- },
- )?;
+ })?;
- make_test_module(
- &mut file,
- "printer",
- &tests_dir.join("parser/"),
- "Printer",
- |path| {
- // Failure tests are only for the parser
- path.starts_with("failure/")
+ make_test_module(&mut file, "printer", "parser/", "Printer", |path| {
+ // Failure tests are only for the parser
+ path.starts_with("failure/")
// Too slow in debug mode
|| path == "success/largeExpression"
// TODO: Inline headers
@@ -132,13 +128,12 @@ fn main() -> std::io::Result<()> {
|| path == "success/unit/import/urls/emptyPathSegment"
// TODO: toMap
|| path == "success/toMap"
- },
- )?;
+ })?;
make_test_module(
&mut file,
"binary_encoding",
- &tests_dir.join("parser/"),
+ "parser/",
"BinaryEncoding",
|path| {
// Failure tests are only for the parser
@@ -169,7 +164,7 @@ fn main() -> std::io::Result<()> {
make_test_module(
&mut file,
"binary_decoding",
- &tests_dir.join("binary-decode/"),
+ "binary-decode/",
"BinaryDecoding",
|path| {
false
@@ -184,7 +179,7 @@ fn main() -> std::io::Result<()> {
make_test_module(
&mut file,
"beta_normalize",
- &tests_dir.join("normalization/"),
+ "normalization/",
"Normalization",
|path| {
// We don't support bignums
@@ -207,7 +202,7 @@ fn main() -> std::io::Result<()> {
make_test_module(
&mut file,
"alpha_normalize",
- &tests_dir.join("alpha-normalization/"),
+ "alpha-normalization/",
"AlphaNormalization",
|_| false,
)?;
@@ -215,7 +210,7 @@ fn main() -> std::io::Result<()> {
make_test_module(
&mut file,
"typecheck",
- &tests_dir.join("typecheck/"),
+ "typecheck/",
"Typecheck",
|path| {
false
@@ -239,7 +234,7 @@ fn main() -> std::io::Result<()> {
make_test_module(
&mut file,
"type_inference",
- &tests_dir.join("type-inference/"),
+ "type-inference/",
"TypeInference",
|path| {
false
diff --git a/dhall/src/phase/resolve.rs b/dhall/src/phase/resolve.rs
index 0609694..0b29513 100644
--- a/dhall/src/phase/resolve.rs
+++ b/dhall/src/phase/resolve.rs
@@ -110,13 +110,13 @@ mod spec_tests {
macro_rules! import_success {
($name:ident, $path:expr) => {
- make_spec_test!(Import, Success, $name, &("success/".to_owned() + $path));
+ make_spec_test!(Import, Success, $name, &("../dhall-lang/tests/import/success/".to_owned() + $path));
};
}
// macro_rules! import_failure {
// ($name:ident, $path:expr) => {
- // make_spec_test!(Import, Failure, $name, &("failure/".to_owned() + $path));
+ // make_spec_test!(Import, Failure, $name, &("../dhall-lang/tests/import/failure/".to_owned() + $path));
// };
// }
diff --git a/dhall/src/tests.rs b/dhall/src/tests.rs
index da48d15..9784eec 100644
--- a/dhall/src/tests.rs
+++ b/dhall/src/tests.rs
@@ -81,19 +81,7 @@ pub fn run_test(
) -> Result<()> {
use self::Feature::*;
use self::Status::*;
- let feature_prefix = match feature {
- Parser => "parser/",
- Printer => "parser/",
- BinaryEncoding => "parser/",
- BinaryDecoding => "binary-decode/",
- Import => "import/",
- Normalization => "normalization/",
- AlphaNormalization => "alpha-normalization/",
- Typecheck => "typecheck/",
- TypeInference => "type-inference/",
- };
- let base_path =
- "../dhall-lang/tests/".to_owned() + feature_prefix + base_path;
+ let base_path = base_path.to_owned();
match status {
Success => {
match feature {