Skip to content

Commit 962957f

Browse files
committed
make it possible to test more of ui_test
1 parent 4d80880 commit 962957f

File tree

2 files changed

+37
-12
lines changed

2 files changed

+37
-12
lines changed

ui_test/src/lib.rs

+28-6
Original file line numberDiff line numberDiff line change
@@ -235,11 +235,34 @@ fn run_test(
235235
}
236236
let output = miri.output().expect("could not execute miri");
237237
let mut errors = config.mode.ok(output.status);
238+
check_test_result(
239+
path,
240+
config,
241+
target,
242+
revision,
243+
comments,
244+
&mut errors,
245+
&output.stdout,
246+
&output.stderr,
247+
);
248+
(miri, errors)
249+
}
250+
251+
fn check_test_result(
252+
path: &Path,
253+
config: &Config,
254+
target: &str,
255+
revision: &str,
256+
comments: &Comments,
257+
errors: &mut Errors,
258+
stdout: &[u8],
259+
stderr: &[u8],
260+
) {
238261
// Always remove annotation comments from stderr.
239262
let annotations = Regex::new(r"\s*//~.*").unwrap();
240-
let stderr = std::str::from_utf8(&output.stderr).unwrap();
263+
let stderr = std::str::from_utf8(stderr).unwrap();
241264
let stderr = annotations.replace_all(stderr, "");
242-
let stdout = std::str::from_utf8(&output.stdout).unwrap();
265+
let stdout = std::str::from_utf8(stdout).unwrap();
243266
// Check output files (if any)
244267
let revised = |extension: &str| {
245268
if revision.is_empty() {
@@ -252,7 +275,7 @@ fn run_test(
252275
check_output(
253276
&stderr,
254277
path,
255-
&mut errors,
278+
errors,
256279
revised("stderr"),
257280
target,
258281
&config.stderr_filters,
@@ -262,16 +285,15 @@ fn run_test(
262285
check_output(
263286
&stdout,
264287
path,
265-
&mut errors,
288+
errors,
266289
revised("stdout"),
267290
target,
268291
&config.stdout_filters,
269292
&config,
270293
comments,
271294
);
272295
// Check error annotations in the source against output
273-
check_annotations(&stderr, &mut errors, config, revision, comments);
274-
(miri, errors)
296+
check_annotations(&stderr, errors, config, revision, comments);
275297
}
276298

277299
fn check_annotations(

ui_test/src/tests.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
use std::path::{Path, PathBuf};
22

3-
use super::{check_annotations, Comments, Config, Error, Mode, OutputConflictHandling};
3+
use super::*;
44

55
fn config() -> Config {
66
Config {
77
args: vec![],
88
target: None,
99
stderr_filters: vec![],
1010
stdout_filters: vec![],
11-
root_dir: PathBuf::from("."),
11+
root_dir: PathBuf::from("$RUSTROOT"),
1212
mode: Mode::Fail,
1313
path_filter: vec![],
1414
program: PathBuf::from("cake"),
@@ -25,10 +25,12 @@ fn main() {
2525
let _x: &i32 = unsafe { mem::transmute(16usize) }; //~ ERROR encountered a dangling reference (address $HEX is unallocated)
2626
}
2727
";
28-
let comments = Comments::parse(Path::new("<dummy>"), s);
28+
let path = Path::new("$DIR/<dummy>");
29+
let comments = Comments::parse(&path, s);
2930
let mut errors = vec![];
3031
let config = config();
31-
let unnormalized_stderr = r"
32+
// Crucially, the intended error string *does* appear in this output, as a quote of the comment itself.
33+
let stderr = br"
3234
error: Undefined Behavior: type validation failed: encountered a dangling reference (address 0x10 is unallocated)
3335
--> tests/compile-fail/validity/dangling_ref1.rs:6:29
3436
|
@@ -42,9 +44,10 @@ LL | let _x: &i32 = unsafe { mem::transmute(16usize) }; //~ ERROR encountere
4244
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
4345
error: aborting due to previous error
4446
";
45-
check_annotations(unnormalized_stderr, &mut errors, &config, "", &comments);
47+
check_test_result(&path, &config, "", "", &comments, &mut errors, /*stdout*/ br"", stderr);
48+
// The "OutputDiffers" is because we cannot open the .rs file
4649
match &errors[..] {
47-
[Error::PatternNotFound { .. }] => {}
50+
[Error::OutputDiffers { .. }, Error::PatternNotFound { .. }] => {}
4851
_ => panic!("not the expected error: {:#?}", errors),
4952
}
5053
}

0 commit comments

Comments
 (0)