1
Fork 0

use --edition for doctests, rather than just the crate

This commit is contained in:
QuietMisdreavus 2018-03-28 13:54:05 +02:00
parent a0e48dde7c
commit d9bf37a5ae
3 changed files with 17 additions and 8 deletions

View file

@ -446,7 +446,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, cfgs, libs, externs, test_args, maybe_sysroot, return markdown::test(input, cfgs, libs, externs, test_args, maybe_sysroot,
display_warnings, linker) display_warnings, linker, edition)
} }
(true, false) => { (true, false) => {
return test::run(Path::new(input), cfgs, libs, externs, test_args, crate_name, return test::run(Path::new(input), cfgs, libs, externs, test_args, crate_name,

View file

@ -18,6 +18,7 @@ use testing;
use rustc::session::search_paths::SearchPaths; use rustc::session::search_paths::SearchPaths;
use rustc::session::config::Externs; use rustc::session::config::Externs;
use syntax::codemap::DUMMY_SP; use syntax::codemap::DUMMY_SP;
use syntax::edition::Edition;
use externalfiles::{ExternalHtml, LoadStringError, load_string}; use externalfiles::{ExternalHtml, LoadStringError, load_string};
@ -139,7 +140,7 @@ pub fn render(input: &Path, 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, cfgs: Vec<String>, libs: SearchPaths, externs: Externs, pub fn test(input: &str, cfgs: Vec<String>, libs: SearchPaths, externs: Externs,
mut test_args: Vec<String>, maybe_sysroot: Option<PathBuf>, mut test_args: Vec<String>, maybe_sysroot: Option<PathBuf>,
display_warnings: bool, linker: Option<PathBuf>) -> isize { display_warnings: bool, linker: Option<PathBuf>, edition: Edition) -> isize {
let input_str = match load_string(input) { let input_str = match load_string(input) {
Ok(s) => s, Ok(s) => s,
Err(LoadStringError::ReadFail) => return 1, Err(LoadStringError::ReadFail) => return 1,
@ -151,7 +152,7 @@ pub fn test(input: &str, cfgs: Vec<String>, libs: SearchPaths, externs: Externs,
let mut collector = Collector::new(input.to_owned(), cfgs, libs, externs, let mut collector = Collector::new(input.to_owned(), cfgs, libs, externs,
true, opts, maybe_sysroot, None, true, opts, maybe_sysroot, None,
Some(PathBuf::from(input)), Some(PathBuf::from(input)),
linker); linker, edition);
find_testable_code(&input_str, &mut collector, DUMMY_SP, None); find_testable_code(&input_str, &mut collector, DUMMY_SP, None);
test_args.insert(0, "rustdoctest".to_string()); test_args.insert(0, "rustdoctest".to_string());
testing::test_main(&test_args, collector.tests, testing::test_main(&test_args, collector.tests,

View file

@ -123,7 +123,8 @@ pub fn run(input_path: &Path,
maybe_sysroot, maybe_sysroot,
Some(codemap), Some(codemap),
None, None,
linker); linker,
edition);
{ {
let map = hir::map::map_crate(&sess, &cstore, &mut hir_forest, &defs); let map = hir::map::map_crate(&sess, &cstore, &mut hir_forest, &defs);
@ -183,8 +184,7 @@ fn run_test(test: &str, cratename: &str, filename: &FileName, line: usize,
externs: Externs, externs: Externs,
should_panic: bool, no_run: bool, as_test_harness: bool, should_panic: bool, no_run: bool, as_test_harness: bool,
compile_fail: bool, mut error_codes: Vec<String>, opts: &TestOptions, compile_fail: bool, mut error_codes: Vec<String>, opts: &TestOptions,
maybe_sysroot: Option<PathBuf>, maybe_sysroot: Option<PathBuf>, linker: Option<PathBuf>, edition: Edition) {
linker: Option<PathBuf>) {
// the test harness wants its own `main` & top level functions, so // the test harness wants its own `main` & top level functions, so
// never wrap the test in `fn main() { ... }` // never wrap the test in `fn main() { ... }`
let (test, line_offset) = make_test(test, Some(cratename), as_test_harness, opts); let (test, line_offset) = make_test(test, Some(cratename), as_test_harness, opts);
@ -210,6 +210,10 @@ fn run_test(test: &str, cratename: &str, filename: &FileName, line: usize,
}, },
test: as_test_harness, test: as_test_harness,
unstable_features: UnstableFeatures::from_environment(), unstable_features: UnstableFeatures::from_environment(),
debugging_opts: config::DebuggingOptions {
edition,
..config::basic_debugging_options()
},
..config::basic_options().clone() ..config::basic_options().clone()
}; };
@ -473,13 +477,14 @@ pub struct Collector {
codemap: Option<Lrc<CodeMap>>, codemap: Option<Lrc<CodeMap>>,
filename: Option<PathBuf>, filename: Option<PathBuf>,
linker: Option<PathBuf>, linker: Option<PathBuf>,
edition: Edition,
} }
impl Collector { impl Collector {
pub fn new(cratename: String, cfgs: Vec<String>, libs: SearchPaths, externs: Externs, pub fn new(cratename: String, cfgs: Vec<String>, libs: SearchPaths, externs: Externs,
use_headers: bool, opts: TestOptions, maybe_sysroot: Option<PathBuf>, use_headers: bool, opts: TestOptions, maybe_sysroot: Option<PathBuf>,
codemap: Option<Lrc<CodeMap>>, filename: Option<PathBuf>, codemap: Option<Lrc<CodeMap>>, filename: Option<PathBuf>,
linker: Option<PathBuf>) -> Collector { linker: Option<PathBuf>, edition: Edition) -> Collector {
Collector { Collector {
tests: Vec::new(), tests: Vec::new(),
names: Vec::new(), names: Vec::new(),
@ -494,6 +499,7 @@ impl Collector {
codemap, codemap,
filename, filename,
linker, linker,
edition,
} }
} }
@ -513,6 +519,7 @@ impl Collector {
let opts = self.opts.clone(); let opts = self.opts.clone();
let maybe_sysroot = self.maybe_sysroot.clone(); let maybe_sysroot = self.maybe_sysroot.clone();
let linker = self.linker.clone(); let linker = self.linker.clone();
let edition = self.edition;
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 {
@ -543,7 +550,8 @@ impl Collector {
error_codes, error_codes,
&opts, &opts,
maybe_sysroot, maybe_sysroot,
linker) linker,
edition)
})) }))
} { } {
Ok(()) => (), Ok(()) => (),