From 1228d88741cf2af635cdd392a629c87220518496 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Tue, 29 Aug 2023 10:48:05 +0000 Subject: [PATCH 1/9] Add regression test --- tests/integrations/basic-fail/Cargo.stderr | 3 ++- tests/integrations/basic-fail/Cargo.stdout | 15 +++++++++++++-- .../actual_tests_bless/aux_build_not_found.rs | 3 +++ 3 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 tests/integrations/basic-fail/tests/actual_tests_bless/aux_build_not_found.rs diff --git a/tests/integrations/basic-fail/Cargo.stderr b/tests/integrations/basic-fail/Cargo.stderr index 14a4f101..f21f2ba6 100644 --- a/tests/integrations/basic-fail/Cargo.stderr +++ b/tests/integrations/basic-fail/Cargo.stderr @@ -6,11 +6,12 @@ error: test failed, to rerun pass `--test ui_tests` Caused by: process didn't exit successfully: `$DIR/target/ui/debug/deps/ui_tests-HASH` (exit status: 1) +thread '' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "No such file or directory" }', $DIR/src/lib.rs:LL:CC +note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace thread 'main' panicked at 'invalid mode/result combo: yolo: Err(tests failed Location: $DIR/src/lib.rs:LL:CC)', tests/ui_tests_bless.rs:49:18 -note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace error: test failed, to rerun pass `--test ui_tests_bless` Error: failed to parse rustc version info: invalid_foobarlaksdfalsdfj diff --git a/tests/integrations/basic-fail/Cargo.stdout b/tests/integrations/basic-fail/Cargo.stdout index f1fa29b4..7eaadd20 100644 --- a/tests/integrations/basic-fail/Cargo.stdout +++ b/tests/integrations/basic-fail/Cargo.stdout @@ -223,8 +223,9 @@ FAILURES: test result: FAIL. 8 failed; -tests/actual_tests_bless/aux_proc_macro_misuse.rs ... FAILED Building dependencies ... ok +tests/actual_tests_bless/aux_build_not_found.rs ... FAILED +tests/actual_tests_bless/aux_proc_macro_misuse.rs ... FAILED Building aux file tests/actual_tests_bless/auxiliary/the_proc_macro.rs ... ok tests/actual_tests_bless/aux_proc_macro_no_main.rs ... FAILED tests/actual_tests_bless/compile_flags_quotes.rs ... FAILED @@ -263,6 +264,15 @@ tests/actual_tests_bless/rustfix-fail.rs ... FAILED tests/actual_tests_bless/unknown_revision.rs ... FAILED tests/actual_tests_bless/unknown_revision2.rs ... FAILED +tests/actual_tests_bless/aux_build_not_found.rs FAILED: +command: "" + +A bug in `ui_test` occurred: called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "No such file or directory" } + +full stderr: + + + tests/actual_tests_bless/aux_proc_macro_misuse.rs FAILED: command: "parse comments" @@ -616,6 +626,7 @@ full stderr: FAILURES: + tests/actual_tests_bless/aux_build_not_found.rs tests/actual_tests_bless/aux_proc_macro_misuse.rs tests/actual_tests_bless/aux_proc_macro_no_main.rs tests/actual_tests_bless/compile_flags_quotes.rs @@ -635,7 +646,7 @@ FAILURES: tests/actual_tests_bless/unknown_revision.rs tests/actual_tests_bless/unknown_revision2.rs -test result: FAIL. 18 failed; 14 passed; 3 ignored; +test result: FAIL. 19 failed; 14 passed; 3 ignored; Building dependencies ... ok tests/actual_tests_bless_yolo/revisions_bad.rs (foo) ... ok diff --git a/tests/integrations/basic-fail/tests/actual_tests_bless/aux_build_not_found.rs b/tests/integrations/basic-fail/tests/actual_tests_bless/aux_build_not_found.rs new file mode 100644 index 00000000..25ce3478 --- /dev/null +++ b/tests/integrations/basic-fail/tests/actual_tests_bless/aux_build_not_found.rs @@ -0,0 +1,3 @@ +//@aux-build:aasdflkjasdlfjasdlfkjasdf + +fn main() {} From 971469cbf79dd5a0ece8ec8e10ab4dd69875b637 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Tue, 29 Aug 2023 11:03:09 +0000 Subject: [PATCH 2/9] Don't crash ui_test on file not found errors --- src/lib.rs | 17 +++++++++++++++-- tests/integrations/basic-fail/Cargo.stderr | 3 +-- tests/integrations/basic-fail/Cargo.stdout | 6 ++---- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 13c97a05..0497a474 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -476,7 +476,11 @@ fn build_aux( config: &Config, build_manager: &BuildManager<'_>, ) -> std::result::Result, Errored> { - let file_contents = std::fs::read(aux_file).unwrap(); + let file_contents = std::fs::read(aux_file).map_err(|err| Errored { + command: Command::new(format!("reading aux file `{}`", aux_file.display())), + errors: vec![], + stderr: err.to_string().into_bytes(), + })?; let comments = parse_comments(&file_contents)?; assert_eq!( comments.revisions, None, @@ -648,7 +652,16 @@ fn build_aux_files( .build( Build::Aux { aux_file: config - .strip_path_prefix(&aux_file.canonicalize().unwrap()) + .strip_path_prefix(&aux_file.canonicalize().map_err(|err| { + Errored { + command: Command::new(format!( + "canonicalizing path `{}`", + aux_file.display() + )), + errors: vec![], + stderr: err.to_string().into_bytes(), + } + })?) .collect(), }, config, diff --git a/tests/integrations/basic-fail/Cargo.stderr b/tests/integrations/basic-fail/Cargo.stderr index f21f2ba6..14a4f101 100644 --- a/tests/integrations/basic-fail/Cargo.stderr +++ b/tests/integrations/basic-fail/Cargo.stderr @@ -6,12 +6,11 @@ error: test failed, to rerun pass `--test ui_tests` Caused by: process didn't exit successfully: `$DIR/target/ui/debug/deps/ui_tests-HASH` (exit status: 1) -thread '' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "No such file or directory" }', $DIR/src/lib.rs:LL:CC -note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace thread 'main' panicked at 'invalid mode/result combo: yolo: Err(tests failed Location: $DIR/src/lib.rs:LL:CC)', tests/ui_tests_bless.rs:49:18 +note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace error: test failed, to rerun pass `--test ui_tests_bless` Error: failed to parse rustc version info: invalid_foobarlaksdfalsdfj diff --git a/tests/integrations/basic-fail/Cargo.stdout b/tests/integrations/basic-fail/Cargo.stdout index 7eaadd20..48abb8af 100644 --- a/tests/integrations/basic-fail/Cargo.stdout +++ b/tests/integrations/basic-fail/Cargo.stdout @@ -265,12 +265,10 @@ tests/actual_tests_bless/unknown_revision.rs ... FAILED tests/actual_tests_bless/unknown_revision2.rs ... FAILED tests/actual_tests_bless/aux_build_not_found.rs FAILED: -command: "" - -A bug in `ui_test` occurred: called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "No such file or directory" } +command: "$CMD" full stderr: - +No such file or directory tests/actual_tests_bless/aux_proc_macro_misuse.rs FAILED: From 7b351a65f9a4de3a0451fc1ea5edad97d7a80875 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Tue, 29 Aug 2023 12:25:11 +0000 Subject: [PATCH 3/9] Canonicalize aux build paths relative to the current directory. Otherwise, within the rustc repo, we get an aux build path relative to the repository root, which we then can't resolve to the actual aux file --- src/config.rs | 26 +------------------------- src/lib.rs | 49 +++++++++++++++++++++++++++++++++++-------------- 2 files changed, 36 insertions(+), 39 deletions(-) diff --git a/src/config.rs b/src/config.rs index 01c3069e..ab9d0fa5 100644 --- a/src/config.rs +++ b/src/config.rs @@ -5,7 +5,7 @@ pub use color_eyre; use color_eyre::eyre::Result; use std::{ ffi::OsString, - path::{Component, Path, PathBuf, Prefix}, + path::{Path, PathBuf}, }; mod args; @@ -218,30 +218,6 @@ impl Config { .iter() .any(|arch| self.target.as_ref().unwrap().contains(arch)) } - - /// Remove the common prefix of this path and the `root_dir`. - pub(crate) fn strip_path_prefix<'a>( - &self, - path: &'a Path, - ) -> impl Iterator> { - let mut components = path.components(); - for c in self.out_dir.components() { - let deverbatimize = |c| match c { - Component::Prefix(prefix) => Err(match prefix.kind() { - Prefix::VerbatimUNC(a, b) => Prefix::UNC(a, b), - Prefix::VerbatimDisk(d) => Prefix::Disk(d), - other => other, - }), - c => Ok(c), - }; - let c2 = components.next(); - if Some(deverbatimize(c)) == c2.map(deverbatimize) { - continue; - } - return c2.into_iter().chain(components); - } - None.into_iter().chain(components) - } } #[derive(Debug, Clone)] diff --git a/src/lib.rs b/src/lib.rs index 0497a474..eb7ef123 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -22,7 +22,7 @@ use std::borrow::Cow; use std::collections::{HashSet, VecDeque}; use std::ffi::OsString; use std::num::NonZeroUsize; -use std::path::{Path, PathBuf}; +use std::path::{Component, Path, PathBuf, Prefix}; use std::process::{Command, ExitStatus}; use std::thread; @@ -513,7 +513,7 @@ fn build_aux( // Put aux builds into a separate directory per path so that multiple aux files // from different directories (but with the same file name) don't collide. - let relative = config.strip_path_prefix(aux_file.parent().unwrap()); + let relative = strip_path_prefix(aux_file.parent().unwrap(), &config.out_dir); config.out_dir.extend(relative); @@ -651,18 +651,18 @@ fn build_aux_files( build_manager .build( Build::Aux { - aux_file: config - .strip_path_prefix(&aux_file.canonicalize().map_err(|err| { - Errored { - command: Command::new(format!( - "canonicalizing path `{}`", - aux_file.display() - )), - errors: vec![], - stderr: err.to_string().into_bytes(), - } - })?) - .collect(), + aux_file: strip_path_prefix( + &aux_file.canonicalize().map_err(|err| Errored { + command: Command::new(format!( + "canonicalizing path `{}`", + aux_file.display() + )), + errors: vec![], + stderr: err.to_string().into_bytes(), + })?, + &std::env::current_dir().unwrap(), + ) + .collect(), }, config, ) @@ -1215,3 +1215,24 @@ fn normalize( } text } +/// Remove the common prefix of this path and the `root_dir`. +fn strip_path_prefix<'a>(path: &'a Path, prefix: &Path) -> impl Iterator> { + let mut components = path.components(); + for c in prefix.components() { + // Windows has some funky paths. This is probably wrong, but works well in practice. + let deverbatimize = |c| match c { + Component::Prefix(prefix) => Err(match prefix.kind() { + Prefix::VerbatimUNC(a, b) => Prefix::UNC(a, b), + Prefix::VerbatimDisk(d) => Prefix::Disk(d), + other => other, + }), + c => Ok(c), + }; + let c2 = components.next(); + if Some(deverbatimize(c)) == c2.map(deverbatimize) { + continue; + } + return c2.into_iter().chain(components); + } + None.into_iter().chain(components) +} From ef4e998f260da0b475e7a7bfd4d55dff72992d99 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Tue, 29 Aug 2023 12:25:48 +0000 Subject: [PATCH 4/9] Version bump --- Cargo.lock | 2 +- Cargo.toml | 2 +- tests/integrations/basic-bin/Cargo.lock | 2 +- tests/integrations/basic-fail-mode/Cargo.lock | 2 +- tests/integrations/basic-fail/Cargo.lock | 2 +- tests/integrations/basic/Cargo.lock | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9b168be3..3045e1c3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -651,7 +651,7 @@ dependencies = [ [[package]] name = "ui_test" -version = "0.17.0" +version = "0.18.0" dependencies = [ "annotate-snippets", "anyhow", diff --git a/Cargo.toml b/Cargo.toml index 70be1259..2f19b056 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ui_test" -version = "0.17.0" +version = "0.18.0" edition = "2021" license = "MIT OR Apache-2.0" description = "A test framework for testing rustc diagnostics output" diff --git a/tests/integrations/basic-bin/Cargo.lock b/tests/integrations/basic-bin/Cargo.lock index ce8654f0..0677d3c4 100644 --- a/tests/integrations/basic-bin/Cargo.lock +++ b/tests/integrations/basic-bin/Cargo.lock @@ -697,7 +697,7 @@ dependencies = [ [[package]] name = "ui_test" -version = "0.17.0" +version = "0.18.0" dependencies = [ "annotate-snippets", "anyhow", diff --git a/tests/integrations/basic-fail-mode/Cargo.lock b/tests/integrations/basic-fail-mode/Cargo.lock index e17a7424..1cf5896c 100644 --- a/tests/integrations/basic-fail-mode/Cargo.lock +++ b/tests/integrations/basic-fail-mode/Cargo.lock @@ -697,7 +697,7 @@ dependencies = [ [[package]] name = "ui_test" -version = "0.17.0" +version = "0.18.0" dependencies = [ "annotate-snippets", "anyhow", diff --git a/tests/integrations/basic-fail/Cargo.lock b/tests/integrations/basic-fail/Cargo.lock index f340a4a2..fbb75007 100644 --- a/tests/integrations/basic-fail/Cargo.lock +++ b/tests/integrations/basic-fail/Cargo.lock @@ -697,7 +697,7 @@ dependencies = [ [[package]] name = "ui_test" -version = "0.17.0" +version = "0.18.0" dependencies = [ "annotate-snippets", "anyhow", diff --git a/tests/integrations/basic/Cargo.lock b/tests/integrations/basic/Cargo.lock index 7c234eb0..c36a8b8d 100644 --- a/tests/integrations/basic/Cargo.lock +++ b/tests/integrations/basic/Cargo.lock @@ -697,7 +697,7 @@ dependencies = [ [[package]] name = "ui_test" -version = "0.17.0" +version = "0.18.0" dependencies = [ "annotate-snippets", "anyhow", From e64b657246627ac39b0cff332a94590c6deb600c Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Tue, 29 Aug 2023 12:40:21 +0000 Subject: [PATCH 5/9] Windows io errors differ from linux ones --- tests/integration.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/integration.rs b/tests/integration.rs index caf1bc06..f26172ed 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -42,6 +42,10 @@ fn main() -> Result<()> { ); // Windows io::Error uses "exit code". config.filter("exit code", "exit status"); + config.filter( + "The system cannot find the file specified", + "No such file or directory", + ); // The order of the `/deps` directory flag is flaky config.stdout_filter("/deps", ""); config.path_filter(std::path::Path::new(path), "$DIR"); From be6861c36ea04829e1b48608c460f532e3e73c60 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Tue, 29 Aug 2023 12:43:22 +0000 Subject: [PATCH 6/9] Not everything is stderr --- src/status_emitter.rs | 9 ++++++++- tests/integrations/basic-fail/Cargo.stdout | 4 ++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/status_emitter.rs b/src/status_emitter.rs index 8e237294..6316ae3c 100644 --- a/src/status_emitter.rs +++ b/src/status_emitter.rs @@ -428,7 +428,14 @@ fn print_error(error: &Error, path: &Path) { output_path.display() ); println!("{}", format!("--- {}", output_path.display()).red()); - println!("{}", "+++ ".green()); + println!( + "{}", + format!( + "+++ <{} output>", + output_path.extension().unwrap().to_str().unwrap() + ) + .green() + ); crate::diff::print_diff(expected, actual); } Error::ErrorsWithoutPattern { path, msgs } => { diff --git a/tests/integrations/basic-fail/Cargo.stdout b/tests/integrations/basic-fail/Cargo.stdout index 48abb8af..b2b98b08 100644 --- a/tests/integrations/basic-fail/Cargo.stdout +++ b/tests/integrations/basic-fail/Cargo.stdout @@ -57,7 +57,7 @@ command: "$CMD" actual output differed from expected Execute `DO NOT BLESS. These are meant to fail` to update `tests/actual_tests/executable.stdout` to the actual output --- tests/actual_tests/executable.stdout -+++ ++++ -69 +42 @@ -189,7 +189,7 @@ command: "$CMD" actual output differed from expected Execute `DO NOT BLESS. These are meant to fail` to update `tests/actual_tests/foomp2.fixed` to the actual output --- tests/actual_tests/foomp2.fixed -+++ ++++ -this is just a test file showing that -stray .fixed files are detected and blessed away From 0de9e43ea74b09e07af984fbe1f78f8982c7bf96 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Tue, 29 Aug 2023 12:51:02 +0000 Subject: [PATCH 7/9] Emit stdout, too --- src/dependencies.rs | 5 ++ src/lib.rs | 27 ++++++-- src/parser.rs | 1 + src/status_emitter.rs | 48 +++++++++++---- tests/integrations/basic-fail/Cargo.stdout | 72 ++++++++++++++++++++++ 5 files changed, 138 insertions(+), 15 deletions(-) diff --git a/src/dependencies.rs b/src/dependencies.rs index 61bdbb95..0e95e0f8 100644 --- a/src/dependencies.rs +++ b/src/dependencies.rs @@ -244,6 +244,7 @@ impl<'a> BuildManager<'a> { command: Command::new(format!("{what:?}")), errors: vec![], stderr: b"previous build failed".to_vec(), + stdout: vec![], }); } let mut lock = self.cache.write().unwrap(); @@ -254,6 +255,7 @@ impl<'a> BuildManager<'a> { command: Command::new(format!("{what:?}")), errors: vec![], stderr: b"previous build failed".to_vec(), + stdout: vec![], }); } entry.get().clone() @@ -280,6 +282,7 @@ impl<'a> BuildManager<'a> { command: Command::new(format!("{what:?}")), errors: vec![], stderr: format!("{e:?}").into_bytes(), + stdout: vec![], }); Err(()) } @@ -299,6 +302,7 @@ impl<'a> BuildManager<'a> { command: Command::new(what.description()), errors: vec![], stderr: vec![], + stdout: vec![], }), ); res @@ -309,6 +313,7 @@ impl<'a> BuildManager<'a> { command: Command::new(what.description()), errors: vec![], stderr: b"previous build failed".to_vec(), + stdout: vec![], }) }) } diff --git a/src/lib.rs b/src/lib.rs index eb7ef123..8e1ce153 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -205,6 +205,8 @@ pub struct Errored { errors: Vec, /// The full stderr of the test run. stderr: Vec, + /// The full stdout of the test run. + stdout: Vec, } struct TestRun { @@ -290,6 +292,7 @@ pub fn run_tests_generic( .unwrap(), )], stderr: vec![], + stdout: vec![], }), status, })?; @@ -332,10 +335,11 @@ pub fn run_tests_generic( command, errors, stderr, + stdout, }, ) in &failures { - let _guard = status.failed_test(command, stderr); + let _guard = status.failed_test(command, stderr, stdout); failure_emitter.test_failure(status, errors); } @@ -434,6 +438,7 @@ fn parse_comments(file_contents: &[u8]) -> Result { command: Command::new("parse comments"), errors, stderr: vec![], + stdout: vec![], }), } } @@ -480,6 +485,7 @@ fn build_aux( command: Command::new(format!("reading aux file `{}`", aux_file.display())), errors: vec![], stderr: err.to_string().into_bytes(), + stdout: vec![], })?; let comments = parse_comments(&file_contents)?; assert_eq!( @@ -541,6 +547,7 @@ fn build_aux( command: aux_cmd, errors: vec![error], stderr: rustc_stderr::process(aux_file, &output.stderr).rendered, + stdout: output.stdout, }); } @@ -605,14 +612,17 @@ impl dyn TestStatus { "test panicked: stderr:\n{stderr}\nstdout:\n{stdout}", ))], stderr: vec![], + stdout: vec![], }); } } } check_test_result( - cmd, *mode, path, config, revision, comments, status, stdout, &stderr, + cmd, *mode, path, config, revision, comments, status, &stdout, &stderr, + )?; + run_rustfix( + &stderr, &stdout, path, comments, revision, config, *mode, extra_args, )?; - run_rustfix(&stderr, path, comments, revision, config, *mode, extra_args)?; Ok(TestOk::Ok) } @@ -659,6 +669,7 @@ fn build_aux_files( )), errors: vec![], stderr: err.to_string().into_bytes(), + stdout: vec![], })?, &std::env::current_dir().unwrap(), ) @@ -671,6 +682,7 @@ fn build_aux_files( command, errors, stderr, + stdout, }| Errored { command, errors: vec![Error::Aux { @@ -679,6 +691,7 @@ fn build_aux_files( line, }], stderr, + stdout, }, )?, ); @@ -727,12 +740,14 @@ fn run_test_binary( command: exe, errors, stderr: vec![], + stdout: vec![], }) } } fn run_rustfix( stderr: &[u8], + stdout: &[u8], path: &Path, comments: &Comments, revision: &str, @@ -786,6 +801,7 @@ fn run_rustfix( command: Command::new(format!("rustfix {}", path.display())), errors: vec![Error::Rustfix(err)], stderr: stderr.into(), + stdout: stdout.into(), })?; let edition = comments.edition(revision, config)?; @@ -849,6 +865,7 @@ fn run_rustfix( command: Command::new(format!("checking {}", path.display())), errors, stderr: vec![], + stdout: vec![], }); } @@ -877,6 +894,7 @@ fn run_rustfix( status: output.status, }], stderr: rustc_stderr::process(&rustfix_path, &output.stderr).rendered, + stdout: output.stdout, }) } } @@ -897,7 +915,7 @@ fn check_test_result( revision: &str, comments: &Comments, status: ExitStatus, - stdout: Vec, + stdout: &[u8], stderr: &[u8], ) -> Result<(), Errored> { let mut errors = vec![]; @@ -930,6 +948,7 @@ fn check_test_result( command, errors, stderr: diagnostics.rendered, + stdout: stdout.into(), }) } } diff --git a/src/parser.rs b/src/parser.rs index 52094587..badb55a4 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -64,6 +64,7 @@ impl Comments { lines: errors, }], stderr: vec![], + stdout: vec![], }) } } diff --git a/src/status_emitter.rs b/src/status_emitter.rs index 6316ae3c..5c67defe 100644 --- a/src/status_emitter.rs +++ b/src/status_emitter.rs @@ -51,7 +51,12 @@ pub trait TestStatus: Send + Sync + RefUnwindSafe { /// Invoked before each failed test prints its errors along with a drop guard that can /// gets invoked afterwards. - fn failed_test<'a>(&'a self, cmd: &'a Command, stderr: &'a [u8]) -> Box; + fn failed_test<'a>( + &'a self, + cmd: &'a Command, + stderr: &'a [u8], + stdout: &'a [u8], + ) -> Box; /// Change the status of the test while it is running to supply some kind of progress fn update_status(&self, msg: String); @@ -223,7 +228,12 @@ impl TestStatus for TextTest { self.text.sender.send(Msg::Status(self.msg(), msg)).unwrap(); } - fn failed_test<'a>(&self, cmd: &Command, stderr: &'a [u8]) -> Box { + fn failed_test<'a>( + &self, + cmd: &Command, + stderr: &'a [u8], + stdout: &'a [u8], + ) -> Box { println!(); let path = self.path.display().to_string(); print!("{}", path.underline().bold()); @@ -239,16 +249,22 @@ impl TestStatus for TextTest { println!(); #[derive(Debug)] - struct Guard<'a>(&'a [u8]); + struct Guard<'a> { + stderr: &'a [u8], + stdout: &'a [u8], + } impl<'a> Drop for Guard<'a> { fn drop(&mut self) { println!("full stderr:"); - std::io::stdout().write_all(self.0).unwrap(); + std::io::stdout().write_all(self.stderr).unwrap(); + println!(); + println!("full stdout:"); + std::io::stdout().write_all(self.stdout).unwrap(); println!(); println!(); } } - Box::new(Guard(stderr)) + Box::new(Guard { stderr, stdout }) } fn path(&self) -> &Path { @@ -746,7 +762,7 @@ impl TestStatus for PathAndRev { }) } - fn failed_test(&self, _cmd: &Command, _stderr: &[u8]) -> Box { + fn failed_test(&self, _cmd: &Command, _stderr: &[u8], _stdout: &[u8]) -> Box { if GROUP { Box::new(github_actions::group(format_args!( "{}:{}", @@ -841,10 +857,15 @@ impl TestStatus for (T, U) { self.1.done(result); } - fn failed_test<'a>(&'a self, cmd: &'a Command, stderr: &'a [u8]) -> Box { + fn failed_test<'a>( + &'a self, + cmd: &'a Command, + stderr: &'a [u8], + stdout: &'a [u8], + ) -> Box { Box::new(( - self.0.failed_test(cmd, stderr), - self.1.failed_test(cmd, stderr), + self.0.failed_test(cmd, stderr, stdout), + self.1.failed_test(cmd, stderr, stdout), )) } @@ -909,8 +930,13 @@ impl TestStatus for Box { (**self).for_revision(revision) } - fn failed_test<'a>(&'a self, cmd: &'a Command, stderr: &'a [u8]) -> Box { - (**self).failed_test(cmd, stderr) + fn failed_test<'a>( + &'a self, + cmd: &'a Command, + stderr: &'a [u8], + stdout: &'a [u8], + ) -> Box { + (**self).failed_test(cmd, stderr, stdout) } fn update_status(&self, msg: String) { diff --git a/tests/integrations/basic-fail/Cargo.stdout b/tests/integrations/basic-fail/Cargo.stdout index b2b98b08..94a15db5 100644 --- a/tests/integrations/basic-fail/Cargo.stdout +++ b/tests/integrations/basic-fail/Cargo.stdout @@ -49,6 +49,8 @@ error: aborting due to previous error For more information about this error, try `rustc --explain E0308`. +full stdout: + tests/actual_tests/executable.rs FAILED: @@ -64,6 +66,8 @@ Execute `DO NOT BLESS. These are meant to fail` to update `tests/actual_tests/ex full stderr: +full stdout: + tests/actual_tests/executable_compile_err.rs FAILED: @@ -106,6 +110,8 @@ error: this file contains an unclosed delimiter error: aborting due to previous error +full stdout: + tests/actual_tests/exit_code_fail.rs FAILED: @@ -117,6 +123,8 @@ no error patterns found in fail test full stderr: +full stdout: + tests/actual_tests/filters.rs FAILED: @@ -131,6 +139,8 @@ error: `x86_64` is not a valid condition, expected `on-host`, /[0-9]+bit/, /host full stderr: +full stdout: + tests/actual_tests/foomp.rs FAILED: @@ -181,6 +191,8 @@ error: aborting due to previous error For more information about this error, try `rustc --explain E0308`. +full stdout: + tests/actual_tests/foomp2.rs FAILED: @@ -196,6 +208,8 @@ Execute `DO NOT BLESS. These are meant to fail` to update `tests/actual_tests/fo full stderr: +full stdout: + tests/actual_tests/pattern_too_many_arrow.rs FAILED: @@ -210,6 +224,8 @@ error: //~^ pattern is trying to refer to 7 lines above, but there are only 2 li full stderr: +full stdout: + FAILURES: tests/actual_tests/bad_pattern.rs @@ -269,6 +285,8 @@ command: "$CMD" full stderr: No such file or directory +full stdout: + tests/actual_tests_bless/aux_proc_macro_misuse.rs FAILED: @@ -283,6 +301,8 @@ error: proc macros are now auto-detected, you can remove the `:proc-macro` after full stderr: +full stdout: + tests/actual_tests_bless/aux_proc_macro_no_main.rs FAILED: @@ -307,6 +327,8 @@ error: expected one of `!` or `::`, found `` error: aborting due to previous error +full stdout: + tests/actual_tests_bless/compile_flags_quotes.rs FAILED: @@ -328,6 +350,8 @@ error: `-Z "cheese is good` contains an unclosed quotation mark full stderr: +full stdout: + tests/actual_tests_bless/compiletest-rs-command.rs FAILED: @@ -362,6 +386,8 @@ The `//` must be directly followed by `@` or `~`. full stderr: +full stdout: + tests/actual_tests_bless/failing_executable.rs FAILED: @@ -371,6 +397,8 @@ run(0) test got exit status: 101, but expected 0 full stderr: +full stdout: + tests/actual_tests_bless/no_main.rs FAILED: @@ -382,6 +410,8 @@ no error patterns found in fail test full stderr: +full stdout: + tests/actual_tests_bless/no_main_manual.rs FAILED: @@ -412,6 +442,8 @@ error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0601`. +full stdout: + tests/actual_tests_bless/no_test.rs FAILED: @@ -423,6 +455,8 @@ no error patterns found in fail test full stderr: +full stdout: + tests/actual_tests_bless/non_top_level_configs.rs FAILED: @@ -448,6 +482,8 @@ The `//` must be directly followed by `@` or `~`. full stderr: +full stdout: + tests/actual_tests_bless/revised_revision.rs FAILED: @@ -462,6 +498,8 @@ error: revisions cannot be declared under a revision full stderr: +full stdout: + tests/actual_tests_bless/revisioned_executable.rs (revision `panic`) FAILED: @@ -471,6 +509,8 @@ run(101) test got exit status: 0, but expected 101 full stderr: +full stdout: + tests/actual_tests_bless/revisioned_executable_panic.rs (revision `run`) FAILED: @@ -480,6 +520,8 @@ run(0) test got exit status: 101, but expected 0 full stderr: +full stdout: + tests/actual_tests_bless/revisions_bad.rs (revision `bar`) FAILED: @@ -510,6 +552,8 @@ error: aborting due to previous error For more information about this error, try `rustc --explain E0601`. +full stdout: + tests/actual_tests_bless/rustfix-fail-revisions.rs (revision `a`) FAILED: @@ -538,6 +582,8 @@ error: aborting due to previous error For more information about this error, try `rustc --explain E0382`. +full stdout: + tests/actual_tests_bless/rustfix-fail-revisions.rs (revision `b`) FAILED: @@ -566,6 +612,8 @@ error: aborting due to previous error For more information about this error, try `rustc --explain E0382`. +full stdout: + tests/actual_tests_bless/rustfix-fail.rs FAILED: @@ -594,6 +642,8 @@ error: aborting due to previous error For more information about this error, try `rustc --explain E0382`. +full stdout: + tests/actual_tests_bless/unknown_revision.rs FAILED: @@ -608,6 +658,8 @@ error: there are no revisions in this test full stderr: +full stdout: + tests/actual_tests_bless/unknown_revision2.rs FAILED: @@ -622,6 +674,8 @@ error: the revision `cake` is not known full stderr: +full stdout: + FAILURES: tests/actual_tests_bless/aux_build_not_found.rs @@ -672,6 +726,8 @@ error: aborting due to previous error For more information about this error, try `rustc --explain E0601`. +full stdout: + FAILURES: tests/actual_tests_bless_yolo/revisions_bad.rs (revision bar) @@ -695,6 +751,8 @@ A bug in `ui_test` occurred: could not spawn `"invalid_foobarlaksdfalsdfj"` as a full stderr: +full stdout: + tests/actual_tests/executable.rs FAILED: @@ -704,6 +762,8 @@ A bug in `ui_test` occurred: could not spawn `"invalid_foobarlaksdfalsdfj"` as a full stderr: +full stdout: + tests/actual_tests/executable_compile_err.rs FAILED: @@ -713,6 +773,8 @@ A bug in `ui_test` occurred: could not spawn `"invalid_foobarlaksdfalsdfj"` as a full stderr: +full stdout: + tests/actual_tests/exit_code_fail.rs FAILED: @@ -722,6 +784,8 @@ A bug in `ui_test` occurred: could not spawn `"invalid_foobarlaksdfalsdfj"` as a full stderr: +full stdout: + tests/actual_tests/filters.rs FAILED: @@ -736,6 +800,8 @@ error: `x86_64` is not a valid condition, expected `on-host`, /[0-9]+bit/, /host full stderr: +full stdout: + tests/actual_tests/foomp.rs FAILED: @@ -745,6 +811,8 @@ A bug in `ui_test` occurred: could not spawn `"invalid_foobarlaksdfalsdfj"` as a full stderr: +full stdout: + tests/actual_tests/foomp2.rs FAILED: @@ -754,6 +822,8 @@ A bug in `ui_test` occurred: could not spawn `"invalid_foobarlaksdfalsdfj"` as a full stderr: +full stdout: + tests/actual_tests/pattern_too_many_arrow.rs FAILED: @@ -768,6 +838,8 @@ error: //~^ pattern is trying to refer to 7 lines above, but there are only 2 li full stderr: +full stdout: + FAILURES: tests/actual_tests/bad_pattern.rs From 29bc09ccb72edbcf448eb99e5deca11f84d580bb Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Tue, 29 Aug 2023 12:51:48 +0000 Subject: [PATCH 8/9] Windows nit --- tests/integration.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration.rs b/tests/integration.rs index f26172ed..14a49dab 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -43,7 +43,7 @@ fn main() -> Result<()> { // Windows io::Error uses "exit code". config.filter("exit code", "exit status"); config.filter( - "The system cannot find the file specified", + "The system cannot find the file specified.", "No such file or directory", ); // The order of the `/deps` directory flag is flaky From 02aadc4824b7c8e814b5a825ff7a16a04ca099ec Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Tue, 29 Aug 2023 12:52:26 +0000 Subject: [PATCH 9/9] clippy --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 8e1ce153..17295dda 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -928,7 +928,7 @@ fn check_test_result( revision, config, comments, - &stdout, + stdout, &diagnostics.rendered, ); // Check error annotations in the source against output