Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conditionally compile only one module at a time

Tags:

rust

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.

like image 639
ustulation Avatar asked Jun 17 '15 11:06

ustulation


1 Answers

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.

like image 116
Vladimir Matveev Avatar answered Nov 06 '22 00:11

Vladimir Matveev