如何在功能门控实现中运行doc测试?

问题描述 投票:1回答:1

我注意到如果你在特征实现周围有像#[feature(cfg = "nightly")]这样的特征门,那么即使在每晚的cargo test上调用rustc也会跳过doctest。我试过cargo test --all-features,但结果是一样的。 (当然,注释掉门会导致测试运行。)我也没有在Rust Reference中看到任何关于此的内容。

您如何确保对功能门控实现的测试运行?

作为参考,这是我的工作Rust版本。

rustc 1.17.0-nightly (c0b7112ba 2017-03-02)
binary: rustc
commit-hash: c0b7112ba246d96f253ba845d91f36c0b7398e42
commit-date: 2017-03-02
testing documentation rust
1个回答
0
投票

必须始终明确选择不属于default集的功能。您可以通过在命令行传递参数或将它们列在[dependencies]部分(如果它们是依赖项)来实现。

SRC / lib.rs

/// ```
/// assert!(false);
/// ```
#[cfg(feature = "nightly")]
trait Foo {}

Cargo.toml

[package]
name = "wuzzy"
version = "0.1.0"
authors = ["An Devloper <[email protected]>"]

[features]
nightly = []

运行cargo test --features=nightly导致断言触发,cargo test忽略测试。这一切都适用于稳定的Rust。

$ cargo test --features=nightly
   Doc-tests wuzzy

running 1 test
test src/lib.rs - Foo (line 1) ... FAILED

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured

$ cargo test
   Doc-tests wuzzy

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
© www.soinside.com 2019 - 2024. All rights reserved.