Show trace logs as part of the test output when any.
``` ┍━ test ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ │ PASS [mem: 6370, cpu: 2591822] trace_1 │ ↳ is negative │ ↳ is non-negative ┕━━━━━━━━━ 1 tests | 1 passed | 0 failed ```
This commit is contained in:
parent
2fc14c7c1f
commit
9068c89c00
|
@ -171,6 +171,7 @@ fn fmt_test(eval_info: &EvalInfo, max_mem: usize, max_cpu: usize, styled: bool)
|
|||
success,
|
||||
script,
|
||||
spent_budget,
|
||||
logs,
|
||||
..
|
||||
} = eval_info;
|
||||
|
||||
|
@ -178,17 +179,38 @@ fn fmt_test(eval_info: &EvalInfo, max_mem: usize, max_cpu: usize, styled: bool)
|
|||
let mem_pad = pretty::pad_left(mem.to_string(), max_mem, " ");
|
||||
let cpu_pad = pretty::pad_left(cpu.to_string(), max_cpu, " ");
|
||||
|
||||
format!(
|
||||
"{} [mem: {}, cpu: {}] {}",
|
||||
if *success {
|
||||
let test = format!(
|
||||
"{status} [mem: {mem_unit}, cpu: {cpu_unit}] {module}",
|
||||
status = if *success {
|
||||
pretty::style_if(styled, "PASS".to_string(), |s| s.bold().green().to_string())
|
||||
} else {
|
||||
pretty::style_if(styled, "FAIL".to_string(), |s| s.bold().red().to_string())
|
||||
},
|
||||
pretty::style_if(styled, mem_pad, |s| s.bright_white().to_string()),
|
||||
pretty::style_if(styled, cpu_pad, |s| s.bright_white().to_string()),
|
||||
pretty::style_if(styled, script.name.clone(), |s| s.bright_blue().to_string()),
|
||||
)
|
||||
mem_unit = pretty::style_if(styled, mem_pad, |s| s.bright_white().to_string()),
|
||||
cpu_unit = pretty::style_if(styled, cpu_pad, |s| s.bright_white().to_string()),
|
||||
module = pretty::style_if(styled, script.name.clone(), |s| s.bright_blue().to_string()),
|
||||
);
|
||||
|
||||
let logs = if logs.is_empty() {
|
||||
String::new()
|
||||
} else {
|
||||
logs.iter()
|
||||
.map(|line| {
|
||||
format!(
|
||||
"{arrow} {styled_line}",
|
||||
arrow = "↳".bright_yellow(),
|
||||
styled_line = line.bright_black()
|
||||
)
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n")
|
||||
};
|
||||
|
||||
if logs.is_empty() {
|
||||
test
|
||||
} else {
|
||||
[test, logs].join("\n")
|
||||
}
|
||||
}
|
||||
|
||||
fn fmt_test_summary(tests: &Vec<&EvalInfo>, styled: bool) -> String {
|
||||
|
|
|
@ -714,23 +714,25 @@ where
|
|||
}
|
||||
|
||||
match script.program.eval(initial_budget) {
|
||||
(Ok(result), remaining_budget, _) => {
|
||||
(Ok(result), remaining_budget, logs) => {
|
||||
let eval_info = EvalInfo {
|
||||
success: result != Term::Error
|
||||
&& result != Term::Constant(Constant::Bool(false)),
|
||||
script,
|
||||
spent_budget: initial_budget - remaining_budget,
|
||||
output: Some(result),
|
||||
logs,
|
||||
};
|
||||
|
||||
results.push(eval_info);
|
||||
}
|
||||
(Err(..), remaining_budget, _) => {
|
||||
(Err(..), remaining_budget, logs) => {
|
||||
let eval_info = EvalInfo {
|
||||
success: false,
|
||||
script,
|
||||
spent_budget: initial_budget - remaining_budget,
|
||||
output: None,
|
||||
logs,
|
||||
};
|
||||
|
||||
results.push(eval_info);
|
||||
|
|
|
@ -43,4 +43,5 @@ pub struct EvalInfo {
|
|||
pub script: Script,
|
||||
pub spent_budget: ExBudget,
|
||||
pub output: Option<Term<NamedDeBruijn>>,
|
||||
pub logs: Vec<String>,
|
||||
}
|
||||
|
|
|
@ -1,5 +1,14 @@
|
|||
use aiken/builtin
|
||||
|
||||
test trace_1() {
|
||||
builtin.trace("foo", True)
|
||||
fn is_negative(i : Int) -> Bool {
|
||||
if i < 0 {
|
||||
builtin.trace("is negative", True)
|
||||
} else {
|
||||
builtin.trace("is non-negative", False)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
test trace_1() {
|
||||
is_negative(-14) && !is_negative(42)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue