Conditionally building rust tests in the "extra" configuration #3305
stevenengler
started this conversation in
General
Replies: 1 comment 6 replies
-
I've used the option 1 ("examples") pattern before |
Beta Was this translation helpful? Give feedback.
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Shadow uses the "extra" configuration to build and run tests that we don't want to build/run by default. For example these include tor-related tests and golang-related tests. We don't want to require users to have tor or golang installed to run tests. We also don't want to add long running tests by default such as the tor tests which can take minutes to run. Finally we don't want to significantly increase the build time of the tests by default. We also would like to minimize the number of dependencies used in the default case to make maintenance easier, but maybe this doesn't mean much since Shadow already has over 100 dependencies.
A question raised by #3242 is "how do we want to build rust tests in this extra configuration?". To only run the tests in the "extra" configuration we can simply add
CONFIGURATIONS extra
to theadd_shadow_tests
cmake definition. But to only build the tests in the "extra" configuration, we need to tell Cargo to conditionally build the tests.Two possibilities might be to use Cargo feature flags or use Cargo examples, as described in (1) and (2) of this SO answer.
Use Cargo examples: Put the test's dependencies in
[dev-dependencies]
and put the test as an[[example]]
. Then you can build the examples usingcargo build --example
. Then we'd need to locate the generated binary and run it from shadow's config like we do with other tests. (Is there a consistent way to get the path to built examples like there is for built binaries?)Use Cargo feature flags: Put the test's dependencies as optional dependencies, then use an "extra" feature to enable them. You would then add the test as a
[[bin]]
like usual and userequired-features = ["extra"]
to only build it when usingcargo build --features extra
. Then we'd run it from shadow's config like we do with other tests.I don't know if there's any downsides to one approach over the other, or if there are alternatives. The two approaches above seem similar, so maybe there isn't really much to discuss.
Beta Was this translation helpful? Give feedback.
All reactions