refactor printing error counts

This commit is contained in:
Folkert 2022-12-23 17:15:39 +01:00
parent ea53a50447
commit 32e3f01a28
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C
2 changed files with 33 additions and 33 deletions

View file

@ -463,7 +463,7 @@ pub fn test(matches: &ArgMatches, triple: Triple) -> io::Result<i32> {
"if there were errors, we would have already exited."
);
if problems.warnings > 0 {
print_problems(problems, start_time.elapsed());
problems.print_to_stdout(start_time.elapsed());
println!(".\n\nRunning tests…\n\n\x1B[36m{}\x1B[39m", "".repeat(80));
}
}
@ -708,7 +708,7 @@ pub fn build(
// since the process is about to exit anyway.
// std::mem::forget(arena);
print_problems(problems, total_time);
problems.print_to_stdout(total_time);
println!(" while successfully building:\n\n {generated_filename}");
// Return a nonzero exit code if there were problems
@ -716,7 +716,7 @@ pub fn build(
}
BuildAndRun => {
if problems.errors > 0 || problems.warnings > 0 {
print_problems(problems, total_time);
problems.print_to_stdout(total_time);
println!(
".\n\nRunning program anyway…\n\n\x1B[36m{}\x1B[39m",
"".repeat(80)
@ -737,7 +737,7 @@ pub fn build(
"if there are errors, they should have been returned as an error variant"
);
if problems.warnings > 0 {
print_problems(problems, total_time);
problems.print_to_stdout(total_time);
println!(
".\n\nRunning program…\n\n\x1B[36m{}\x1B[39m",
"".repeat(80)
@ -771,7 +771,7 @@ fn handle_error_module(
let problems = roc_build::program::report_problems_typechecked(&mut module);
print_problems(problems, total_time);
problems.print_to_stdout(total_time);
if print_run_anyway_hint {
// If you're running "main.roc" then you can just do `roc run`
@ -803,34 +803,6 @@ fn handle_loading_problem(problem: LoadingProblem) -> io::Result<i32> {
}
}
fn print_problems(problems: Problems, total_time: std::time::Duration) {
const GREEN: usize = 32;
const YELLOW: usize = 33;
print!(
"\x1B[{}m{}\x1B[39m {} and \x1B[{}m{}\x1B[39m {} found in {} ms",
match problems.errors {
0 => GREEN,
_ => YELLOW,
},
problems.errors,
match problems.errors {
1 => "error",
_ => "errors",
},
match problems.warnings {
0 => GREEN,
_ => YELLOW,
},
problems.warnings,
match problems.warnings {
1 => "warning",
_ => "warnings",
},
total_time.as_millis(),
);
}
fn roc_run<'a, I: IntoIterator<Item = &'a OsStr>>(
arena: &Bump,
opt_level: OptLevel,