1
Fork 0

doc tests: use the filename from the source file for doc test programs, rather than a dummy name

This commit is contained in:
Nick Cameron 2017-08-10 17:19:58 +12:00
parent 177cbe01be
commit 6d736df76b
3 changed files with 49 additions and 25 deletions

View file

@ -191,7 +191,7 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'a, I> {
.map(|l| map_line(l).for_code()) .map(|l| map_line(l).for_code())
.collect::<Vec<&str>>().join("\n"); .collect::<Vec<&str>>().join("\n");
let krate = krate.as_ref().map(|s| &**s); let krate = krate.as_ref().map(|s| &**s);
let test = test::maketest(&test, krate, false, let test = test::make_test(&test, krate, false,
&Default::default()); &Default::default());
let channel = if test.contains("#![feature(") { let channel = if test.contains("#![feature(") {
"&amp;version=nightly" "&amp;version=nightly"
@ -585,7 +585,7 @@ pub fn render(w: &mut fmt::Formatter,
.map(|l| map_line(l).for_code()) .map(|l| map_line(l).for_code())
.collect::<Vec<&str>>().join("\n"); .collect::<Vec<&str>>().join("\n");
let krate = krate.as_ref().map(|s| &**s); let krate = krate.as_ref().map(|s| &**s);
let test = test::maketest(&test, krate, false, let test = test::make_test(&test, krate, false,
&Default::default()); &Default::default());
let channel = if test.contains("#![feature(") { let channel = if test.contains("#![feature(") {
"&amp;version=nightly" "&amp;version=nightly"

View file

@ -167,16 +167,16 @@ fn scrape_test_config(krate: &::rustc::hir::Crate) -> TestOptions {
opts opts
} }
fn runtest(test: &str, cratename: &str, cfgs: Vec<String>, libs: SearchPaths, fn run_test(test: &str, cratename: &str, filename: &str, cfgs: Vec<String>, libs: SearchPaths,
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>) {
// 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 = maketest(test, Some(cratename), as_test_harness, opts); let test = make_test(test, Some(cratename), as_test_harness, opts);
let input = config::Input::Str { let input = config::Input::Str {
name: driver::anon_src(), name: filename.to_owned(),
input: test.to_owned(), input: test.to_owned(),
}; };
let outputs = OutputTypes::new(&[(OutputType::Exe, None)]); let outputs = OutputTypes::new(&[(OutputType::Exe, None)]);
@ -313,8 +313,11 @@ fn runtest(test: &str, cratename: &str, cfgs: Vec<String>, libs: SearchPaths,
} }
} }
pub fn maketest(s: &str, cratename: Option<&str>, dont_insert_main: bool, pub fn make_test(s: &str,
opts: &TestOptions) -> String { cratename: Option<&str>,
dont_insert_main: bool,
opts: &TestOptions)
-> String {
let (crate_attrs, everything_else) = partition_source(s); let (crate_attrs, everything_else) = partition_source(s);
let mut prog = String::new(); let mut prog = String::new();
@ -498,8 +501,9 @@ impl Collector {
rustc_driver::in_rustc_thread(move || { rustc_driver::in_rustc_thread(move || {
io::set_panic(panic); io::set_panic(panic);
io::set_print(print); io::set_print(print);
runtest(&test, run_test(&test,
&cratename, &cratename,
&filename,
cfgs, cfgs,
libs, libs,
externs, externs,

View file

@ -0,0 +1,20 @@
// Copyright 2017 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.
// Test that `include!` in a doc test searches relative to the directory in
// which the test is declared.
// compile-flags:--test
/// ```rust
/// include!("auxiliary/empty.rs");
/// fn main() {}
/// ```
pub struct Foo;