Improve behavior and reporting of tests expected to fail

Fixes #786.
This commit is contained in:
KtorZ 2024-01-19 18:18:44 +01:00
parent 94f9fa9cab
commit 8a90e9eda0
No known key found for this signature in database
GPG Key ID: 33173CB6F77F4277
8 changed files with 96 additions and 14 deletions

View File

@ -10,6 +10,7 @@
### Fixed ### Fixed
- **aiken-lang**: Fix flat encoding and decoding of large integer values. @KtorZ - **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 ### Removed

View File

@ -821,6 +821,7 @@ where
bin_op, bin_op,
left, left,
right, right,
can_error: *can_error,
} }
}); });

View File

@ -43,6 +43,7 @@ pub struct EvalHint {
pub bin_op: BinOp, pub bin_op: BinOp,
pub left: Program<NamedDeBruijn>, pub left: Program<NamedDeBruijn>,
pub right: Program<NamedDeBruijn>, pub right: Program<NamedDeBruijn>,
pub can_error: bool,
} }
impl Display for EvalHint { impl Display for EvalHint {
@ -66,20 +67,42 @@ impl Display for EvalHint {
Err(err) => format!("{err}"), Err(err) => format!("{err}"),
}, },
); );
let msg = match self.bin_op { let msg = if self.can_error {
BinOp::And => Some(format!("{left}\n\nand\n\n{right}\n\nshould both be true.")), match self.bin_op {
BinOp::Or => Some(format!("{left}\n\nor\n\n{right}\n\nshould be true.")), BinOp::And => Some(format!(
BinOp::Eq => Some(format!("{left}\n\nshould be equal to\n\n{right}")), "{left}\n\nand\n\n{right}\n\nare both true but shouldn't."
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::Or => Some(format!(
BinOp::LtEqInt => Some(format!( "neither\n\n{left}\n\nnor\n\n{right}\n\nshould be true."
"{left}\n\nshould be lower than or equal to\n\n{right}" )),
)), BinOp::Eq => Some(format!("{left}\n\nshould not be equal to\n\n{right}")),
BinOp::GtEqInt => Some(format!("{left}\n\nshould be greater than\n\n{right}")), BinOp::NotEq => Some(format!("{left}\n\nshould be equal to\n\n{right}")),
BinOp::GtInt => Some(format!( BinOp::LtInt => Some(format!(
"{left}\n\nshould be greater than or equal to\n\n{right}" "{left}\n\nshould be greater than or equal to\n\n{right}"
)), )),
_ => None, 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)?; .ok_or(fmt::Error)?;

View File

@ -35,6 +35,7 @@ impl EvalResult {
pub fn failed(&self, can_error: bool) -> bool { pub fn failed(&self, can_error: bool) -> bool {
if can_error { if can_error {
self.result.is_ok() self.result.is_ok()
&& !matches!(self.result, Ok(Term::Constant(ref con)) if matches!(con.as_ref(), Constant::Bool(false)))
} else { } else {
self.result.is_err() self.result.is_err()
|| matches!(self.result, Ok(Term::Error)) || matches!(self.result, Ok(Term::Error))

View File

@ -0,0 +1,7 @@
# This file was generated by Aiken
# You typically do not need to edit this file
requirements = []
packages = []
[etags]

View File

@ -0,0 +1,2 @@
name = "aiken-lang/acceptance_test_091"
version = "0.0.0"

View File

@ -0,0 +1,8 @@
test foo_1() fail {
False
}
test foo_2() fail {
expect 14 == 42
True
}

View File

@ -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"
}
}
}