summaryrefslogtreecommitdiff
path: root/dhall
diff options
context:
space:
mode:
authorNadrieril2019-05-12 19:06:32 +0200
committerNadrieril2019-05-12 19:06:32 +0200
commit8abb4843a4d0fd62a70fc704f894b76b52d40c9b (patch)
treecb97b008437043a29a314c20b26798adb25a7f53 /dhall
parent1274a997c49ae8dcf73ec6a3d1afe96dd03a2ae2 (diff)
Split-off printer and binary encoding tests from parser tests
Diffstat (limited to '')
-rw-r--r--dhall/build.rs26
-rw-r--r--dhall/src/tests.rs96
2 files changed, 85 insertions, 37 deletions
diff --git a/dhall/build.rs b/dhall/build.rs
index 3548d33..d28239d 100644
--- a/dhall/build.rs
+++ b/dhall/build.rs
@@ -85,6 +85,32 @@ fn main() -> std::io::Result<()> {
|path| {
// Too slow in debug mode
path == "success/largeExpression"
+ },
+ )?;
+
+ make_test_module(
+ &mut file,
+ "printer",
+ &tests_dir.join("parser/"),
+ "Printer",
+ |path| {
+ // Failure tests are only for the parser
+ path.starts_with("failure/")
+ // Too slow in debug mode
+ || path == "success/largeExpression"
+ },
+ )?;
+
+ make_test_module(
+ &mut file,
+ "binary_encoding",
+ &tests_dir.join("parser/"),
+ "BinaryEncoding",
+ |path| {
+ // Failure tests are only for the parser
+ path.starts_with("failure/")
+ // Too slow in debug mode
+ || path == "success/largeExpression"
// Fails binary encoding
|| path == "success/multilet"
|| path == "success/double"
diff --git a/dhall/src/tests.rs b/dhall/src/tests.rs
index b7a38be..2f68dac 100644
--- a/dhall/src/tests.rs
+++ b/dhall/src/tests.rs
@@ -43,6 +43,8 @@ use crate::phase::Parsed;
#[derive(Copy, Clone)]
pub enum Feature {
Parser,
+ Printer,
+ BinaryEncoding,
Import,
Normalization,
AlphaNormalization,
@@ -80,6 +82,8 @@ pub fn run_test(
use self::Status::*;
let feature_prefix = match feature {
Parser => "parser/",
+ Printer => "parser/",
+ BinaryEncoding => "parser/",
Import => "import/",
Normalization => "normalization/",
AlphaNormalization => "alpha-normalization/",
@@ -93,45 +97,62 @@ pub fn run_test(
let expr_file_path = base_path.clone() + "A.dhall";
let expr = parse_file_str(&expr_file_path)?;
- if let Parser = feature {
- // Compare parse/decoded
- let expected_file_path = base_path + "B.dhallb";
- let expected_file_path = PathBuf::from(&expected_file_path);
- let mut expected_data = Vec::new();
- {
- File::open(&expected_file_path)?
- .read_to_end(&mut expected_data)?;
+ match feature {
+ Parser => {
+ // Compare parse/decoded
+ let expected_file_path = base_path + "B.dhallb";
+ let expected_file_path = PathBuf::from(&expected_file_path);
+ let mut expected_data = Vec::new();
+ {
+ File::open(&expected_file_path)?
+ .read_to_end(&mut expected_data)?;
+ }
+ let expected = Parsed::parse_binary(&expected_data)?;
+ assert_eq_pretty!(expr, expected);
+
+ return Ok(());
}
- let expected = Parsed::parse_binary(&expected_data)?;
- assert_eq_pretty!(expr, expected);
-
- // Compare encoded/expected
- let expr_data = expr.encode()?;
- // Compare bit-by-bit
- if expr_data != expected_data {
- // use std::io::Write;
- // File::create(&expected_file_path)?.write_all(&expr_data)?;
- // Pretty-print difference
- assert_eq_pretty!(
- serde_cbor::de::from_slice::<serde_cbor::value::Value>(
- &expr_data
- )
- .unwrap(),
- serde_cbor::de::from_slice::<serde_cbor::value::Value>(
- &expected_data
- )
- .unwrap()
- );
- // If difference was not visible in the cbor::Value
- assert_eq!(expr_data, expected_data);
+ Printer => {
+ // Round-trip pretty-printer
+ let expr_string = expr.to_string();
+ let expected = expr;
+ let expr: Parsed = Parsed::parse_str(&expr_string)?;
+ assert_eq!(expr, expected);
+
+ return Ok(());
}
+ BinaryEncoding => {
+ let expected_file_path = base_path + "B.dhallb";
+ let expected_file_path = PathBuf::from(&expected_file_path);
+ let mut expected_data = Vec::new();
+ {
+ File::open(&expected_file_path)?
+ .read_to_end(&mut expected_data)?;
+ }
+ let expr_data = expr.encode()?;
+
+ // Compare bit-by-bit
+ if expr_data != expected_data {
+ // use std::io::Write;
+ // File::create(&expected_file_path)?.write_all(&expr_data)?;
+ // Pretty-print difference
+ assert_eq_pretty!(
+ serde_cbor::de::from_slice::<
+ serde_cbor::value::Value,
+ >(&expr_data)
+ .unwrap(),
+ serde_cbor::de::from_slice::<
+ serde_cbor::value::Value,
+ >(&expected_data)
+ .unwrap()
+ );
+ // If difference was not visible in the cbor::Value
+ assert_eq!(expr_data, expected_data);
+ }
- // Round-trip pretty-printer
- let expr_string = expr.to_string();
- let expr: Parsed = Parsed::parse_str(&expr_string)?;
- assert_eq!(expr, expected);
-
- return Ok(());
+ return Ok(());
+ }
+ _ => {}
}
let expr = expr.resolve()?;
@@ -143,7 +164,7 @@ pub fn run_test(
.normalize();
match feature {
- Parser => unreachable!(),
+ Parser | Printer | BinaryEncoding => unreachable!(),
Import => {
let expr = expr.skip_typecheck().normalize();
assert_eq_display!(expr, expected);
@@ -177,6 +198,7 @@ pub fn run_test(
e => panic!("Expected parse error, got: {:?}", e),
}
}
+ Printer | BinaryEncoding => unreachable!(),
Import => {
parse_file_str(&file_path)?.resolve().unwrap_err();
}