rustdoc: set cfg(doctest) when collecting doctests
This commit is contained in:
parent
b0bd5f236d
commit
bed54cf854
9 changed files with 77 additions and 3 deletions
|
|
@ -5,6 +5,8 @@
|
|||
// Crates like core have doctests gated on `cfg(not(test))` so we need to make
|
||||
// sure `cfg(test)` is not active when running `rustdoc --test`.
|
||||
|
||||
#![feature(cfg_doctest)]
|
||||
|
||||
/// this doctest will be ignored:
|
||||
///
|
||||
/// ```
|
||||
|
|
@ -20,3 +22,11 @@ pub struct Foo;
|
|||
/// ```
|
||||
#[cfg(not(test))]
|
||||
pub struct Foo;
|
||||
|
||||
/// this doctest will be tested, but will not appear in documentation:
|
||||
///
|
||||
/// ```
|
||||
/// assert!(true)
|
||||
/// ```
|
||||
#[cfg(doctest)]
|
||||
pub struct Bar;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
|
||||
running 1 test
|
||||
test $DIR/cfg-test.rs - Foo (line 18) ... ok
|
||||
running 2 tests
|
||||
test $DIR/cfg-test.rs - Foo (line 20) ... ok
|
||||
test $DIR/cfg-test.rs - Bar (line 28) ... ok
|
||||
|
||||
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
|
||||
test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
|
||||
|
||||
|
|
|
|||
8
src/test/rustdoc/cfg-doctest.rs
Normal file
8
src/test/rustdoc/cfg-doctest.rs
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#![feature(cfg_doctest)]
|
||||
|
||||
// @!has cfg_doctest/struct.SomeStruct.html
|
||||
// @!has cfg_doctest/index.html '//a/@href' 'struct.SomeStruct.html'
|
||||
|
||||
/// Sneaky, this isn't actually part of docs.
|
||||
#[cfg(doctest)]
|
||||
pub struct SomeStruct;
|
||||
4
src/test/ui/feature-gate/feature-gate-cfg_doctest.rs
Normal file
4
src/test/ui/feature-gate/feature-gate-cfg_doctest.rs
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
#[cfg(doctest)] //~ ERROR
|
||||
pub struct SomeStruct;
|
||||
|
||||
fn main() {}
|
||||
12
src/test/ui/feature-gate/feature-gate-cfg_doctest.stderr
Normal file
12
src/test/ui/feature-gate/feature-gate-cfg_doctest.stderr
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
error[E0658]: `cfg(doctest)` is experimental and subject to change
|
||||
--> $DIR/feature-gate-cfg_doctest.rs:1:7
|
||||
|
|
||||
LL | #[cfg(doctest)]
|
||||
| ^^^^^^^
|
||||
|
|
||||
= note: for more information, see https://github.com/rust-lang/rust/issues/62210
|
||||
= help: add #![feature(cfg_doctest)] to the crate attributes to enable
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0658`.
|
||||
Loading…
Add table
Add a link
Reference in a new issue