Auto merge of #73842 - euclio:doctest-expn, r=GuillaumeGomez

Use outermost invocation span for doctest names

Fixes #70090.

This PR also allows using aux-build files in rustdoc-ui tests.
This commit is contained in:
bors 2020-08-07 11:38:17 +00:00
commit 1e0e618cfb
6 changed files with 34 additions and 7 deletions

View file

@ -943,7 +943,12 @@ impl<'a, 'hir, 'tcx> HirCollector<'a, 'hir, 'tcx> {
// The collapse-docs pass won't combine sugared/raw doc attributes, or included files with
// anything else, this will combine them for us.
if let Some(doc) = attrs.collapsed_doc_value() {
self.collector.set_position(attrs.span.unwrap_or(DUMMY_SP));
// Use the outermost invocation, so that doctest names come from where the docs were written.
let span = attrs
.span
.map(|span| span.ctxt().outer_expn().expansion_cause().unwrap_or(span))
.unwrap_or(DUMMY_SP);
self.collector.set_position(span);
markdown::find_testable_code(
&doc,
self.collector,

View file

@ -0,0 +1,7 @@
#[macro_export]
macro_rules! attrs_on_struct {
( $( #[$attr:meta] )* ) => {
$( #[$attr] )*
pub struct ExpandedStruct;
}
}

View file

@ -1,3 +1,5 @@
// edition:2018
// aux-build:extern_macros.rs
// compile-flags:--test --test-args=--test-threads=1
// normalize-stdout-test: "src/test/rustdoc-ui" -> "$$DIR"
// check-pass
@ -6,6 +8,10 @@
//! assert_eq!(1 + 1, 2);
//! ```
extern crate extern_macros as macros;
use macros::attrs_on_struct;
pub mod foo {
/// ```
@ -13,3 +19,9 @@ pub mod foo {
/// ```
pub fn bar() {}
}
attrs_on_struct! {
/// ```
/// assert!(true);
/// ```
}

View file

@ -1,7 +1,8 @@
running 2 tests
test $DIR/doctest-output.rs - (line 5) ... ok
test $DIR/doctest-output.rs - foo::bar (line 11) ... ok
running 3 tests
test $DIR/doctest-output.rs - (line 7) ... ok
test $DIR/doctest-output.rs - ExpandedStruct (line 23) ... ok
test $DIR/doctest-output.rs - foo::bar (line 17) ... ok
test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

View file

@ -169,7 +169,7 @@ impl fmt::Display for Debugger {
}
/// Configuration for compiletest
#[derive(Clone)]
#[derive(Debug, Clone)]
pub struct Config {
/// `true` to to overwrite stderr/stdout files instead of complaining about changes in output.
pub bless: bool,

View file

@ -1885,7 +1885,8 @@ impl<'test> TestCx<'test> {
emit_metadata: EmitMetadata,
allow_unused: AllowUnused,
) -> Command {
let is_rustdoc = self.is_rustdoc();
let is_aux = input_file.components().map(|c| c.as_os_str()).any(|c| c == "auxiliary");
let is_rustdoc = self.is_rustdoc() && !is_aux;
let mut rustc = if !is_rustdoc {
Command::new(&self.config.rustc_path)
} else {
@ -3573,6 +3574,7 @@ impl ProcRes {
}
}
#[derive(Debug)]
enum TargetLocation {
ThisFile(PathBuf),
ThisDirectory(PathBuf),