Skip to content

Commit aa19b41

Browse files
committed
make pretty printer tests understand revisions, and make them ignore the
should-fail annotation
1 parent 9601e6f commit aa19b41

File tree

2 files changed

+32
-20
lines changed

2 files changed

+32
-20
lines changed

src/compiletest/compiletest.rs

+14-5
Original file line numberDiff line numberDiff line change
@@ -355,15 +355,24 @@ pub fn is_test(config: &Config, testfile: &Path) -> bool {
355355

356356
pub fn make_test(config: &Config, testpaths: &TestPaths) -> test::TestDescAndFn {
357357
let early_props = header::early_props(config, &testpaths.file);
358+
359+
// The `should-fail` annotation doesn't apply to pretty tests,
360+
// since we run the pretty printer across all tests by default.
361+
// If desired, we could add a `should-fail-pretty` annotation.
362+
let should_panic = match config.mode {
363+
Pretty => test::ShouldPanic::No,
364+
_ => if early_props.should_fail {
365+
test::ShouldPanic::Yes
366+
} else {
367+
test::ShouldPanic::No
368+
}
369+
};
370+
358371
test::TestDescAndFn {
359372
desc: test::TestDesc {
360373
name: make_test_name(config, testpaths),
361374
ignore: early_props.ignore,
362-
should_panic: if early_props.should_fail {
363-
test::ShouldPanic::Yes
364-
} else {
365-
test::ShouldPanic::No
366-
},
375+
should_panic: should_panic,
367376
},
368377
testfn: make_test_closure(config, testpaths),
369378
}

src/compiletest/runtest.rs

+18-15
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,13 @@ fn run_valgrind_test(config: &Config, props: &TestProps, testpaths: &TestPaths)
213213
}
214214

215215
fn run_pretty_test(config: &Config, props: &TestProps, testpaths: &TestPaths) {
216-
// Note: because we run the --pretty tests on the code in run-pass etc,
217-
// we may see a list of revisions -- but we can just ignore them.
218-
// We cannot assert that the list is empty as we do elsewhere.
219-
//
220-
// assert!(props.revisions.is_empty(), "revisions not relevant here");
216+
for_each_revision(config, props, testpaths, run_pretty_test_revision);
217+
}
221218

219+
fn run_pretty_test_revision(config: &Config,
220+
props: &TestProps,
221+
testpaths: &TestPaths,
222+
revision: Option<&str>) {
222223
if props.pp_exact.is_some() {
223224
logv(config, "testing for exact pretty-printing".to_owned());
224225
} else {
@@ -234,16 +235,18 @@ fn run_pretty_test(config: &Config, props: &TestProps, testpaths: &TestPaths) {
234235

235236
let mut round = 0;
236237
while round < rounds {
237-
logv(config, format!("pretty-printing round {}", round));
238+
logv(config, format!("pretty-printing round {} revision {:?}",
239+
round, revision));
238240
let proc_res = print_source(config,
239241
props,
240242
testpaths,
241243
srcs[round].to_owned(),
242244
&props.pretty_mode);
243245

244246
if !proc_res.status.success() {
245-
fatal_proc_rec(None,
246-
&format!("pretty-printing failed in round {}", round),
247+
fatal_proc_rec(revision,
248+
&format!("pretty-printing failed in round {} revision {:?}",
249+
round, revision),
247250
&proc_res);
248251
}
249252

@@ -270,30 +273,30 @@ fn run_pretty_test(config: &Config, props: &TestProps, testpaths: &TestPaths) {
270273
expected = expected.replace(&cr, "").to_owned();
271274
}
272275

273-
compare_source(&expected, &actual);
276+
compare_source(revision, &expected, &actual);
274277

275278
// If we're only making sure that the output matches then just stop here
276279
if props.pretty_compare_only { return; }
277280

278281
// Finally, let's make sure it actually appears to remain valid code
279282
let proc_res = typecheck_source(config, props, testpaths, actual);
280-
281283
if !proc_res.status.success() {
282-
fatal_proc_rec(None, "pretty-printed source does not typecheck", &proc_res);
284+
fatal_proc_rec(revision, "pretty-printed source does not typecheck", &proc_res);
283285
}
286+
284287
if !props.pretty_expanded { return }
285288

286289
// additionally, run `--pretty expanded` and try to build it.
287290
let proc_res = print_source(config, props, testpaths, srcs[round].clone(), "expanded");
288291
if !proc_res.status.success() {
289-
fatal_proc_rec(None, "pretty-printing (expanded) failed", &proc_res);
292+
fatal_proc_rec(revision, "pretty-printing (expanded) failed", &proc_res);
290293
}
291294

292295
let ProcRes{ stdout: expanded_src, .. } = proc_res;
293296
let proc_res = typecheck_source(config, props, testpaths, expanded_src);
294297
if !proc_res.status.success() {
295298
fatal_proc_rec(
296-
None,
299+
revision,
297300
"pretty-printed source (expanded) does not typecheck",
298301
&proc_res);
299302
}
@@ -339,9 +342,9 @@ fn run_pretty_test(config: &Config, props: &TestProps, testpaths: &TestPaths) {
339342
};
340343
}
341344

342-
fn compare_source(expected: &str, actual: &str) {
345+
fn compare_source(revision: Option<&str>, expected: &str, actual: &str) {
343346
if expected != actual {
344-
error(None, "pretty-printed source does not match expected source");
347+
error(revision, "pretty-printed source does not match expected source");
345348
println!("\n\
346349
expected:\n\
347350
------------------------------------------\n\

0 commit comments

Comments
 (0)