私は次のようなプロジェクトのレイアウトを持っている:テストディレクトリのファイルからsrcディレクトリのファイルにアクセスするにはどうすればよいですか?
src/
int_rle.rs
lib.rs
tests/
test_int_rle.rs
プロジェクトは、cargo build
でコンパイルが、私はcargo test
でテストを実行することができません。
// src/lib.rs
pub mod int_rle;
// src/int_rle.rs
#[derive(Debug, PartialEq)]
pub struct IntRle {
pub values: Vec<i32>,
}
// tests/test_int_rle.rs
use int_rle;
#[cfg(test)]
mod tests {
#[test]
fn it_works() {
int_rle::IntRle { values: vec![1, 2, 3] }
}
}
// Cargo.toml
[package]
name = "minimal_example_test_directories"
version = "0.1.0"
authors = ["Johann Gambolputty de von Ausfern ... von Hautkopft of Ulm"]
[dependencies]
関連:私はエラー
error[E0432]: unresolved import `int_rle`. There is no `int_rle` in the crate root
--> tests/test_int_rle.rs:1:5
|
1 | use int_rle;
| ^^^^^^^
error[E0433]: failed to resolve. Use of undeclared type or module `int_rle`
--> tests/test_int_rle.rs:7:9
|
7 | int_rle::IntRle { values: vec![1, 2, 3] }
| ^^^^^^^^^^^^^^^ Use of undeclared type or module `int_rle`
error: aborting due to 2 previous errors
error: Could not compile `minimal_example_test_directories`.
私のコードを取得How do I compile a multi-file crate in Rust?(。テストおよびソースファイルが同じフォルダ内にある場合はそれを行う方法)
も '(|自己|スーパーSRC)を使用してみました:: int_rle''テスト/ test_int_rle.rs'ファイルインチ –
モジュールは、その親がアクセスできるシンボルに自動的にアクセスすることはできません。あなたは 'mod test {'の後に 'use int_rle;'を動かしてみましたか? –
この質問は、さまざまなフォルダのファイルを扱いますが、動作させることができません:http://stackoverflow.com/questions/20922091/how-do-you-use-parent-module-imports-in-rust-noredirect= 1&lq = 1(答えに私のコメントを見てください)。 –