-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Proof of concept: implement test ignore-by-panic #96574
Conversation
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
r? @notriddle (rust-highfive has picked a reviewer for you, use r? to override) |
@rustbot modify labels +T-libs -T-lang whoops typed the wrong thing |
Per highfive I guess I should also r? rust-lang/libs-api @rustbot label +T-libs-api -T-libs |
|
This also relates to #68007 |
I think probably the best way to handle the doctest wrapping will probably be an It still requires stabilizing the macro or magicking up some way of injecting it without impacting user code, but I do think it'd be useful to use. But that's not really the point of this PR. |
I've also heard folks requesting a feature to allow them to mark a test as failed without returning/exiting/panicking just yet. That makes me wonder if that should use the same feature as a dynamic ignore feature. For example, something like: // to ignore:
test::set_result(TestResult::Ignored, "message");
return; // to fail, but continue checking other checks in the same test:
test::set_result(TestResult::Failed, "message"); (cc @de-vri-es for It's not clear to me this would be a better solution, as it might be tricky to define what happens when different results are set this way, or when the test panics after setting a result. But I do think we should consider other use cases of dynamically picking a test result before deciding to go for the |
Yes, I would love a way to mark a test as failed without panicking. For An easy choice for dealing with conflicting results would simply be to panic, which would end up failing the test. However, for |
As per discussion in rust-lang/rfcs#3221 the two issues here are requirement for |
This PR is a mechanism for signalling an ignore during runtime, but I suspect that the actual API might look more like
I mean, initially, it's going to be feature gated anyway, so while this is something that needs to be resolved for stabilization, it doesn't need to block implementation. I don't see a way to properly expose this feature without stabilizing (minimally the existence of) the test support crate, though. You could provide the APIs as part of |
The linked draft RFC proposes extending the fn missing_avx_support() -> bool {
!std::is_x86_feature_detected!("avx")
}
#[test]
#[ignore(if = missing_avx_support, reason = "missing AVX support")]
fn test_memcpy_avx() {
// ...
} My worry with requiring |
Ultimately, I consider a more declarative interface like
#[test]
fn with_panic() {
let chrome = match headless_chrome::start() {
Ok(chrome) => chrome,
Err(err) => test::abort(format!("headless chrome is not available: {err}")),
}
// do test
} #[test]
#[ignore(if = headless_chrome::exists, reason = "headless chrome is not available")]
fn with_if() {
let chrome = match headless_chrome::start() {
Ok(chrome) => chrome,
Err(err) => panic!("headless chrome is not available: {err}"),
}
// do test
} This is especially important for
|
Hi @m-ou-se, @de-vri-es ,
The following solution may help them, and I believe that ignoring runtime is a different issue. Changing #[cfg(test)]
#[test]
mod infra {
#[test]
fn test_infra_works () {...}
#[test]
fn test_infra_fail () {...}
}
Because it is a different scenario, could we consider ignore-by-panic without setting test fail on runtime? |
@yanganto |
Hi @Boegie19, Thanks for the advice.
and also address #68007, which wants to ignore the test in
As you can see, we are just trying to provide some proposals here, and we do not have the power to make sure everything will happen. Such that #68007 was opened more than two years but there is no solution fully accepted to solve it now. Nevertheless, it is always a good try to make this better, because we love to use Rust to solve problems in a smart way and keep safe at the same time. |
Hi @yanganto My previous message
was as a reaction to
what you suggested in this post should be under a cargo argument and this should also probably be an other pr ;) |
(triaging my open PRs) I'm going to close this PR for now. The implementation baseline can likely be reused in the future (is there a place to collect closed-but-potentially-interesting PRs?), but I think a different API surface should be pursued. Namely:
|
Implements dynamic ignoring of tests via
panic_any(IgnoreTest { reason })
. Additionally, does the work to pass through the ignored status via exit code across the process boundary in order to support doing so both in process-isolatedcargo test
tests and rustdoc documentation tests.The actual API might look like
panic_any(test::IgnoreTest { reason })
ortest::ignore(reason) -> !
; I've just implemented the mechanism.I know this has been asked about before, though I can't find references at the moment.
The sketchiest part is enabling this in rustdoc, since it needs to inject uses of unstable API into the doctest. I've gone for the hacky solution of only enabling it when an attribute
feature(test)
andextern crate test;
are both present in the test but would appreciate advice here on a better way to gate this. Just always adding the extra shim on the nightly toolchain isn't the most desirable, as then doctests would be able to usefeature(test)
without explicitly saying#![feature(test)]
.@rustbot modify labels +T-lang +T-rustdoc