Why is my test subfile not found?

I have a submodule for tests with the following structure. When I run cargo test I get an error:
file not found for module test_chunk can someone explain this? I looked into the rust book but didnt find my error.

bytecode_interpreter
--Cargo.lock
--Cargo.toml
--src/
----common.rs
----main.rs
----tests.rs
----lib.rs
----tests/
------test_chunk
----target

then I have separated the test file into a subdirectory like done in the rust book:

//lib.rs
mod common;


#[cfg(test)]
mod tests;
//tests.rs
mod test_chunk;
//test_chunk.rs
use common;


#[test]
fn test_write_chunk() {
    let chunk = CodeChunk::new();
    chunk.write_chunk(chunk,common::OpCode::OpConstant, 0);
    asserteq!(chunk.code[0] == common::OpCode::Halt)
}

It looks like this filename is missing the .rs extension.

ouch thank you!

can you tell me why use common; is not found as module? I corrected the file to test_chunk.rs

common is at the top level of your crate. In the tests::test_chunk module, you can refer to it by its absolute path:

use crate::common;
// `crate` is a special name that means “root of this crate’s module tree.”

or by a relative path:

use super::super::common;
// `super` means “parent of this module” (similar to `..` in file paths). 

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.