Skip to content

Commit

Permalink
Fix librustdoc test
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Feb 9, 2016
1 parent 194f1ca commit eb7664b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 27 deletions.
30 changes: 9 additions & 21 deletions src/librustdoc/html/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@
#![allow(non_camel_case_types)]

use libc;
use rustc::session::config::get_unstable_features_setting;
use std::ascii::AsciiExt;
use std::cell::RefCell;
use std::default::Default;
use std::ffi::CString;
use std::fmt;
use std::slice;
use std::str;
use std::env;
use syntax::feature_gate::UnstableFeatures;

use html::render::derive_id;
use html::toc::TocBuilder;
Expand Down Expand Up @@ -440,18 +441,6 @@ pub fn find_testable_code(doc: &str, tests: &mut ::test::Collector) {
}
}

fn get_unstable_features_setting() -> bool {
// Check if we can activate compile_fail option or not.
//
// It is done to ensure that it won't be used out-of-tree
// because it's not ready yet for production.
match (option_env!("CFG_BOOTSTRAP_KEY"),
env::var("RUSTC_BOOTSTRAP_KEY").ok()) {
(Some(ref cfg), Some(ref r_key)) => cfg == r_key,
_ => false,
}
}

#[derive(Eq, PartialEq, Clone, Debug)]
struct LangString {
should_panic: bool,
Expand All @@ -478,7 +467,10 @@ impl LangString {
let mut seen_rust_tags = false;
let mut seen_other_tags = false;
let mut data = LangString::all_false();
let allow_compile_fail = get_unstable_features_setting();
let allow_compile_fail = match get_unstable_features_setting() {
UnstableFeatures::Allow | UnstableFeatures::Cheat=> true,
_ => false,
};

let tokens = string.split(|c: char|
!(c == '_' || c == '-' || c.is_alphanumeric())
Expand All @@ -487,11 +479,7 @@ impl LangString {
for token in tokens {
match token {
"" => {},
"should_panic" => {
data.should_panic = true;
seen_rust_tags = true;
data.no_run = true;
},
"should_panic" => { data.should_panic = true; seen_rust_tags = true; },
"no_run" => { data.no_run = true; seen_rust_tags = true; },
"ignore" => { data.ignore = true; seen_rust_tags = true; },
"rust" => { data.rust = true; seen_rust_tags = true; },
Expand Down Expand Up @@ -600,10 +588,10 @@ mod tests {
t("rust", false, false, false, true, false, false);
t("sh", false, false, false, false, false, false);
t("ignore", false, false, true, true, false, false);
t("should_panic", true, true, false, true, false, false);
t("should_panic", true, false, false, true, false, false);
t("no_run", false, true, false, true, false, false);
t("test_harness", false, false, false, true, true, false);
t("compile_fail", false, false, false, true, false, true);
t("compile_fail", false, true, false, true, false, true);
t("{.no_run .example}", false, true, false, true, false, false);
t("{.sh .should_panic}", true, false, false, true, false, false);
t("{.example .rust}", false, false, false, true, false, false);
Expand Down
10 changes: 4 additions & 6 deletions src/librustdoc/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,18 +257,16 @@ fn runtest(test: &str, cratename: &str, cfgs: Vec<String>, libs: SearchPaths,
let b_sess = AssertRecoverSafe::new(&sess);
let b_cstore = AssertRecoverSafe::new(&cstore);
let b_cfg = AssertRecoverSafe::new(cfg.clone());
let b_input = AssertRecoverSafe::new(&input);
let b_out = AssertRecoverSafe::new(&out);
let b_control = AssertRecoverSafe::new(&control);

panic::recover(|| {
AssertRecoverSafe::new(driver::compile_input(&b_sess, &b_cstore, (*b_cfg).clone(),
&b_input, &b_out,
&None, None, &b_control))
driver::compile_input(&b_sess, &b_cstore, (*b_cfg).clone(),
&input, &out,
&None, None, &b_control)
})
} {
Ok(r) => {
match *r {
match r {
Err(count) if count > 0 && compile_fail == false => {
sess.fatal("aborting due to previous error(s)")
}
Expand Down

0 comments on commit eb7664b

Please sign in to comment.