Closed

Description
- I have checked the latest
main
branch to see if this has already been fixed - I have searched existing issues and pull requests for duplicates
URL to the section(s) of the book with this problem: https://doc.rust-lang.org/book/ch11-03-test-organization.html
Description of the problem:
Copying the content of the tests/common.rs file (subsequently tests/common/mod.rs) from the book includes hidden lines:
#![allow(unused)]
fn main() {
pub fn setup() {
// setup code specific to your library's tests would go here
}
}
The chapter tells the user to include this in the integration_test.rs file with mod common;
This is fine, however, running the test fails due to the scoping of the setup function within the block of fn main(). The error is:
cargo test 302ms Mon Jan 17 15:35:08 2022
Compiling adder v0.1.0 (/Users/{PATH_TO_ADDER}/adder)
error[E0425]: cannot find function `setup` in module `common`
--> tests/integration_test.rs:7:13
|
7 | common::setup();
| ^^^^^ not found in `common`
For more information about this error, try `rustc --explain E0425`.
error: could not compile `adder` due to previous error
Suggested fix:
The content of mod.rs should just be
#![allow(unused)]
pub fn setup() {
// setup code specific to your library's tests would go here
}