From 0b12932200bf49ee3784669a5496af1f7f83774b Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Fri, 21 Jun 2024 14:26:26 +0200 Subject: [PATCH 1/3] Deduplicate success and failure path --- src/status_emitter.rs | 102 +++++++++++++++++++----------------------- 1 file changed, 45 insertions(+), 57 deletions(-) diff --git a/src/status_emitter.rs b/src/status_emitter.rs index 41d05cb..56ca57b 100644 --- a/src/status_emitter.rs +++ b/src/status_emitter.rs @@ -421,7 +421,7 @@ impl StatusEmitter for Text { fn finalize( &self, - failures: usize, + _failures: usize, succeeded: usize, ignored: usize, filtered: usize, @@ -436,49 +436,37 @@ impl StatusEmitter for Text { println!(); } // Print all errors in a single thread to show reliable output - if failures == 0 { - println!(); - print!("test result: {}.", "ok".green()); - if succeeded > 0 { - print!(" {} passed;", succeeded.to_string().green()); - } - if ignored > 0 { - print!(" {} ignored;", ignored.to_string().yellow()); - } - if filtered > 0 { - print!(" {} filtered out;", filtered.to_string().yellow()); - } - println!(); - println!(); - Box::new(()) - } else { - struct Summarizer { - failures: Vec, - succeeded: usize, - ignored: usize, - filtered: usize, - } - - impl Summary for Summarizer { - fn test_failure(&mut self, status: &dyn TestStatus, errors: &Errors) { - for error in errors { - print_error(error, status.path()); - } + struct Summarizer { + failures: Vec, + succeeded: usize, + ignored: usize, + filtered: usize, + } - self.failures.push(if status.revision().is_empty() { - format!(" {}", display(status.path())) - } else { - format!( - " {} (revision {})", - display(status.path()), - status.revision() - ) - }); + impl Summary for Summarizer { + fn test_failure(&mut self, status: &dyn TestStatus, errors: &Errors) { + for error in errors { + print_error(error, status.path()); } + + self.failures.push(if status.revision().is_empty() { + format!(" {}", display(status.path())) + } else { + format!( + " {} (revision {})", + display(status.path()), + status.revision() + ) + }); } + } - impl Drop for Summarizer { - fn drop(&mut self) { + impl Drop for Summarizer { + fn drop(&mut self) { + if self.failures.is_empty() { + println!(); + print!("test result: {}.", "ok".green()); + } else { println!("{}", "FAILURES:".bright_red().underline().bold()); for line in &self.failures { println!("{line}"); @@ -486,26 +474,26 @@ impl StatusEmitter for Text { println!(); print!("test result: {}.", "FAIL".bright_red()); print!(" {} failed;", self.failures.len().to_string().green()); - if self.succeeded > 0 { - print!(" {} passed;", self.succeeded.to_string().green()); - } - if self.ignored > 0 { - print!(" {} ignored;", self.ignored.to_string().yellow()); - } - if self.filtered > 0 { - print!(" {} filtered out;", self.filtered.to_string().yellow()); - } - println!(); - println!(); } + if self.succeeded > 0 { + print!(" {} passed;", self.succeeded.to_string().green()); + } + if self.ignored > 0 { + print!(" {} ignored;", self.ignored.to_string().yellow()); + } + if self.filtered > 0 { + print!(" {} filtered out;", self.filtered.to_string().yellow()); + } + println!(); + println!(); } - Box::new(Summarizer { - failures: vec![], - succeeded, - ignored, - filtered, - }) } + Box::new(Summarizer { + failures: vec![], + succeeded, + ignored, + filtered, + }) } } From 5547d8fe95b5c03eac11d263b0346831d46269a3 Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Fri, 21 Jun 2024 14:31:15 +0200 Subject: [PATCH 2/3] Avoid extraneous semicolons --- src/status_emitter.rs | 17 +++++++++++++---- tests/integrations/basic-fail-mode/Cargo.stdout | 2 +- tests/integrations/basic-fail/Cargo.stdout | 10 +++++----- tests/integrations/basic/Cargo.stdout | 2 +- tests/integrations/cargo-run/Cargo.stdout | 2 +- tests/integrations/dep-fail/Cargo.stdout | 2 +- tests/integrations/ui_test_dep_bug/Cargo.stdout | 2 +- 7 files changed, 23 insertions(+), 14 deletions(-) diff --git a/src/status_emitter.rs b/src/status_emitter.rs index 56ca57b..f3e30d2 100644 --- a/src/status_emitter.rs +++ b/src/status_emitter.rs @@ -473,16 +473,25 @@ impl StatusEmitter for Text { } println!(); print!("test result: {}.", "FAIL".bright_red()); - print!(" {} failed;", self.failures.len().to_string().green()); + print!(" {} failed", self.failures.len().to_string().green()); + if self.succeeded > 0 || self.ignored > 0 || self.filtered > 0 { + print!(";"); + } } if self.succeeded > 0 { - print!(" {} passed;", self.succeeded.to_string().green()); + print!(" {} passed", self.succeeded.to_string().green()); + if self.ignored > 0 || self.filtered > 0 { + print!(";"); + } } if self.ignored > 0 { - print!(" {} ignored;", self.ignored.to_string().yellow()); + print!(" {} ignored", self.ignored.to_string().yellow()); + if self.filtered > 0 { + print!(";"); + } } if self.filtered > 0 { - print!(" {} filtered out;", self.filtered.to_string().yellow()); + print!(" {} filtered out", self.filtered.to_string().yellow()); } println!(); println!(); diff --git a/tests/integrations/basic-fail-mode/Cargo.stdout b/tests/integrations/basic-fail-mode/Cargo.stdout index 69a90b2..15df52b 100644 --- a/tests/integrations/basic-fail-mode/Cargo.stdout +++ b/tests/integrations/basic-fail-mode/Cargo.stdout @@ -11,7 +11,7 @@ test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; fini Building dependencies ... ok tests/actual_tests/foomp.rs ... ok -test result: ok. 1 passed; +test result: ok. 1 passed running 0 tests diff --git a/tests/integrations/basic-fail/Cargo.stdout b/tests/integrations/basic-fail/Cargo.stdout index 39e6499..a27553f 100644 --- a/tests/integrations/basic-fail/Cargo.stdout +++ b/tests/integrations/basic-fail/Cargo.stdout @@ -452,7 +452,7 @@ FAILURES: tests/actual_tests/touching_above_below.rs tests/actual_tests/touching_above_below_chain.rs -test result: FAIL. 15 failed; 1 passed; +test result: FAIL. 15 failed; 1 passed Building dependencies ... ok tests/actual_tests_bless/abort.rs (revision `run`) ... FAILED @@ -1078,7 +1078,7 @@ FAILURES: tests/actual_tests_bless/unknown_revision2.rs tests/actual_tests_bless/wrong_diagnostic_code.rs -test result: FAIL. 23 failed; 24 passed; 3 ignored; +test result: FAIL. 23 failed; 24 passed; 3 ignored Building dependencies ... ok tests/actual_tests_bless_yolo/revisions_bad.rs (revision `foo`) ... ok @@ -1129,7 +1129,7 @@ full stdout: FAILURES: tests/actual_tests_bless_yolo/rustfix-multiple-fail.2.fixed -test result: FAIL. 1 failed; 7 passed; +test result: FAIL. 1 failed; 7 passed tests/actual_tests/bad_pattern.rs ... FAILED tests/actual_tests/executable.rs ... FAILED @@ -1475,7 +1475,7 @@ FAILURES: tests/actual_tests/touching_above_below.rs tests/actual_tests/touching_above_below_chain.rs -test result: FAIL. 15 failed; +test result: FAIL. 15 failed tests/actual_tests/bad_pattern.rs ... FAILED tests/actual_tests/executable.rs ... FAILED @@ -1707,7 +1707,7 @@ FAILURES: tests/actual_tests/touching_above_below.rs tests/actual_tests/touching_above_below_chain.rs -test result: FAIL. 15 failed; +test result: FAIL. 15 failed running 0 tests diff --git a/tests/integrations/basic/Cargo.stdout b/tests/integrations/basic/Cargo.stdout index 3a17343..cdd35c3 100644 --- a/tests/integrations/basic/Cargo.stdout +++ b/tests/integrations/basic/Cargo.stdout @@ -44,7 +44,7 @@ tests/actual_tests/unicode.rs ... ok tests/actual_tests/windows_paths.rs ... ok tests/actual_tests/subdir/aux_proc_macro.rs ... ok -test result: ok. 31 passed; +test result: ok. 31 passed running 0 tests diff --git a/tests/integrations/cargo-run/Cargo.stdout b/tests/integrations/cargo-run/Cargo.stdout index daf5a3f..d803003 100644 --- a/tests/integrations/cargo-run/Cargo.stdout +++ b/tests/integrations/cargo-run/Cargo.stdout @@ -8,5 +8,5 @@ tests/actual_tests/matching_stdin.rs ... ok tests/actual_tests/mismatching_stdin.rs ... ok tests/actual_tests/no_stdin.rs ... ok -test result: ok. 4 passed; +test result: ok. 4 passed diff --git a/tests/integrations/dep-fail/Cargo.stdout b/tests/integrations/dep-fail/Cargo.stdout index 66532d6..c053179 100644 --- a/tests/integrations/dep-fail/Cargo.stdout +++ b/tests/integrations/dep-fail/Cargo.stdout @@ -31,7 +31,7 @@ BuildFinished { success: false } FAILURES: tests/ui/basic_test.rs -test result: FAIL. 1 failed; +test result: FAIL. 1 failed running 0 tests diff --git a/tests/integrations/ui_test_dep_bug/Cargo.stdout b/tests/integrations/ui_test_dep_bug/Cargo.stdout index 2e8471b..990abfa 100644 --- a/tests/integrations/ui_test_dep_bug/Cargo.stdout +++ b/tests/integrations/ui_test_dep_bug/Cargo.stdout @@ -6,7 +6,7 @@ test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; fini Building dependencies ... ok tests/ui/basic_test.rs ... ok -test result: ok. 1 passed; +test result: ok. 1 passed running 0 tests From 4055b973d6cf33db055aebfe51d5c00cc0bae6f0 Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Fri, 2 Aug 2024 12:53:59 +0200 Subject: [PATCH 3/3] Also run bin tests under windows now that that works --- tests/integration.rs | 6 +----- tests/integrations/basic-bin/Cargo.stdout | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/tests/integration.rs b/tests/integration.rs index 0c50926..c74eede 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -6,7 +6,7 @@ fn main() -> Result<()> { let path = Path::new(file!()).parent().unwrap(); let root_dir = path.join("integrations"); let mut config = Config { - bless_command: Some("cargo test".to_string()), + bless_command: Some("cargo test -- -- --bless".to_string()), ..Config::cargo(root_dir.clone()) }; @@ -113,10 +113,6 @@ fn main() -> Result<()> { .to_str() .unwrap() .ends_with("-fail"); - if cfg!(windows) && path.components().any(|c| c.as_os_str() == "basic-bin") { - // on windows there's also a .pdb file, so we get additional errors that aren't there on other platforms - return Some(false); - } if !path.ends_with("Cargo.toml") { return None; } diff --git a/tests/integrations/basic-bin/Cargo.stdout b/tests/integrations/basic-bin/Cargo.stdout index 6140d16..058d804 100644 --- a/tests/integrations/basic-bin/Cargo.stdout +++ b/tests/integrations/basic-bin/Cargo.stdout @@ -6,5 +6,5 @@ test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; fini Building dependencies ... ok tests/actual_tests/foomp.rs ... ok -test result: ok. 1 passed; +test result: ok. 1 passed