mod simulation;
use simulation::factory::FactoryType;
在main.rs
工作正常,但不是在裏面simulation/factory.rs
一個文檔測試:如何在doctest中使用自定義模塊?
impl product_type::ProductType for FactoryType {
/// Lorem Ipsum
///
/// # Examples
///
/// ```
/// use simulation::factory::FactoryType;
///
/// ...
/// ```
fn human_id(&self) -> &String {
...
}
}
cargo test
給我的錯誤
---- simulation::factory::human_id_0 stdout ----
<anon>:2:9: 2:19 error: unresolved import `simulation::factory::FactoryType`. Maybe a missing `extern crate simulation`?
<anon>:2 use simulation::factory::FactoryType;
^~~~~~~~~~
error: aborting due to previous error
thread 'simulation::factory::human_id_0' panicked at 'Box<Any>', /home/rustbuild/src/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libsyntax/diagnostic.rs:192
我怎樣才能得到文檔測試工作?
如果你正在創建一個二進制文件(例如,如果你有'src/main.rs'而不是'src/lib.rs'),那麼你不能在doctest中使用它的函數:doc tests import他們來自一個圖書館(如果它是一個)。 – huon
請求幫助時,請花時間創建[MCVE](/ help/mcve)。正如你現在所說的你的問題,我們必須做很多猜測才能確切地知道存在什麼。 – Shepmaster