about summary refs log tree commit diff
diff options
context:
space:
mode:
authorHuon Wilson <dbau.pp+github@gmail.com>2014-03-08 21:30:43 +1100
committerHuon Wilson <dbau.pp+github@gmail.com>2014-03-09 19:34:40 +1100
commit8e904120487f67172eb2d509531ed8f9e230af3a (patch)
tree68c3ec630d9fb282ba20922c8742ac89042fb21a
parent7a70ec1ba6e64949cab5edcad33b0d7538065884 (diff)
downloadrust-8e904120487f67172eb2d509531ed8f9e230af3a.tar.gz
rust-8e904120487f67172eb2d509531ed8f9e230af3a.zip
rustdoc: adding some common feature gates when testing a markdown file.
The manual, tutorial and guides need the feature gates quite often,
unfortunately, so this is the low-cost path to migrating to use
rustdoc. This is only activated for pure-Markdown files.

Preferably this would be avoided: #12773
-rw-r--r--src/librustdoc/markdown.rs2
-rw-r--r--src/librustdoc/test.rs27
2 files changed, 21 insertions, 8 deletions
diff --git a/src/librustdoc/markdown.rs b/src/librustdoc/markdown.rs
index 67a08706e98..5d8e0008b87 100644
--- a/src/librustdoc/markdown.rs
+++ b/src/librustdoc/markdown.rs
@@ -163,7 +163,7 @@ pub fn render(input: &str, mut output: Path, matches: &getopts::Matches) -> int
 pub fn test(input: &str, libs: @RefCell<HashSet<Path>>, mut test_args: ~[~str]) -> int {
     let input_str = load_or_return!(input, 1, 2);
 
-    let mut collector = Collector::new(input.to_owned(), libs, true);
+    let mut collector = Collector::new(input.to_owned(), libs, true, true);
     find_testable_code(input_str, &mut collector);
     test_args.unshift(~"rustdoctest");
     testing::test_main(test_args, collector.tests);
diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs
index 640a3304094..45607a0992e 100644
--- a/src/librustdoc/test.rs
+++ b/src/librustdoc/test.rs
@@ -77,7 +77,7 @@ pub fn run(input: &str, libs: @RefCell<HashSet<Path>>, mut test_args: ~[~str]) -
     let (krate, _) = passes::unindent_comments(krate);
     let (krate, _) = passes::collapse_docs(krate);
 
-    let mut collector = Collector::new(krate.name.to_owned(), libs, false);
+    let mut collector = Collector::new(krate.name.to_owned(), libs, false, false);
     collector.fold_crate(krate);
 
     test_args.unshift(~"rustdoctest");
@@ -88,8 +88,8 @@ pub fn run(input: &str, libs: @RefCell<HashSet<Path>>, mut test_args: ~[~str]) -
 }
 
 fn runtest(test: &str, cratename: &str, libs: HashSet<Path>, should_fail: bool,
-           no_run: bool) {
-    let test = maketest(test, cratename);
+           no_run: bool, loose_feature_gating: bool) {
+    let test = maketest(test, cratename, loose_feature_gating);
     let parsesess = parse::new_parse_sess();
     let input = driver::StrInput(test);
 
@@ -162,11 +162,18 @@ fn runtest(test: &str, cratename: &str, libs: HashSet<Path>, should_fail: bool,
     }
 }
 
-fn maketest(s: &str, cratename: &str) -> ~str {
+fn maketest(s: &str, cratename: &str, loose_feature_gating: bool) -> ~str {
     let mut prog = ~r"
 #[deny(warnings)];
 #[allow(unused_variable, dead_assignment, unused_mut, attribute_usage, dead_code)];
 ";
+
+    if loose_feature_gating {
+        // FIXME #12773: avoid inserting these when the tutorial & manual
+        // etc. have been updated to not use them so prolifically.
+        prog.push_str("#[ feature(macro_rules, globs, struct_variant, managed_boxes) ];\n");
+    }
+
     if !s.contains("extern crate") {
         if s.contains("extra") {
             prog.push_str("extern crate extra;\n");
@@ -194,10 +201,13 @@ pub struct Collector {
     priv use_headers: bool,
     priv current_header: Option<~str>,
     priv cratename: ~str,
+
+    priv loose_feature_gating: bool
 }
 
 impl Collector {
-    pub fn new(cratename: ~str, libs: @RefCell<HashSet<Path>>, use_headers: bool) -> Collector {
+    pub fn new(cratename: ~str, libs: @RefCell<HashSet<Path>>,
+               use_headers: bool, loose_feature_gating: bool) -> Collector {
         Collector {
             tests: ~[],
             names: ~[],
@@ -205,7 +215,9 @@ impl Collector {
             cnt: 0,
             use_headers: use_headers,
             current_header: None,
-            cratename: cratename
+            cratename: cratename,
+
+            loose_feature_gating: loose_feature_gating
         }
     }
 
@@ -220,6 +232,7 @@ impl Collector {
         let libs = self.libs.borrow();
         let libs = (*libs.get()).clone();
         let cratename = self.cratename.to_owned();
+        let loose_feature_gating = self.loose_feature_gating;
         debug!("Creating test {}: {}", name, test);
         self.tests.push(testing::TestDescAndFn {
             desc: testing::TestDesc {
@@ -228,7 +241,7 @@ impl Collector {
                 should_fail: false, // compiler failures are test failures
             },
             testfn: testing::DynTestFn(proc() {
-                runtest(test, cratename, libs, should_fail, no_run);
+                runtest(test, cratename, libs, should_fail, no_run, loose_feature_gating);
             }),
         });
     }