]> git.lizzy.rs Git - rust.git/commitdiff
rustdoc: adding some common feature gates when testing a markdown file.
authorHuon Wilson <dbau.pp+github@gmail.com>
Sat, 8 Mar 2014 10:30:43 +0000 (21:30 +1100)
committerHuon Wilson <dbau.pp+github@gmail.com>
Sun, 9 Mar 2014 08:34:40 +0000 (19:34 +1100)
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

src/librustdoc/markdown.rs
src/librustdoc/test.rs

index 67a08706e982c83a8403662cb4f26662ecfe4421..5d8e0008b870d393069a7f33c64a5fb8dfa206a9 100644 (file)
@@ -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);
index 640a3304094a88f72ed7831654b172e360db59fb..45607a0992e2342d42543785527083d3d16a14ba 100644 (file)
@@ -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 @@ pub fn new(cratename: ~str, libs: @RefCell<HashSet<Path>>, use_headers: bool) ->
             cnt: 0,
             use_headers: use_headers,
             current_header: None,
-            cratename: cratename
+            cratename: cratename,
+
+            loose_feature_gating: loose_feature_gating
         }
     }
 
@@ -220,6 +232,7 @@ pub fn add_test(&mut self, test: ~str, should_fail: bool, no_run: bool) {
         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 @@ pub fn add_test(&mut self, test: ~str, should_fail: bool, no_run: bool) {
                 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);
             }),
         });
     }