Skip to content

Commit

Permalink
Auto merge of rust-lang#73842 - euclio:doctest-expn, r=GuillaumeGomez
Browse files Browse the repository at this point in the history
Use outermost invocation span for doctest names

Fixes rust-lang#70090.

This PR also allows using aux-build files in rustdoc-ui tests.
  • Loading branch information
bors committed Aug 7, 2020
2 parents 8b26609 + 6088079 commit 1e0e618
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 7 deletions.
7 changes: 6 additions & 1 deletion src/librustdoc/test.rs
Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions src/test/rustdoc-ui/auxiliary/extern_macros.rs
@@ -0,0 +1,7 @@
#[macro_export]
macro_rules! attrs_on_struct {
( $( #[$attr:meta] )* ) => {
$( #[$attr] )*
pub struct ExpandedStruct;
}
}
12 changes: 12 additions & 0 deletions src/test/rustdoc-ui/doctest-output.rs
@@ -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
Expand All @@ -6,10 +8,20 @@
//! assert_eq!(1 + 1, 2);
//! ```

extern crate extern_macros as macros;

use macros::attrs_on_struct;

pub mod foo {

/// ```
/// assert_eq!(1 + 1, 2);
/// ```
pub fn bar() {}
}

attrs_on_struct! {
/// ```
/// assert!(true);
/// ```
}
9 changes: 5 additions & 4 deletions src/test/rustdoc-ui/doctest-output.stdout
@@ -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

2 changes: 1 addition & 1 deletion src/tools/compiletest/src/common.rs
Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion src/tools/compiletest/src/runtest.rs
Expand Up @@ -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 {
Expand Down Expand Up @@ -3573,6 +3574,7 @@ impl ProcRes {
}
}

#[derive(Debug)]
enum TargetLocation {
ThisFile(PathBuf),
ThisDirectory(PathBuf),
Expand Down

0 comments on commit 1e0e618

Please sign in to comment.