mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 00:24:34 +00:00
refactor printing error counts
This commit is contained in:
parent
ea53a50447
commit
32e3f01a28
2 changed files with 33 additions and 33 deletions
|
@ -463,7 +463,7 @@ pub fn test(matches: &ArgMatches, triple: Triple) -> io::Result<i32> {
|
||||||
"if there were errors, we would have already exited."
|
"if there were errors, we would have already exited."
|
||||||
);
|
);
|
||||||
if problems.warnings > 0 {
|
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));
|
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.
|
// since the process is about to exit anyway.
|
||||||
// std::mem::forget(arena);
|
// std::mem::forget(arena);
|
||||||
|
|
||||||
print_problems(problems, total_time);
|
problems.print_to_stdout(total_time);
|
||||||
println!(" while successfully building:\n\n {generated_filename}");
|
println!(" while successfully building:\n\n {generated_filename}");
|
||||||
|
|
||||||
// Return a nonzero exit code if there were problems
|
// Return a nonzero exit code if there were problems
|
||||||
|
@ -716,7 +716,7 @@ pub fn build(
|
||||||
}
|
}
|
||||||
BuildAndRun => {
|
BuildAndRun => {
|
||||||
if problems.errors > 0 || problems.warnings > 0 {
|
if problems.errors > 0 || problems.warnings > 0 {
|
||||||
print_problems(problems, total_time);
|
problems.print_to_stdout(total_time);
|
||||||
println!(
|
println!(
|
||||||
".\n\nRunning program anyway…\n\n\x1B[36m{}\x1B[39m",
|
".\n\nRunning program anyway…\n\n\x1B[36m{}\x1B[39m",
|
||||||
"─".repeat(80)
|
"─".repeat(80)
|
||||||
|
@ -737,7 +737,7 @@ pub fn build(
|
||||||
"if there are errors, they should have been returned as an error variant"
|
"if there are errors, they should have been returned as an error variant"
|
||||||
);
|
);
|
||||||
if problems.warnings > 0 {
|
if problems.warnings > 0 {
|
||||||
print_problems(problems, total_time);
|
problems.print_to_stdout(total_time);
|
||||||
println!(
|
println!(
|
||||||
".\n\nRunning program…\n\n\x1B[36m{}\x1B[39m",
|
".\n\nRunning program…\n\n\x1B[36m{}\x1B[39m",
|
||||||
"─".repeat(80)
|
"─".repeat(80)
|
||||||
|
@ -771,7 +771,7 @@ fn handle_error_module(
|
||||||
|
|
||||||
let problems = roc_build::program::report_problems_typechecked(&mut 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 print_run_anyway_hint {
|
||||||
// If you're running "main.roc" then you can just do `roc run`
|
// 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>>(
|
fn roc_run<'a, I: IntoIterator<Item = &'a OsStr>>(
|
||||||
arena: &Bump,
|
arena: &Bump,
|
||||||
opt_level: OptLevel,
|
opt_level: OptLevel,
|
||||||
|
|
|
@ -20,6 +20,34 @@ impl Problems {
|
||||||
self.warnings.min(1) as i32
|
self.warnings.min(1) as i32
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn print_to_stdout(&self, 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 self.errors {
|
||||||
|
0 => GREEN,
|
||||||
|
_ => YELLOW,
|
||||||
|
},
|
||||||
|
self.errors,
|
||||||
|
match self.errors {
|
||||||
|
1 => "error",
|
||||||
|
_ => "errors",
|
||||||
|
},
|
||||||
|
match self.warnings {
|
||||||
|
0 => GREEN,
|
||||||
|
_ => YELLOW,
|
||||||
|
},
|
||||||
|
self.warnings,
|
||||||
|
match self.warnings {
|
||||||
|
1 => "warning",
|
||||||
|
_ => "warnings",
|
||||||
|
},
|
||||||
|
total_time.as_millis(),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn report_problems(
|
pub fn report_problems(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue