-
Notifications
You must be signed in to change notification settings - Fork 180
/
pretty_printing.rs
61 lines (51 loc) · 2.17 KB
/
pretty_printing.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
use crate::test_case_summary::TestCaseSummary;
use crate::TestFileSummary;
use anyhow::Error;
use camino::Utf8PathBuf;
use console::style;
pub fn print_error_message(error: &Error) {
let error_tag = style("ERROR").red();
println!("[{error_tag}] {error}");
}
pub(crate) fn print_collected_tests_count(tests_num: usize, tests_files_num: usize) {
let plain_text = format!("Collected {tests_num} test(s) and {tests_files_num} test file(s)");
println!("{}", style(plain_text).bold());
}
pub(crate) fn print_running_tests(test_file: &Utf8PathBuf, package_name: &str, tests_num: usize) {
let plain_text = if test_file == "src/lib.cairo" {
format!("Running {tests_num} test(s) from {package_name} package")
} else {
format!("Running {tests_num} test(s) from {test_file}")
};
println!("{}", style(plain_text).bold());
}
pub(crate) fn print_test_summary(summaries: &[TestFileSummary]) {
let passed: usize = summaries.iter().map(TestFileSummary::count_passed).sum();
let skipped: usize = summaries.iter().map(TestFileSummary::count_skipped).sum();
let failed: usize = summaries.iter().map(TestFileSummary::count_failed).sum();
println!(
"{}: {} passed, {} failed, {} skipped",
style("Tests").bold(),
passed,
failed,
skipped,
);
}
pub(crate) fn print_test_result(test_result: &TestCaseSummary) {
let result_header = match test_result {
TestCaseSummary::Passed { .. } => format!("[{}]", style("PASS").green()),
TestCaseSummary::Failed { .. } => format!("[{}]", style("FAIL").red()),
TestCaseSummary::Skipped { .. } => format!("[{}]", style("SKIP").yellow()),
};
let result_name = match test_result {
TestCaseSummary::Skipped { name }
| TestCaseSummary::Failed { name, .. }
| TestCaseSummary::Passed { name, .. } => name,
};
let result_message = match test_result {
TestCaseSummary::Passed { msg: Some(msg), .. } => format!("\n\nSuccess data:{msg}"),
TestCaseSummary::Failed { msg: Some(msg), .. } => format!("\n\nFailure data:{msg}"),
_ => String::new(),
};
println!("{result_header} {result_name}{result_message}");
}