match (should_test, markdown_input) {
(true, true) => {
- return markdown::test(input, libs, externs, test_args)
+ return markdown::test(input, cfgs, libs, externs, test_args)
}
(true, false) => {
return test::run(input, cfgs, libs, externs, test_args, crate_name)
}
/// Run any tests/code examples in the markdown file `input`.
-pub fn test(input: &str, libs: SearchPaths, externs: core::Externs,
+pub fn test(input: &str, cfgs: Vec<String>, libs: SearchPaths, externs: core::Externs,
mut test_args: Vec<String>) -> isize {
let input_str = load_or_return!(input, 1, 2);
let mut opts = TestOptions::default();
opts.no_crate_inject = true;
- let mut collector = Collector::new(input.to_string(), libs, externs,
+ let mut collector = Collector::new(input.to_string(), cfgs, libs, externs,
true, opts);
find_testable_code(&input_str, &mut collector);
test_args.insert(0, "rustdoctest".to_string());
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
let mut cfg = config::build_configuration(&sess);
- cfg.extend(config::parse_cfgspecs(cfgs));
+ cfg.extend(config::parse_cfgspecs(cfgs.clone()));
let krate = driver::phase_1_parse_input(&sess, cfg, &input);
let krate = driver::phase_2_configure_and_expand(&sess, &cstore, krate,
"rustdoc-test", None)
let (krate, _) = passes::unindent_comments(krate);
let mut collector = Collector::new(krate.name.to_string(),
+ cfgs,
libs,
externs,
false,
return opts;
}
-fn runtest(test: &str, cratename: &str, libs: SearchPaths,
+fn runtest(test: &str, cratename: &str, cfgs: Vec<String>, libs: SearchPaths,
externs: core::Externs,
should_panic: bool, no_run: bool, as_test_harness: bool,
opts: &TestOptions) {
let outdir = TempDir::new("rustdoctest").ok().expect("rustdoc needs a tempdir");
let out = Some(outdir.path().to_path_buf());
- let cfg = config::build_configuration(&sess);
+ let mut cfg = config::build_configuration(&sess);
+ cfg.extend(config::parse_cfgspecs(cfgs));
let libdir = sess.target_filesearch(PathKind::All).get_lib_path();
let mut control = driver::CompileController::basic();
if no_run {
pub struct Collector {
pub tests: Vec<testing::TestDescAndFn>,
names: Vec<String>,
+ cfgs: Vec<String>,
libs: SearchPaths,
externs: core::Externs,
cnt: usize,
}
impl Collector {
- pub fn new(cratename: String, libs: SearchPaths, externs: core::Externs,
+ pub fn new(cratename: String, cfgs: Vec<String>, libs: SearchPaths, externs: core::Externs,
use_headers: bool, opts: TestOptions) -> Collector {
Collector {
tests: Vec::new(),
names: Vec::new(),
+ cfgs: cfgs,
libs: libs,
externs: externs,
cnt: 0,
format!("{}_{}", self.names.join("::"), self.cnt)
};
self.cnt += 1;
+ let cfgs = self.cfgs.clone();
let libs = self.libs.clone();
let externs = self.externs.clone();
let cratename = self.cratename.to_string();
testfn: testing::DynTestFn(Box::new(move|| {
runtest(&test,
&cratename,
+ cfgs,
libs,
externs,
should_panic,
--- /dev/null
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// compile-flags:--test --cfg feature="bar"
+
+/// ```rust
+/// assert_eq!(cfg!(feature = "bar"), true);
+/// ```
+pub fn foo() {}