Sometimes while refactoring a change in one of the modules has impact on every other module (or many others), because say a type has been changed or a function parameter has been changed etc. In this case instead of changing everything and then compiling at once is there a way i can compile and run unit tests for only that particular module, tweak it to hearts content and when all is right changed the other modules etc and run the complete/normal cargo build/test
? Of-course one of the ways could be to manually comment/uncomment the module listings in their corresponding root module that introduces them, but is there any other way directly from say cargo test --someflag -only_this_module
or something ?
Explaining More:
say I have following modules:
a, b, c, d, e, f, g, h
where f
depends only on g
and h
but rest of a, b, c, d, e
depend on f
(and maybe g
and h
but that should not matter). g
and h
ofcourse dont depend on anything from above. So if i make a change to f
i want to compile only f
and test it without changing all of them. Since f
depends only on g
and h
i assume that if things are fine with these three then i should be able to test f
even though a, b ... e
are broken and crate will not compile if i do the normal cargo build/test
. Is this possible.
You can run tests specifically for one module by providing it as an argument to the test binary. Cargo passes arguments to the test binary if you specify it after --
, so something like this should work:
cargo test -- module::you::want::to::test
However, you can't compile only a part of a crate. Crates in Rust are units of compilation, like .c
files in C, and you can't compile a half of it and ignore the other half.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With