refactor: run_tests to avoid repetition.

This commit is contained in:
KtorZ 2022-12-08 17:02:53 +01:00 committed by rvcas
parent e9d8e1d317
commit db25ff3817
No known key found for this signature in database
GPG Key ID: C09B64E263F7D68C
1 changed files with 22 additions and 22 deletions

View File

@ -483,7 +483,6 @@ impl Project {
} }
fn run_tests(&self, tests: Vec<Script>) { fn run_tests(&self, tests: Vec<Script>) {
for test in tests {
// TODO: in the future we probably just want to be able to // TODO: in the future we probably just want to be able to
// tell the machine to not explode on budget consumption. // tell the machine to not explode on budget consumption.
let initial_budget = ExBudget { let initial_budget = ExBudget {
@ -491,24 +490,25 @@ impl Project {
cpu: i64::MAX, cpu: i64::MAX,
}; };
let result = test.program.eval(initial_budget); let fmt_tests = |is_passing: bool, test: Script, remaining_budget: ExBudget| -> String {
match result {
(Ok(..), remaining_budget, _) => {
let ExBudget { mem, cpu } = initial_budget - remaining_budget; let ExBudget { mem, cpu } = initial_budget - remaining_budget;
format!(
" [{}] [mem: {}, cpu: {}] {}::{}",
if is_passing { "PASS" } else { "FAIL" },
mem,
cpu,
test.module,
test.name
)
};
println!( for test in tests {
" [PASS] [mem: {}, cpu: {}] {}::{}", match test.program.eval(initial_budget) {
mem, cpu, test.module, test.name (Ok(..), remaining_budget, _) => {
); println!("{}", fmt_tests(true, test, remaining_budget));
} }
(Err(_), remaining_budget, _) => { (Err(_), remaining_budget, _) => {
let ExBudget { mem, cpu } = initial_budget - remaining_budget; println!("{}", fmt_tests(false, test, remaining_budget));
println!(
" [FAIL] [mem: {}, cpu: {}] {}::{}",
mem, cpu, test.module, test.name
);
} }
} }
} }