refactor: run_tests to avoid repetition.
This commit is contained in:
parent
e9d8e1d317
commit
db25ff3817
|
@ -483,7 +483,6 @@ impl Project {
|
|||
}
|
||||
|
||||
fn run_tests(&self, tests: Vec<Script>) {
|
||||
for test in tests {
|
||||
// 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 {
|
||||
|
@ -491,24 +490,25 @@ impl Project {
|
|||
cpu: i64::MAX,
|
||||
};
|
||||
|
||||
let result = test.program.eval(initial_budget);
|
||||
|
||||
match result {
|
||||
(Ok(..), remaining_budget, _) => {
|
||||
let fmt_tests = |is_passing: bool, test: Script, remaining_budget: ExBudget| -> String {
|
||||
let ExBudget { mem, cpu } = initial_budget - remaining_budget;
|
||||
format!(
|
||||
" [{}] [mem: {}, cpu: {}] {}::{}",
|
||||
if is_passing { "PASS" } else { "FAIL" },
|
||||
mem,
|
||||
cpu,
|
||||
test.module,
|
||||
test.name
|
||||
)
|
||||
};
|
||||
|
||||
println!(
|
||||
" [PASS] [mem: {}, cpu: {}] {}::{}",
|
||||
mem, cpu, test.module, test.name
|
||||
);
|
||||
for test in tests {
|
||||
match test.program.eval(initial_budget) {
|
||||
(Ok(..), remaining_budget, _) => {
|
||||
println!("{}", fmt_tests(true, test, remaining_budget));
|
||||
}
|
||||
(Err(_), remaining_budget, _) => {
|
||||
let ExBudget { mem, cpu } = initial_budget - remaining_budget;
|
||||
|
||||
println!(
|
||||
" [FAIL] [mem: {}, cpu: {}] {}::{}",
|
||||
mem, cpu, test.module, test.name
|
||||
);
|
||||
println!("{}", fmt_tests(false, test, remaining_budget));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue