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
This commit is contained in:
parent
7a70ec1ba6
commit
8e90412048
2 changed files with 21 additions and 8 deletions
|
@ -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 {
|
pub fn test(input: &str, libs: @RefCell<HashSet<Path>>, mut test_args: ~[~str]) -> int {
|
||||||
let input_str = load_or_return!(input, 1, 2);
|
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);
|
find_testable_code(input_str, &mut collector);
|
||||||
test_args.unshift(~"rustdoctest");
|
test_args.unshift(~"rustdoctest");
|
||||||
testing::test_main(test_args, collector.tests);
|
testing::test_main(test_args, collector.tests);
|
||||||
|
|
|
@ -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::unindent_comments(krate);
|
||||||
let (krate, _) = passes::collapse_docs(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);
|
collector.fold_crate(krate);
|
||||||
|
|
||||||
test_args.unshift(~"rustdoctest");
|
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,
|
fn runtest(test: &str, cratename: &str, libs: HashSet<Path>, should_fail: bool,
|
||||||
no_run: bool) {
|
no_run: bool, loose_feature_gating: bool) {
|
||||||
let test = maketest(test, cratename);
|
let test = maketest(test, cratename, loose_feature_gating);
|
||||||
let parsesess = parse::new_parse_sess();
|
let parsesess = parse::new_parse_sess();
|
||||||
let input = driver::StrInput(test);
|
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"
|
let mut prog = ~r"
|
||||||
#[deny(warnings)];
|
#[deny(warnings)];
|
||||||
#[allow(unused_variable, dead_assignment, unused_mut, attribute_usage, dead_code)];
|
#[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("extern crate") {
|
||||||
if s.contains("extra") {
|
if s.contains("extra") {
|
||||||
prog.push_str("extern crate extra;\n");
|
prog.push_str("extern crate extra;\n");
|
||||||
|
@ -194,10 +201,13 @@ pub struct Collector {
|
||||||
priv use_headers: bool,
|
priv use_headers: bool,
|
||||||
priv current_header: Option<~str>,
|
priv current_header: Option<~str>,
|
||||||
priv cratename: ~str,
|
priv cratename: ~str,
|
||||||
|
|
||||||
|
priv loose_feature_gating: bool
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Collector {
|
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 {
|
Collector {
|
||||||
tests: ~[],
|
tests: ~[],
|
||||||
names: ~[],
|
names: ~[],
|
||||||
|
@ -205,7 +215,9 @@ impl Collector {
|
||||||
cnt: 0,
|
cnt: 0,
|
||||||
use_headers: use_headers,
|
use_headers: use_headers,
|
||||||
current_header: None,
|
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 = self.libs.borrow();
|
||||||
let libs = (*libs.get()).clone();
|
let libs = (*libs.get()).clone();
|
||||||
let cratename = self.cratename.to_owned();
|
let cratename = self.cratename.to_owned();
|
||||||
|
let loose_feature_gating = self.loose_feature_gating;
|
||||||
debug!("Creating test {}: {}", name, test);
|
debug!("Creating test {}: {}", name, test);
|
||||||
self.tests.push(testing::TestDescAndFn {
|
self.tests.push(testing::TestDescAndFn {
|
||||||
desc: testing::TestDesc {
|
desc: testing::TestDesc {
|
||||||
|
@ -228,7 +241,7 @@ impl Collector {
|
||||||
should_fail: false, // compiler failures are test failures
|
should_fail: false, // compiler failures are test failures
|
||||||
},
|
},
|
||||||
testfn: testing::DynTestFn(proc() {
|
testfn: testing::DynTestFn(proc() {
|
||||||
runtest(test, cratename, libs, should_fail, no_run);
|
runtest(test, cratename, libs, should_fail, no_run, loose_feature_gating);
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue