Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make Cargo run tests for local dependencies?

I'm working on a project split across multiple crates. The top-level crate (the app) requires the two other crates (libraries) as dependencies. Running cargo test in the top-level crate builds the dependencies and runs tests for the top-level crate, but it doesn't run tests for the two other crates. Is there a way to configure cargo test so that it will run tests in all three crates?

Thanks!

like image 681
Eliza Weisman Avatar asked Feb 09 '15 18:02

Eliza Weisman


1 Answers

You can pass the -p parameter to make Cargo run the tests of a dependency.

So, if your crate is called sublib, you can run its tests using:

cargo test -p sublib

From cargo test --help:

-p SPEC, --package SPEC Package to run tests for

If the --package argument is given, then SPEC is a package id specification which indicates which package should be tested. If it is not given, then the current package is tested. For more information on SPEC and its format, see the cargo help pkgid command.

like image 103
Renato Zannon Avatar answered Nov 08 '22 15:11

Renato Zannon