-
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
Let cargo test and cargo commands with --examples ignore examples that are not for the current target #7233
Comments
ps: I haven't tested what the score is with features, but I imagine it would be handy to in/exclude examples depending on whether a feature is turned on or not. |
I have a similar problem with a crate that compiles on stable, but has examples that require nightly. Now cargo test can no longer be run on stable. |
I made some progress without modifying cargo:
I suppose a solution to #4663 would solve most of the user facing problem here. |
I'm having the similar problem, but with an example that uses |
#9208 sounds like its wanting to solve the same problem, so I'm going to close this to consolidate the conversation. If there is something that I missed, let us know! |
Describe the problem you are trying to solve
Currently
cargo test --target wasm32-unkown-unkown
will try to compile all examples. This is a problem if there is code that uses dev-dependencies that are not available on this target, like networking crates.Describe the solution you'd like
This already works for files in the
tests
directory, but not for examples:I would like to see an example ignored when it has:
#![ cfg(not( target_arch = "wasm32" )) ]
at the top of the file.Currently this throws an error like:
The only workaround I have found is to put a cfg attribute on each toplevel statement and to add a dummy main tagged with a cfg for wasm. This is problematic if you have a bunch of free standing functions and type definitions, especially since examples are a form of documentation.
Ideally also cargo would have a nice error message if a user tries to run an example on the wrong target. That is, if there is a positive cfg limiting the example to a single target, telling them to run it with
cargo run --example basic --target wasm32-unknown-unknown
and if there is a negative cfg, telling them: This example cannot run on target xxx.The text was updated successfully, but these errors were encountered: