From 8a90e9eda0465025bbc8910ef8534e700f008f7a Mon Sep 17 00:00:00 2001 From: KtorZ Date: Fri, 19 Jan 2024 18:18:44 +0100 Subject: [PATCH] Improve behavior and reporting of tests expected to fail Fixes #786. --- CHANGELOG.md | 1 + crates/aiken-project/src/lib.rs | 1 + crates/aiken-project/src/script.rs | 51 ++++++++++++++++------- crates/uplc/src/machine/eval_result.rs | 1 + examples/acceptance_tests/091/aiken.lock | 7 ++++ examples/acceptance_tests/091/aiken.toml | 2 + examples/acceptance_tests/091/lib/foo.ak | 8 ++++ examples/acceptance_tests/091/plutus.json | 39 +++++++++++++++++ 8 files changed, 96 insertions(+), 14 deletions(-) create mode 100644 examples/acceptance_tests/091/aiken.lock create mode 100644 examples/acceptance_tests/091/aiken.toml create mode 100644 examples/acceptance_tests/091/lib/foo.ak create mode 100644 examples/acceptance_tests/091/plutus.json diff --git a/CHANGELOG.md b/CHANGELOG.md index 05f81514..3f91db35 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ ### Fixed - **aiken-lang**: Fix flat encoding and decoding of large integer values. @KtorZ +- **aiken**: Ensures that test expected to fail that return `False` are considered to pass & improve error reporting when they fail. @KtorZ ### Removed diff --git a/crates/aiken-project/src/lib.rs b/crates/aiken-project/src/lib.rs index f6f74ff9..88470075 100644 --- a/crates/aiken-project/src/lib.rs +++ b/crates/aiken-project/src/lib.rs @@ -821,6 +821,7 @@ where bin_op, left, right, + can_error: *can_error, } }); diff --git a/crates/aiken-project/src/script.rs b/crates/aiken-project/src/script.rs index 9aa4d28d..4493c897 100644 --- a/crates/aiken-project/src/script.rs +++ b/crates/aiken-project/src/script.rs @@ -43,6 +43,7 @@ pub struct EvalHint { pub bin_op: BinOp, pub left: Program, pub right: Program, + pub can_error: bool, } impl Display for EvalHint { @@ -66,20 +67,42 @@ impl Display for EvalHint { Err(err) => format!("{err}"), }, ); - let msg = match self.bin_op { - BinOp::And => Some(format!("{left}\n\nand\n\n{right}\n\nshould both be true.")), - BinOp::Or => Some(format!("{left}\n\nor\n\n{right}\n\nshould be true.")), - BinOp::Eq => Some(format!("{left}\n\nshould be equal to\n\n{right}")), - BinOp::NotEq => Some(format!("{left}\n\nshould not be equal to\n\n{right}")), - BinOp::LtInt => Some(format!("{left}\n\nshould be lower than\n\n{right}")), - BinOp::LtEqInt => Some(format!( - "{left}\n\nshould be lower than or equal to\n\n{right}" - )), - BinOp::GtEqInt => Some(format!("{left}\n\nshould be greater than\n\n{right}")), - BinOp::GtInt => Some(format!( - "{left}\n\nshould be greater than or equal to\n\n{right}" - )), - _ => None, + let msg = if self.can_error { + match self.bin_op { + BinOp::And => Some(format!( + "{left}\n\nand\n\n{right}\n\nare both true but shouldn't." + )), + BinOp::Or => Some(format!( + "neither\n\n{left}\n\nnor\n\n{right}\n\nshould be true." + )), + BinOp::Eq => Some(format!("{left}\n\nshould not be equal to\n\n{right}")), + BinOp::NotEq => Some(format!("{left}\n\nshould be equal to\n\n{right}")), + BinOp::LtInt => Some(format!( + "{left}\n\nshould be greater than or equal to\n\n{right}" + )), + BinOp::LtEqInt => Some(format!("{left}\n\nshould be greater than\n\n{right}")), + BinOp::GtEqInt => Some(format!( + "{left}\n\nshould be lower than or equal\n\n{right}" + )), + BinOp::GtInt => Some(format!("{left}\n\nshould be lower than\n\n{right}")), + _ => None, + } + } else { + match self.bin_op { + BinOp::And => Some(format!("{left}\n\nand\n\n{right}\n\nshould both be true.")), + BinOp::Or => Some(format!("{left}\n\nor\n\n{right}\n\nshould be true.")), + BinOp::Eq => Some(format!("{left}\n\nshould be equal to\n\n{right}")), + BinOp::NotEq => Some(format!("{left}\n\nshould not be equal to\n\n{right}")), + BinOp::LtInt => Some(format!("{left}\n\nshould be lower than\n\n{right}")), + BinOp::LtEqInt => Some(format!( + "{left}\n\nshould be lower than or equal to\n\n{right}" + )), + BinOp::GtEqInt => Some(format!("{left}\n\nshould be greater than\n\n{right}")), + BinOp::GtInt => Some(format!( + "{left}\n\nshould be greater than or equal to\n\n{right}" + )), + _ => None, + } } .ok_or(fmt::Error)?; diff --git a/crates/uplc/src/machine/eval_result.rs b/crates/uplc/src/machine/eval_result.rs index 2841e564..5156c726 100644 --- a/crates/uplc/src/machine/eval_result.rs +++ b/crates/uplc/src/machine/eval_result.rs @@ -35,6 +35,7 @@ impl EvalResult { pub fn failed(&self, can_error: bool) -> bool { if can_error { self.result.is_ok() + && !matches!(self.result, Ok(Term::Constant(ref con)) if matches!(con.as_ref(), Constant::Bool(false))) } else { self.result.is_err() || matches!(self.result, Ok(Term::Error)) diff --git a/examples/acceptance_tests/091/aiken.lock b/examples/acceptance_tests/091/aiken.lock new file mode 100644 index 00000000..6e350cda --- /dev/null +++ b/examples/acceptance_tests/091/aiken.lock @@ -0,0 +1,7 @@ +# This file was generated by Aiken +# You typically do not need to edit this file + +requirements = [] +packages = [] + +[etags] diff --git a/examples/acceptance_tests/091/aiken.toml b/examples/acceptance_tests/091/aiken.toml new file mode 100644 index 00000000..b69dbfe6 --- /dev/null +++ b/examples/acceptance_tests/091/aiken.toml @@ -0,0 +1,2 @@ +name = "aiken-lang/acceptance_test_091" +version = "0.0.0" diff --git a/examples/acceptance_tests/091/lib/foo.ak b/examples/acceptance_tests/091/lib/foo.ak new file mode 100644 index 00000000..a101f5bb --- /dev/null +++ b/examples/acceptance_tests/091/lib/foo.ak @@ -0,0 +1,8 @@ +test foo_1() fail { + False +} + +test foo_2() fail { + expect 14 == 42 + True +} diff --git a/examples/acceptance_tests/091/plutus.json b/examples/acceptance_tests/091/plutus.json new file mode 100644 index 00000000..a6a24507 --- /dev/null +++ b/examples/acceptance_tests/091/plutus.json @@ -0,0 +1,39 @@ +{ + "preamble": { + "title": "aiken-lang/acceptance_test_090", + "version": "0.0.0", + "plutusVersion": "v2", + "compiler": { + "name": "Aiken", + "version": "v1.0.21-alpha+9f263c4" + } + }, + "validators": [ + { + "title": "foo.spend", + "datum": { + "title": "datum", + "schema": { + "$ref": "#/definitions/Int" + } + }, + "redeemer": { + "title": "_redeemer", + "schema": { + "$ref": "#/definitions/Data" + } + }, + "compiledCode": "583f010000322223253330053370e00290487777c9cfdde5c8f27bf4c1637fc55b5eeef7d8c4d9e0d4454967ff7d6e7ee6e242eb60c6318a4c26cac6eb400d5cd1", + "hash": "d18aa035514acb988a34d33fc246420c5b0eca4f3f947ce95e294447" + } + ], + "definitions": { + "Data": { + "title": "Data", + "description": "Any Plutus data." + }, + "Int": { + "dataType": "integer" + } + } +} \ No newline at end of file