]> git.lizzy.rs Git - rust.git/commitdiff
refactor and generalize revisions
authorNiko Matsakis <niko@alum.mit.edu>
Wed, 2 Mar 2016 03:05:39 +0000 (22:05 -0500)
committerNiko Matsakis <niko@alum.mit.edu>
Wed, 2 Mar 2016 10:02:04 +0000 (05:02 -0500)
src/compiletest/errors.rs
src/compiletest/header.rs
src/compiletest/runtest.rs

index 63bc657baa428d0c0830afc3f4182d13799c488c..44634e4d565ff0f68158a8932f5e154eb45f596f 100644 (file)
@@ -33,7 +33,7 @@ enum WhichLine { ThisLine, FollowPrevious(usize), AdjustBackward(usize) }
 ///
 /// If cfg is not None (i.e., in an incremental test), then we look
 /// for `//[X]~` instead, where `X` is the current `cfg`.
-pub fn load_errors(testfile: &Path, cfg: &Option<String>) -> Vec<ExpectedError> {
+pub fn load_errors(testfile: &Path, cfg: Option<&str>) -> Vec<ExpectedError> {
     let rdr = BufReader::new(File::open(testfile).unwrap());
 
     // `last_nonfollow_error` tracks the most recently seen
@@ -46,8 +46,8 @@ pub fn load_errors(testfile: &Path, cfg: &Option<String>) -> Vec<ExpectedError>
     // updating it in the map callback below.)
     let mut last_nonfollow_error = None;
 
-    let tag = match *cfg {
-        Some(ref rev) => format!("//[{}]~", rev),
+    let tag = match cfg {
+        Some(rev) => format!("//[{}]~", rev),
         None => format!("//~")
     };
 
index c9dfc0bf1a49743a8668ba1108416192871c12bb..75d7ada8719b78c8141bd36073f47bb46b1a5ddc 100644 (file)
 
 #[derive(Clone, Debug)]
 pub struct TestProps {
-    // For the main test file, this is initialized to `None`. But
-    // when running tests that test multiple revisions, such as
-    // incremental tests, we will set this to `Some(foo)` where `foo`
-    // is the current revision identifier.
-    //
-    // Note that, unlike the other options here, this value is never
-    // loaded from the input file (though it is always set to one of
-    // the values listed in the vec `self.revisions`, which is loaded
-    // from the file).
-    pub revision: Option<String>,
     // Lines that should be expected, in order, on standard out
     pub error_patterns: Vec<String> ,
     // Extra flags to pass to the compiler
@@ -81,7 +71,6 @@ pub fn load_props(testfile: &Path) -> TestProps {
     let pretty_compare_only = false;
     let forbid_output = Vec::new();
     let mut props = TestProps {
-        revision: None,
         error_patterns: error_patterns,
         compile_flags: vec![],
         run_flags: run_flags,
index ab766eecd9dfe6767c7bc630c89e6f911b84b96c..880f9742b1066d9818901462f395aed8c31bf0d1 100644 (file)
@@ -70,7 +70,36 @@ fn get_output(props: &TestProps, proc_res: &ProcRes) -> String {
     }
 }
 
+
+fn for_each_revision<OP>(config: &Config, props: &TestProps, testpaths: &TestPaths,
+                         mut op: OP)
+    where OP: FnMut(&Config, &TestProps, &TestPaths, Option<&str>)
+{
+    if props.revisions.is_empty() {
+        op(config, props, testpaths, None)
+    } else {
+        for revision in &props.revisions {
+            let mut revision_props = props.clone();
+            header::load_props_into(&mut revision_props,
+                                    &testpaths.file,
+                                    Some(&revision));
+            revision_props.compile_flags.extend(vec![
+                format!("--cfg"),
+                format!("{}", revision),
+            ]);
+            op(config, &revision_props, testpaths, Some(revision));
+        }
+    }
+}
+
 fn run_cfail_test(config: &Config, props: &TestProps, testpaths: &TestPaths) {
+    for_each_revision(config, props, testpaths, run_cfail_test_revision);
+}
+
+fn run_cfail_test_revision(config: &Config,
+                           props: &TestProps,
+                           testpaths: &TestPaths,
+                           revision: Option<&str>) {
     let proc_res = compile_test(config, props, testpaths);
 
     if proc_res.status.success() {
@@ -85,7 +114,7 @@ fn run_cfail_test(config: &Config, props: &TestProps, testpaths: &TestPaths) {
     }
 
     let output_to_check = get_output(props, &proc_res);
-    let expected_errors = errors::load_errors(&testpaths.file, &props.revision);
+    let expected_errors = errors::load_errors(&testpaths.file, revision);
     if !expected_errors.is_empty() {
         if !props.error_patterns.is_empty() {
             fatal("both error pattern and expected errors specified");
@@ -99,6 +128,13 @@ fn run_cfail_test(config: &Config, props: &TestProps, testpaths: &TestPaths) {
 }
 
 fn run_rfail_test(config: &Config, props: &TestProps, testpaths: &TestPaths) {
+    for_each_revision(config, props, testpaths, run_rfail_test_revision);
+}
+
+fn run_rfail_test_revision(config: &Config,
+                           props: &TestProps,
+                           testpaths: &TestPaths,
+                           _revision: Option<&str>) {
     let proc_res = compile_test(config, props, testpaths);
 
     if !proc_res.status.success() {
@@ -130,6 +166,13 @@ fn check_correct_failure_status(proc_res: &ProcRes) {
 }
 
 fn run_rpass_test(config: &Config, props: &TestProps, testpaths: &TestPaths) {
+    for_each_revision(config, props, testpaths, run_rpass_test_revision);
+}
+
+fn run_rpass_test_revision(config: &Config,
+                           props: &TestProps,
+                           testpaths: &TestPaths,
+                           _revision: Option<&str>) {
     let proc_res = compile_test(config, props, testpaths);
 
     if !proc_res.status.success() {
@@ -144,6 +187,8 @@ fn run_rpass_test(config: &Config, props: &TestProps, testpaths: &TestPaths) {
 }
 
 fn run_valgrind_test(config: &Config, props: &TestProps, testpaths: &TestPaths) {
+    assert!(props.revisions.is_empty(), "revisions not relevant to rpass tests");
+
     if config.valgrind_path.is_none() {
         assert!(!config.force_valgrind);
         return run_rpass_test(config, props, testpaths);
@@ -1804,6 +1849,8 @@ fn run_rustdoc_test(config: &Config, props: &TestProps, testpaths: &TestPaths) {
 }
 
 fn run_codegen_units_test(config: &Config, props: &TestProps, testpaths: &TestPaths) {
+    assert!(props.revisions.is_empty(), "revisions not relevant to codegen units");
+
     let proc_res = compile_test(config, props, testpaths);
 
     if !proc_res.status.success() {
@@ -1821,7 +1868,7 @@ fn run_codegen_units_test(config: &Config, props: &TestProps, testpaths: &TestPa
         .map(|s| (&s[prefix.len()..]).to_string())
         .collect();
 
-    let expected: HashSet<String> = errors::load_errors(&testpaths.file, &props.revision)
+    let expected: HashSet<String> = errors::load_errors(&testpaths.file, None)
         .iter()
         .map(|e| e.msg.trim().to_string())
         .collect();