feat: print budget consumed by test

This commit is contained in:
rvcas 2022-12-08 10:57:13 -05:00
parent 141a9aef30
commit e9d8e1d317
No known key found for this signature in database
GPG Key ID: C09B64E263F7D68C
3 changed files with 29 additions and 9 deletions

View File

@ -293,7 +293,7 @@ impl Diagnostic for Warning {
fn code<'a>(&'a self) -> Option<Box<dyn Display + 'a>> {
match self {
Warning::Type { .. } => Some(Box::new("aiken::typecheck")),
Warning::Type { .. } => Some(Box::new("aiken::check")),
}
}
}

View File

@ -25,7 +25,10 @@ use pallas::{
use pallas_traverse::ComputeHash;
use script::Script;
use serde_json::json;
use uplc::ast::{DeBruijn, Program};
use uplc::{
ast::{DeBruijn, Program},
machine::cost_model::ExBudget,
};
use crate::{
config::Config,
@ -481,14 +484,31 @@ impl Project {
fn run_tests(&self, tests: Vec<Script>) {
for test in tests {
let result = test.program.eval();
// TODO: in the future we probably just want to be able to
// tell the machine to not explode on budget consumption.
let initial_budget = ExBudget {
mem: i64::MAX,
cpu: i64::MAX,
};
let result = test.program.eval(initial_budget);
match result {
(Ok(..), _, _) => {
println!("{}::{}", test.module, test.name);
(Ok(..), remaining_budget, _) => {
let ExBudget { mem, cpu } = initial_budget - remaining_budget;
println!(
" [PASS] [mem: {}, cpu: {}] {}::{}",
mem, cpu, test.module, test.name
);
}
(Err(e), _, _) => {
println!("{}::{} x", test.module, test.name);
println!("{}", e);
(Err(_), remaining_budget, _) => {
let ExBudget { mem, cpu } = initial_budget - remaining_budget;
println!(
" [FAIL] [mem: {}, cpu: {}] {}::{}",
mem, cpu, test.module, test.name
);
}
}
}

View File

@ -1,7 +1,7 @@
use sample
pub fn spend(datum: sample.Datum, rdmr: sample.Redeemer, _ctx: Nil) -> Bool {
let x = #(datum, #[244])
let _x = #(datum, rdmr, #[244])
let y = [#(#[222], #[222]), #(#[233], #[52])]