make pretty printer tests understand revisions, and make them ignore the
should-fail annotation
This commit is contained in:
parent
9601e6f252
commit
aa19b41f25
2 changed files with 32 additions and 20 deletions
|
@ -355,15 +355,24 @@ pub fn is_test(config: &Config, testfile: &Path) -> bool {
|
||||||
|
|
||||||
pub fn make_test(config: &Config, testpaths: &TestPaths) -> test::TestDescAndFn {
|
pub fn make_test(config: &Config, testpaths: &TestPaths) -> test::TestDescAndFn {
|
||||||
let early_props = header::early_props(config, &testpaths.file);
|
let early_props = header::early_props(config, &testpaths.file);
|
||||||
|
|
||||||
|
// The `should-fail` annotation doesn't apply to pretty tests,
|
||||||
|
// since we run the pretty printer across all tests by default.
|
||||||
|
// If desired, we could add a `should-fail-pretty` annotation.
|
||||||
|
let should_panic = match config.mode {
|
||||||
|
Pretty => test::ShouldPanic::No,
|
||||||
|
_ => if early_props.should_fail {
|
||||||
|
test::ShouldPanic::Yes
|
||||||
|
} else {
|
||||||
|
test::ShouldPanic::No
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
test::TestDescAndFn {
|
test::TestDescAndFn {
|
||||||
desc: test::TestDesc {
|
desc: test::TestDesc {
|
||||||
name: make_test_name(config, testpaths),
|
name: make_test_name(config, testpaths),
|
||||||
ignore: early_props.ignore,
|
ignore: early_props.ignore,
|
||||||
should_panic: if early_props.should_fail {
|
should_panic: should_panic,
|
||||||
test::ShouldPanic::Yes
|
|
||||||
} else {
|
|
||||||
test::ShouldPanic::No
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
testfn: make_test_closure(config, testpaths),
|
testfn: make_test_closure(config, testpaths),
|
||||||
}
|
}
|
||||||
|
|
|
@ -213,12 +213,13 @@ fn run_valgrind_test(config: &Config, props: &TestProps, testpaths: &TestPaths)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_pretty_test(config: &Config, props: &TestProps, testpaths: &TestPaths) {
|
fn run_pretty_test(config: &Config, props: &TestProps, testpaths: &TestPaths) {
|
||||||
// Note: because we run the --pretty tests on the code in run-pass etc,
|
for_each_revision(config, props, testpaths, run_pretty_test_revision);
|
||||||
// we may see a list of revisions -- but we can just ignore them.
|
}
|
||||||
// We cannot assert that the list is empty as we do elsewhere.
|
|
||||||
//
|
|
||||||
// assert!(props.revisions.is_empty(), "revisions not relevant here");
|
|
||||||
|
|
||||||
|
fn run_pretty_test_revision(config: &Config,
|
||||||
|
props: &TestProps,
|
||||||
|
testpaths: &TestPaths,
|
||||||
|
revision: Option<&str>) {
|
||||||
if props.pp_exact.is_some() {
|
if props.pp_exact.is_some() {
|
||||||
logv(config, "testing for exact pretty-printing".to_owned());
|
logv(config, "testing for exact pretty-printing".to_owned());
|
||||||
} else {
|
} else {
|
||||||
|
@ -234,7 +235,8 @@ fn run_pretty_test(config: &Config, props: &TestProps, testpaths: &TestPaths) {
|
||||||
|
|
||||||
let mut round = 0;
|
let mut round = 0;
|
||||||
while round < rounds {
|
while round < rounds {
|
||||||
logv(config, format!("pretty-printing round {}", round));
|
logv(config, format!("pretty-printing round {} revision {:?}",
|
||||||
|
round, revision));
|
||||||
let proc_res = print_source(config,
|
let proc_res = print_source(config,
|
||||||
props,
|
props,
|
||||||
testpaths,
|
testpaths,
|
||||||
|
@ -242,8 +244,9 @@ fn run_pretty_test(config: &Config, props: &TestProps, testpaths: &TestPaths) {
|
||||||
&props.pretty_mode);
|
&props.pretty_mode);
|
||||||
|
|
||||||
if !proc_res.status.success() {
|
if !proc_res.status.success() {
|
||||||
fatal_proc_rec(None,
|
fatal_proc_rec(revision,
|
||||||
&format!("pretty-printing failed in round {}", round),
|
&format!("pretty-printing failed in round {} revision {:?}",
|
||||||
|
round, revision),
|
||||||
&proc_res);
|
&proc_res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -270,30 +273,30 @@ fn run_pretty_test(config: &Config, props: &TestProps, testpaths: &TestPaths) {
|
||||||
expected = expected.replace(&cr, "").to_owned();
|
expected = expected.replace(&cr, "").to_owned();
|
||||||
}
|
}
|
||||||
|
|
||||||
compare_source(&expected, &actual);
|
compare_source(revision, &expected, &actual);
|
||||||
|
|
||||||
// If we're only making sure that the output matches then just stop here
|
// If we're only making sure that the output matches then just stop here
|
||||||
if props.pretty_compare_only { return; }
|
if props.pretty_compare_only { return; }
|
||||||
|
|
||||||
// Finally, let's make sure it actually appears to remain valid code
|
// Finally, let's make sure it actually appears to remain valid code
|
||||||
let proc_res = typecheck_source(config, props, testpaths, actual);
|
let proc_res = typecheck_source(config, props, testpaths, actual);
|
||||||
|
|
||||||
if !proc_res.status.success() {
|
if !proc_res.status.success() {
|
||||||
fatal_proc_rec(None, "pretty-printed source does not typecheck", &proc_res);
|
fatal_proc_rec(revision, "pretty-printed source does not typecheck", &proc_res);
|
||||||
}
|
}
|
||||||
|
|
||||||
if !props.pretty_expanded { return }
|
if !props.pretty_expanded { return }
|
||||||
|
|
||||||
// additionally, run `--pretty expanded` and try to build it.
|
// additionally, run `--pretty expanded` and try to build it.
|
||||||
let proc_res = print_source(config, props, testpaths, srcs[round].clone(), "expanded");
|
let proc_res = print_source(config, props, testpaths, srcs[round].clone(), "expanded");
|
||||||
if !proc_res.status.success() {
|
if !proc_res.status.success() {
|
||||||
fatal_proc_rec(None, "pretty-printing (expanded) failed", &proc_res);
|
fatal_proc_rec(revision, "pretty-printing (expanded) failed", &proc_res);
|
||||||
}
|
}
|
||||||
|
|
||||||
let ProcRes{ stdout: expanded_src, .. } = proc_res;
|
let ProcRes{ stdout: expanded_src, .. } = proc_res;
|
||||||
let proc_res = typecheck_source(config, props, testpaths, expanded_src);
|
let proc_res = typecheck_source(config, props, testpaths, expanded_src);
|
||||||
if !proc_res.status.success() {
|
if !proc_res.status.success() {
|
||||||
fatal_proc_rec(
|
fatal_proc_rec(
|
||||||
None,
|
revision,
|
||||||
"pretty-printed source (expanded) does not typecheck",
|
"pretty-printed source (expanded) does not typecheck",
|
||||||
&proc_res);
|
&proc_res);
|
||||||
}
|
}
|
||||||
|
@ -339,9 +342,9 @@ fn run_pretty_test(config: &Config, props: &TestProps, testpaths: &TestPaths) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compare_source(expected: &str, actual: &str) {
|
fn compare_source(revision: Option<&str>, expected: &str, actual: &str) {
|
||||||
if expected != actual {
|
if expected != actual {
|
||||||
error(None, "pretty-printed source does not match expected source");
|
error(revision, "pretty-printed source does not match expected source");
|
||||||
println!("\n\
|
println!("\n\
|
||||||
expected:\n\
|
expected:\n\
|
||||||
------------------------------------------\n\
|
------------------------------------------\n\
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue