From 071b2a3f981b9d8c955c6460a92c5d06e114335f Mon Sep 17 00:00:00 2001 From: guipublic Date: Wed, 4 Dec 2024 10:43:56 +0000 Subject: [PATCH] code review --- tooling/nargo_cli/src/cli/test_cmd.rs | 51 ++++++++++++--------------- 1 file changed, 22 insertions(+), 29 deletions(-) diff --git a/tooling/nargo_cli/src/cli/test_cmd.rs b/tooling/nargo_cli/src/cli/test_cmd.rs index 20c80543e9c..c998b15b7dd 100644 --- a/tooling/nargo_cli/src/cli/test_cmd.rs +++ b/tooling/nargo_cli/src/cli/test_cmd.rs @@ -281,40 +281,33 @@ fn display_test_report( let plural_failed = if count_failed == 1 { "" } else { "s" }; let plural_passed = if count_passed == 1 { "" } else { "s" }; let plural_skipped = if count_skipped == 1 { "" } else { "s" }; - - if count_failed == 0 { + let mut previous = false; + if count_passed > 0 { writer.set_color(ColorSpec::new().set_fg(Some(Color::Green))).expect("Failed to set color"); - write!(writer, "{count_passed} test{plural_passed} passed") + write!(writer, "{count_passed} test{plural_passed} passed",) .expect("Failed to write to stderr"); - if count_skipped > 0 { - writer - .set_color(ColorSpec::new().set_fg(Some(Color::Yellow))) - .expect("Failed to set color"); - write!(writer, ", {count_skipped} test{plural_skipped} skipped") - .expect("Failed to write to stderr"); - } - writer.reset().expect("Failed to reset writer"); - writeln!(writer).expect("Failed to write to stderr"); - } else { - if count_passed != 0 { - writer - .set_color(ColorSpec::new().set_fg(Some(Color::Green))) - .expect("Failed to set color"); - write!(writer, "{count_passed} test{plural_passed} passed, ",) - .expect("Failed to write to stderr"); - } - if count_skipped != 0 { - writer - .set_color(ColorSpec::new().set_fg(Some(Color::Yellow))) - .expect("Failed to set color"); - write!(writer, ", {count_skipped} test{plural_skipped} skipped") - .expect("Failed to write to stderr"); + previous = true; + } + if count_skipped > 0 { + writer + .set_color(ColorSpec::new().set_fg(Some(Color::Yellow))) + .expect("Failed to set color"); + if previous { + write!(writer, ", ").expect("Failed to write to stderr"); } + write!(writer, "{count_skipped} test{plural_skipped} skipped") + .expect("Failed to write to stderr"); + previous = true; + } + if count_failed > 0 { writer.set_color(ColorSpec::new().set_fg(Some(Color::Red))).expect("Failed to set color"); - writeln!(writer, "{count_failed} test{plural_failed} failed") + if previous { + write!(writer, ", ").expect("Failed to write to stderr"); + } + write!(writer, "{count_failed} test{plural_failed} failed") .expect("Failed to write to stderr"); - writer.reset().expect("Failed to reset writer"); } - + writeln!(writer).expect("Failed to write to stderr"); + writer.reset().expect("Failed to reset writer"); Ok(()) }