Skip to content

Commit 80bf204

Browse files
committed
don't configure the same regex twice
1 parent b9d79a2 commit 80bf204

File tree

3 files changed

+12
-14
lines changed

3 files changed

+12
-14
lines changed

tests/compiletest.rs

-2
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,6 @@ regexes! {
106106
r"\\" => "/",
107107
// erase platform file paths
108108
"sys/[a-z]+/" => "sys/PLATFORM/",
109-
// erase error annotations in tests
110-
r"\s*//~.*" => "",
111109
}
112110

113111
fn ui(mode: Mode, path: &str) {

ui_test/src/lib.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,11 @@ fn run_test(
231231
}
232232
let output = miri.output().expect("could not execute miri");
233233
let mut errors = config.mode.ok(output.status);
234+
// Always remove annotation comments from stderr.
235+
let annotations = Regex::new(r"\s*//~.*").unwrap();
236+
let stderr = std::str::from_utf8(&output.stderr).unwrap();
237+
let stderr = annotations.replace_all(stderr, "");
238+
let stdout = std::str::from_utf8(&output.stdout).unwrap();
234239
// Check output files (if any)
235240
let revised = |extension: &str| {
236241
if revision.is_empty() {
@@ -241,7 +246,7 @@ fn run_test(
241246
};
242247
// Check output files against actual output
243248
check_output(
244-
&output.stderr,
249+
&stderr,
245250
path,
246251
&mut errors,
247252
revised("stderr"),
@@ -251,7 +256,7 @@ fn run_test(
251256
comments,
252257
);
253258
check_output(
254-
&output.stdout,
259+
&stdout,
255260
path,
256261
&mut errors,
257262
revised("stdout"),
@@ -261,21 +266,17 @@ fn run_test(
261266
comments,
262267
);
263268
// Check error annotations in the source against output
264-
check_annotations(&output.stderr, &mut errors, config, revision, comments);
269+
check_annotations(&stderr, &mut errors, config, revision, comments);
265270
(miri, errors)
266271
}
267272

268273
fn check_annotations(
269-
unnormalized_stderr: &[u8],
274+
unnormalized_stderr: &str,
270275
errors: &mut Errors,
271276
config: &Config,
272277
revision: &str,
273278
comments: &Comments,
274279
) {
275-
let unnormalized_stderr = std::str::from_utf8(unnormalized_stderr).unwrap();
276-
// erase annotations from the stderr so they don't match themselves
277-
let annotations = Regex::new(r"\s*//~.*").unwrap();
278-
let unnormalized_stderr = annotations.replace(unnormalized_stderr, "");
279280
let mut found_annotation = false;
280281
if let Some((ref error_pattern, definition_line)) = comments.error_pattern {
281282
if !unnormalized_stderr.contains(error_pattern) {
@@ -313,7 +314,7 @@ fn check_annotations(
313314
}
314315

315316
fn check_output(
316-
output: &[u8],
317+
output: &str,
317318
path: &Path,
318319
errors: &mut Errors,
319320
kind: String,
@@ -322,7 +323,6 @@ fn check_output(
322323
config: &Config,
323324
comments: &Comments,
324325
) {
325-
let output = std::str::from_utf8(&output).unwrap();
326326
let output = normalize(path, output, filters, comments);
327327
let path = output_path(path, comments, kind, target);
328328
match config.output_conflict_handling {

ui_test/src/tests.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ LL | let _x: &i32 = unsafe { mem::transmute(16usize) }; //~ ERROR encountere
4242
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
4343
error: aborting due to previous error
4444
";
45-
check_annotations(unnormalized_stderr.as_bytes(), &mut errors, &config, "", &comments);
45+
check_annotations(unnormalized_stderr, &mut errors, &config, "", &comments);
4646
match &errors[..] {
4747
[Error::PatternNotFound { .. }] => {}
48-
_ => panic!("{:#?}", errors),
48+
_ => panic!("not the expected error: {:#?}", errors),
4949
}
5050
}

0 commit comments

Comments
 (0)