mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-02 15:32:06 +00:00
Use --cfg when running doctests
Previously passed --cfg was used only when collecting doctests.
This commit is contained in:
parent
9e63cecb10
commit
eb25721063
@ -261,7 +261,7 @@ pub fn main_args(args: &[String]) -> isize {
|
|||||||
|
|
||||||
match (should_test, markdown_input) {
|
match (should_test, markdown_input) {
|
||||||
(true, true) => {
|
(true, true) => {
|
||||||
return markdown::test(input, libs, externs, test_args)
|
return markdown::test(input, cfgs, libs, externs, test_args)
|
||||||
}
|
}
|
||||||
(true, false) => {
|
(true, false) => {
|
||||||
return test::run(input, cfgs, libs, externs, test_args, crate_name)
|
return test::run(input, cfgs, libs, externs, test_args, crate_name)
|
||||||
|
@ -142,13 +142,13 @@ pub fn render(input: &str, mut output: PathBuf, matches: &getopts::Matches,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Run any tests/code examples in the markdown file `input`.
|
/// 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 {
|
mut test_args: Vec<String>) -> isize {
|
||||||
let input_str = load_or_return!(input, 1, 2);
|
let input_str = load_or_return!(input, 1, 2);
|
||||||
|
|
||||||
let mut opts = TestOptions::default();
|
let mut opts = TestOptions::default();
|
||||||
opts.no_crate_inject = true;
|
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);
|
true, opts);
|
||||||
find_testable_code(&input_str, &mut collector);
|
find_testable_code(&input_str, &mut collector);
|
||||||
test_args.insert(0, "rustdoctest".to_string());
|
test_args.insert(0, "rustdoctest".to_string());
|
||||||
|
@ -85,7 +85,7 @@ pub fn run(input: &str,
|
|||||||
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
|
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
|
||||||
|
|
||||||
let mut cfg = config::build_configuration(&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_1_parse_input(&sess, cfg, &input);
|
||||||
let krate = driver::phase_2_configure_and_expand(&sess, &cstore, krate,
|
let krate = driver::phase_2_configure_and_expand(&sess, &cstore, krate,
|
||||||
"rustdoc-test", None)
|
"rustdoc-test", None)
|
||||||
@ -122,6 +122,7 @@ pub fn run(input: &str,
|
|||||||
let (krate, _) = passes::unindent_comments(krate);
|
let (krate, _) = passes::unindent_comments(krate);
|
||||||
|
|
||||||
let mut collector = Collector::new(krate.name.to_string(),
|
let mut collector = Collector::new(krate.name.to_string(),
|
||||||
|
cfgs,
|
||||||
libs,
|
libs,
|
||||||
externs,
|
externs,
|
||||||
false,
|
false,
|
||||||
@ -168,7 +169,7 @@ fn scrape_test_config(krate: &::rustc_front::hir::Crate) -> TestOptions {
|
|||||||
return opts;
|
return opts;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn runtest(test: &str, cratename: &str, libs: SearchPaths,
|
fn runtest(test: &str, cratename: &str, cfgs: Vec<String>, libs: SearchPaths,
|
||||||
externs: core::Externs,
|
externs: core::Externs,
|
||||||
should_panic: bool, no_run: bool, as_test_harness: bool,
|
should_panic: bool, no_run: bool, as_test_harness: bool,
|
||||||
opts: &TestOptions) {
|
opts: &TestOptions) {
|
||||||
@ -239,7 +240,8 @@ fn runtest(test: &str, cratename: &str, libs: SearchPaths,
|
|||||||
|
|
||||||
let outdir = TempDir::new("rustdoctest").ok().expect("rustdoc needs a tempdir");
|
let outdir = TempDir::new("rustdoctest").ok().expect("rustdoc needs a tempdir");
|
||||||
let out = Some(outdir.path().to_path_buf());
|
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 libdir = sess.target_filesearch(PathKind::All).get_lib_path();
|
||||||
let mut control = driver::CompileController::basic();
|
let mut control = driver::CompileController::basic();
|
||||||
if no_run {
|
if no_run {
|
||||||
@ -349,6 +351,7 @@ fn partition_source(s: &str) -> (String, String) {
|
|||||||
pub struct Collector {
|
pub struct Collector {
|
||||||
pub tests: Vec<testing::TestDescAndFn>,
|
pub tests: Vec<testing::TestDescAndFn>,
|
||||||
names: Vec<String>,
|
names: Vec<String>,
|
||||||
|
cfgs: Vec<String>,
|
||||||
libs: SearchPaths,
|
libs: SearchPaths,
|
||||||
externs: core::Externs,
|
externs: core::Externs,
|
||||||
cnt: usize,
|
cnt: usize,
|
||||||
@ -359,11 +362,12 @@ pub struct Collector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Collector {
|
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 {
|
use_headers: bool, opts: TestOptions) -> Collector {
|
||||||
Collector {
|
Collector {
|
||||||
tests: Vec::new(),
|
tests: Vec::new(),
|
||||||
names: Vec::new(),
|
names: Vec::new(),
|
||||||
|
cfgs: cfgs,
|
||||||
libs: libs,
|
libs: libs,
|
||||||
externs: externs,
|
externs: externs,
|
||||||
cnt: 0,
|
cnt: 0,
|
||||||
@ -384,6 +388,7 @@ impl Collector {
|
|||||||
format!("{}_{}", self.names.join("::"), self.cnt)
|
format!("{}_{}", self.names.join("::"), self.cnt)
|
||||||
};
|
};
|
||||||
self.cnt += 1;
|
self.cnt += 1;
|
||||||
|
let cfgs = self.cfgs.clone();
|
||||||
let libs = self.libs.clone();
|
let libs = self.libs.clone();
|
||||||
let externs = self.externs.clone();
|
let externs = self.externs.clone();
|
||||||
let cratename = self.cratename.to_string();
|
let cratename = self.cratename.to_string();
|
||||||
@ -399,6 +404,7 @@ impl Collector {
|
|||||||
testfn: testing::DynTestFn(Box::new(move|| {
|
testfn: testing::DynTestFn(Box::new(move|| {
|
||||||
runtest(&test,
|
runtest(&test,
|
||||||
&cratename,
|
&cratename,
|
||||||
|
cfgs,
|
||||||
libs,
|
libs,
|
||||||
externs,
|
externs,
|
||||||
should_panic,
|
should_panic,
|
||||||
|
16
src/test/rustdoc/issue-30252.rs
Normal file
16
src/test/rustdoc/issue-30252.rs
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
// 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() {}
|
Loading…
Reference in New Issue
Block a user