그냥 문서 및 테스트의 두 가지 세트를 작성하고이 모든 작업으로는-입니다됩니다
/// ```
/// assert_eq!(42, dt::foo());
/// ```
#[cfg(not(feature = "alternate"))]
pub fn foo() -> u8 { 42 }
/// ```
/// assert_eq!(true, dt::foo());
/// ```
#[cfg(feature = "alternate")]
pub fn foo() -> bool { true }
$ cargo test
Compiling dt v0.1.0 (file:///private/tmp/dt)
Running target/debug/dt-c3e297f8592542b5
running 0 tests
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
Doc-tests dt
running 1 test
test foo_0 ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
$ cargo test --features=alternate
Compiling dt v0.1.0 (file:///private/tmp/dt)
Running target/debug/dt-c3e297f8592542b5
running 0 tests
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
Doc-tests dt
running 1 test
test foo_0 ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
가 doctest가 내부에'# [cfg_attr]'일을합니까? 그런 다음 ['#'] (https://doc.rust-lang.org/book/documentation.html#documentation-as-tests)로 숨길 수 있습니다. – mcarton
@Shepmaster를 편집 해 주셔서 감사합니다! –
그리고 당신의 방법은 완벽하게 작동하는 것 같습니다. 감사합니다 :) –