Skip to content

Commit c5bdc35

Browse files
committed
refactor and generalize revisions
1 parent bb2a425 commit c5bdc35

File tree

3 files changed

+52
-16
lines changed

3 files changed

+52
-16
lines changed

src/compiletest/errors.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ enum WhichLine { ThisLine, FollowPrevious(usize), AdjustBackward(usize) }
3333
///
3434
/// If cfg is not None (i.e., in an incremental test), then we look
3535
/// for `//[X]~` instead, where `X` is the current `cfg`.
36-
pub fn load_errors(testfile: &Path, cfg: &Option<String>) -> Vec<ExpectedError> {
36+
pub fn load_errors(testfile: &Path, cfg: Option<&str>) -> Vec<ExpectedError> {
3737
let rdr = BufReader::new(File::open(testfile).unwrap());
3838

3939
// `last_nonfollow_error` tracks the most recently seen
@@ -46,8 +46,8 @@ pub fn load_errors(testfile: &Path, cfg: &Option<String>) -> Vec<ExpectedError>
4646
// updating it in the map callback below.)
4747
let mut last_nonfollow_error = None;
4848

49-
let tag = match *cfg {
50-
Some(ref rev) => format!("//[{}]~", rev),
49+
let tag = match cfg {
50+
Some(rev) => format!("//[{}]~", rev),
5151
None => format!("//~")
5252
};
5353

src/compiletest/header.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,6 @@ use util;
2020

2121
#[derive(Clone, Debug)]
2222
pub struct TestProps {
23-
// For the main test file, this is initialized to `None`. But
24-
// when running tests that test multiple revisions, such as
25-
// incremental tests, we will set this to `Some(foo)` where `foo`
26-
// is the current revision identifier.
27-
//
28-
// Note that, unlike the other options here, this value is never
29-
// loaded from the input file (though it is always set to one of
30-
// the values listed in the vec `self.revisions`, which is loaded
31-
// from the file).
32-
pub revision: Option<String>,
3323
// Lines that should be expected, in order, on standard out
3424
pub error_patterns: Vec<String> ,
3525
// Extra flags to pass to the compiler
@@ -81,7 +71,6 @@ pub fn load_props(testfile: &Path) -> TestProps {
8171
let pretty_compare_only = false;
8272
let forbid_output = Vec::new();
8373
let mut props = TestProps {
84-
revision: None,
8574
error_patterns: error_patterns,
8675
compile_flags: vec![],
8776
run_flags: run_flags,

src/compiletest/runtest.rs

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,36 @@ fn get_output(props: &TestProps, proc_res: &ProcRes) -> String {
7070
}
7171
}
7272

73+
74+
fn for_each_revision<OP>(config: &Config, props: &TestProps, testpaths: &TestPaths,
75+
mut op: OP)
76+
where OP: FnMut(&Config, &TestProps, &TestPaths, Option<&str>)
77+
{
78+
if props.revisions.is_empty() {
79+
op(config, props, testpaths, None)
80+
} else {
81+
for revision in &props.revisions {
82+
let mut revision_props = props.clone();
83+
header::load_props_into(&mut revision_props,
84+
&testpaths.file,
85+
Some(&revision));
86+
revision_props.compile_flags.extend(vec![
87+
format!("--cfg"),
88+
format!("{}", revision),
89+
]);
90+
op(config, &revision_props, testpaths, Some(revision));
91+
}
92+
}
93+
}
94+
7395
fn run_cfail_test(config: &Config, props: &TestProps, testpaths: &TestPaths) {
96+
for_each_revision(config, props, testpaths, run_cfail_test_revision);
97+
}
98+
99+
fn run_cfail_test_revision(config: &Config,
100+
props: &TestProps,
101+
testpaths: &TestPaths,
102+
revision: Option<&str>) {
74103
let proc_res = compile_test(config, props, testpaths);
75104

76105
if proc_res.status.success() {
@@ -85,7 +114,7 @@ fn run_cfail_test(config: &Config, props: &TestProps, testpaths: &TestPaths) {
85114
}
86115

87116
let output_to_check = get_output(props, &proc_res);
88-
let expected_errors = errors::load_errors(&testpaths.file, &props.revision);
117+
let expected_errors = errors::load_errors(&testpaths.file, revision);
89118
if !expected_errors.is_empty() {
90119
if !props.error_patterns.is_empty() {
91120
fatal("both error pattern and expected errors specified");
@@ -99,6 +128,13 @@ fn run_cfail_test(config: &Config, props: &TestProps, testpaths: &TestPaths) {
99128
}
100129

101130
fn run_rfail_test(config: &Config, props: &TestProps, testpaths: &TestPaths) {
131+
for_each_revision(config, props, testpaths, run_rfail_test_revision);
132+
}
133+
134+
fn run_rfail_test_revision(config: &Config,
135+
props: &TestProps,
136+
testpaths: &TestPaths,
137+
_revision: Option<&str>) {
102138
let proc_res = compile_test(config, props, testpaths);
103139

104140
if !proc_res.status.success() {
@@ -130,6 +166,13 @@ fn check_correct_failure_status(proc_res: &ProcRes) {
130166
}
131167

132168
fn run_rpass_test(config: &Config, props: &TestProps, testpaths: &TestPaths) {
169+
for_each_revision(config, props, testpaths, run_rpass_test_revision);
170+
}
171+
172+
fn run_rpass_test_revision(config: &Config,
173+
props: &TestProps,
174+
testpaths: &TestPaths,
175+
_revision: Option<&str>) {
133176
let proc_res = compile_test(config, props, testpaths);
134177

135178
if !proc_res.status.success() {
@@ -144,6 +187,8 @@ fn run_rpass_test(config: &Config, props: &TestProps, testpaths: &TestPaths) {
144187
}
145188

146189
fn run_valgrind_test(config: &Config, props: &TestProps, testpaths: &TestPaths) {
190+
assert!(props.revisions.is_empty(), "revisions not relevant to rpass tests");
191+
147192
if config.valgrind_path.is_none() {
148193
assert!(!config.force_valgrind);
149194
return run_rpass_test(config, props, testpaths);
@@ -1804,6 +1849,8 @@ fn run_rustdoc_test(config: &Config, props: &TestProps, testpaths: &TestPaths) {
18041849
}
18051850

18061851
fn run_codegen_units_test(config: &Config, props: &TestProps, testpaths: &TestPaths) {
1852+
assert!(props.revisions.is_empty(), "revisions not relevant to codegen units");
1853+
18071854
let proc_res = compile_test(config, props, testpaths);
18081855

18091856
if !proc_res.status.success() {
@@ -1821,7 +1868,7 @@ fn run_codegen_units_test(config: &Config, props: &TestProps, testpaths: &TestPa
18211868
.map(|s| (&s[prefix.len()..]).to_string())
18221869
.collect();
18231870

1824-
let expected: HashSet<String> = errors::load_errors(&testpaths.file, &props.revision)
1871+
let expected: HashSet<String> = errors::load_errors(&testpaths.file, None)
18251872
.iter()
18261873
.map(|e| e.msg.trim().to_string())
18271874
.collect();

0 commit comments

Comments
 (0)