-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Build and test examples when invoking cargo test
#2667
Conversation
Previously, `cargo test` would only build the examples, but any tests which were inside would not get executed. If you'd prefer to not have the examples built and tested, you can modify your Cargo.toml to include: ```toml [[example]] name = "foo" path = "examples/foo.rs" test = false ```
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @alexcrichton (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
Previously `cargo test --example foo` would just build the example. If you want the old behaviour, you can use: `cargo build --example foo`
Thanks for the PR! This tweaks the current behavior where |
If we set Without introducing a new flag, or repurposing a flag, we'll have to choose between |
☔ The latest upstream changes (presumably #2670) made this pull request unmergeable. Please resolve the merge conflicts. |
Whoa I had no idea that In some sense may unit tests don't belong in unit tests? In theory example unit tests are just unit tests :) |
I'm failing to parse this line 100%, my best guess is: "tests don't belong in examples, examples are a form of unit test" so that's the interpretation I'm replying to: I think in many cases tests won't make any sense for examples, which is why opt-in is best, I think we both agree there. For reasons why it can be useful to allow some form of executed tests:
Test inclusion can be emulated using the integration-test harness by abusing the cc #2631 |
Gah sorry, you had the right interpretation, I just messed up that comment quite a bit! I guess what I mean is that if we're building and running tests in the |
Closing due to inactivity, but feel free to resubmit with a rebase! |
This patch currently only adds new behaviour of testing and doesn't move building of the examples to
cargo build
as there may be people relying on that behaviour?How should this be opt-in / Improvement to consider:
During
cargo test
we're only really using thetest
flag from the[[example]]
config to determine if we should add it to the compilation unit. But, if we don't move the building of the examples tocargo build
then perhaps we can use abuild
flag to determine if the examples get built duringcargo test
. This would allow only building and not testing examples. If we do that, shouldexample.test
be false (opt-in) by default then? (can therefore only activate it in explicit examples?)