-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Support "compile fail" tests #1194
Comments
There's a ticket for this on rust-lang/rust too |
@steveklabnik What I had in mind was that Cargo could rustc as it does for integration tests, but check for an error return code (and possibly check for specific error messages in the captured stderr output). Is any change to rustc needed for Cargo to do that? |
This is a dupe of #521, which I closed in favor of rust-lang/rust#12335. I don't think that Cargo is going to bundle its own tool to do this (when we already have one!). I'm also fairly hesitant about doing with as this means we have a stability commitment to our error messages at that point. I would expect the discussion to officially provide |
I am trying to write a test that verifies a program fails when the environment variables are not present, and I'm having a lot of trouble... 😢 I am using Command for this "integration test" and dotenv to load the environment variables. |
I know of two ways to write compile-fail tests today without making a whole new test harness:
|
cargo test
already supports unit tests and integration tests, which are similar to Rust’s own "run pass" tests. "run fail" tests can be emulated with the#[should_fail]
attribute.The missing kind is "compile fail" tests that are expected to trigger a build error. This can be useful, for example, to tests that a library that uses unsafe code internally has the correct bounds on its public API to prevent at compile-time potential incorrect usage.
(Perhaps for a second iteration, it’d be nice to check for specific rustc error messages, as in Rust’s "compile fail" tests.)
The text was updated successfully, but these errors were encountered: