refactor: run_tests to avoid repetition.
This commit is contained in:
parent
e9d8e1d317
commit
db25ff3817
|
@ -483,32 +483,32 @@ impl Project {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_tests(&self, tests: Vec<Script>) {
|
fn run_tests(&self, tests: Vec<Script>) {
|
||||||
|
// 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 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
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
for test in tests {
|
for test in tests {
|
||||||
// TODO: in the future we probably just want to be able to
|
match test.program.eval(initial_budget) {
|
||||||
// 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(..), remaining_budget, _) => {
|
(Ok(..), remaining_budget, _) => {
|
||||||
let ExBudget { mem, cpu } = initial_budget - remaining_budget;
|
println!("{}", fmt_tests(true, test, remaining_budget));
|
||||||
|
|
||||||
println!(
|
|
||||||
" [PASS] [mem: {}, cpu: {}] {}::{}",
|
|
||||||
mem, cpu, test.module, test.name
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
(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
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue