From 962957f11f456949395535037b45b98d18bbcf19 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 30 May 2022 12:56:34 +0200 Subject: [PATCH] make it possible to test more of ui_test --- ui_test/src/lib.rs | 34 ++++++++++++++++++++++++++++------ ui_test/src/tests.rs | 15 +++++++++------ 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/ui_test/src/lib.rs b/ui_test/src/lib.rs index 37af27dcfb1..6052efe02e0 100644 --- a/ui_test/src/lib.rs +++ b/ui_test/src/lib.rs @@ -235,11 +235,34 @@ fn run_test( } let output = miri.output().expect("could not execute miri"); let mut errors = config.mode.ok(output.status); + check_test_result( + path, + config, + target, + revision, + comments, + &mut errors, + &output.stdout, + &output.stderr, + ); + (miri, errors) +} + +fn check_test_result( + path: &Path, + config: &Config, + target: &str, + revision: &str, + comments: &Comments, + errors: &mut Errors, + stdout: &[u8], + stderr: &[u8], +) { // Always remove annotation comments from stderr. let annotations = Regex::new(r"\s*//~.*").unwrap(); - let stderr = std::str::from_utf8(&output.stderr).unwrap(); + let stderr = std::str::from_utf8(stderr).unwrap(); let stderr = annotations.replace_all(stderr, ""); - let stdout = std::str::from_utf8(&output.stdout).unwrap(); + let stdout = std::str::from_utf8(stdout).unwrap(); // Check output files (if any) let revised = |extension: &str| { if revision.is_empty() { @@ -252,7 +275,7 @@ fn run_test( check_output( &stderr, path, - &mut errors, + errors, revised("stderr"), target, &config.stderr_filters, @@ -262,7 +285,7 @@ fn run_test( check_output( &stdout, path, - &mut errors, + errors, revised("stdout"), target, &config.stdout_filters, @@ -270,8 +293,7 @@ fn run_test( comments, ); // Check error annotations in the source against output - check_annotations(&stderr, &mut errors, config, revision, comments); - (miri, errors) + check_annotations(&stderr, errors, config, revision, comments); } fn check_annotations( diff --git a/ui_test/src/tests.rs b/ui_test/src/tests.rs index 7b25eaeeafe..d0ef1195d88 100644 --- a/ui_test/src/tests.rs +++ b/ui_test/src/tests.rs @@ -1,6 +1,6 @@ use std::path::{Path, PathBuf}; -use super::{check_annotations, Comments, Config, Error, Mode, OutputConflictHandling}; +use super::*; fn config() -> Config { Config { @@ -8,7 +8,7 @@ fn config() -> Config { target: None, stderr_filters: vec![], stdout_filters: vec![], - root_dir: PathBuf::from("."), + root_dir: PathBuf::from("$RUSTROOT"), mode: Mode::Fail, path_filter: vec![], program: PathBuf::from("cake"), @@ -25,10 +25,12 @@ fn main() { let _x: &i32 = unsafe { mem::transmute(16usize) }; //~ ERROR encountered a dangling reference (address $HEX is unallocated) } "; - let comments = Comments::parse(Path::new(""), s); + let path = Path::new("$DIR/"); + let comments = Comments::parse(&path, s); let mut errors = vec![]; let config = config(); - let unnormalized_stderr = r" + // Crucially, the intended error string *does* appear in this output, as a quote of the comment itself. + let stderr = br" error: Undefined Behavior: type validation failed: encountered a dangling reference (address 0x10 is unallocated) --> tests/compile-fail/validity/dangling_ref1.rs:6:29 | @@ -42,9 +44,10 @@ fn main() { note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace error: aborting due to previous error "; - check_annotations(unnormalized_stderr, &mut errors, &config, "", &comments); + check_test_result(&path, &config, "", "", &comments, &mut errors, /*stdout*/ br"", stderr); + // The "OutputDiffers" is because we cannot open the .rs file match &errors[..] { - [Error::PatternNotFound { .. }] => {} + [Error::OutputDiffers { .. }, Error::PatternNotFound { .. }] => {} _ => panic!("not the expected error: {:#?}", errors), } }