-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Add new SKIP macro for skipping tests at runtime #2360
Conversation
Codecov Report
@@ Coverage Diff @@
## devel #2360 +/- ##
==========================================
+ Coverage 91.13% 91.15% +0.01%
==========================================
Files 187 187
Lines 7634 7691 +57
==========================================
+ Hits 6957 7010 +53
- Misses 677 681 +4 |
This is going to take awhile to review, I don't think I will really get to this before next weekend. |
TEST_CASE( "sections can be skipped dynamically at runtime", "[skipping]" ) { | ||
SECTION( "not skipped" ) { SUCCEED(); } | ||
SECTION( "skipped" ) { SKIP(); } | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to see a SECTION
after the skipped one as well.
I think that skipped tests should not count as failures, nor should they This has some consequences, such as if a test run only invokes skipped tests, However, it might be useful to add a warning ( From this also follows what should happen when a section/generator input TEST_CASE() {
CHECK(1 == 2);
SKIP();
REQUIRE(1 == 2);
} then that test case should be counted as failed. Further examples: TEST_CASE() {
SECTION("A") { std::cout << "A\n"; }
SECTION("B") { SKIP(); }
SECTION("C") { std::cout << "C\n"; }
} Should print out "A\n" and "C\n", and similarly TEST_CASE() {
SECTION("A") { std::cout << "A"; }
SECTION("B") {
SECTION("B1") { std::cout << "B1"; }
SECTION("B2") { SKIP(); }
}
std::cout << "\n";
} should print out "A\n" and "B1\n", and nothing more. (Generally exits As to the other parts, "skipped assertions" should definitely not be Also I have no idea what to do about the existing |
If the section tracking proves trouble some, I am willing to say that test skips can only happen at the top of a TEST_CASE() {
auto i = GENERATE( ... );
if (i % 2 == 1) { SKIP(); }
} |
Thank you, I will need some time to investigate how to best address all your points.
Would you in principle be open to repurposing that hook for the |
Yes, but it would also likely need to be renamed and further changed, as the SKIP granularity is at section level, not test case level. |
Sorry for the delay. After looking back into this now, it seems like not too many things need changing after all. I've rebased onto current Skipping BehaviorI think the initial version of this PR already mostly did what you expected in your examples. I've added a few more test cases to better cover these scenarios.
Not sure I'm following. If there were a
Again I'm not sure I understand why I would need to do section tracking manually; by treating Exit CodeI've adjusted things to return a non-zero exit code (4) when tests were run, but all of them ended up being skipped. Do we want something analogous to I've also added a new test case for this behavior, however I'm not sure whether "ExtraTests" is the right location for it. Also I have no idea what the whole Hooks
Turns out I don't actually have a use case for a hook when |
I‘d be happy to see this feature in Catch2 at some point in time. I have a similar use case, namely skipping some test cases at runtime if certain ressources (in my case some attached sensors) are not availabe. |
de84f7a
to
3d1225c
Compare
I am finally back around for long enough to go through the larger PRs. I rebased the PR and will pick it up during this week. Sorry for the long wait 😃 |
Thanks for looking into this again, let me know if you need anything! |
@psalz I read through it again today, I think the changes are fine, but the other reporters need to have a better support for skipping. I tried a few, and the output is not very useful, e.g.
The 0 passed, all green output is confusing, especially when combined with the return code being 4 (because all selected tests were skipped).
XML reporter should provide all available information, because it implements Catch2-specific output format to be used for machine parsing of the output.
I am not sure if this is the best we can do, see below. In total, there are 8 built-in reporters.
And 5 implement specific format we do not control.
|
I also went to the original post (this is a very high quality PR btw) and
I don't think this is useful. While skips are not counted as errors, I think we should report them by default, as they are an indicator of potential issue. E.g. if the dynamic check for whether the test should be skipped is wrong, the user might end up with a test that never actually runs. OTOH, there might be some use for an option that turns skipped tests into failures, instead of passes, for similar reasons. |
I started looking at the reporter formats. TeamCity - I think the Ignored tests message matches up with the intent of Went through all the 3rd party format reporters, and I am pleasantly surprised that all of them support concept of reporting skipped tests. See my previous post with list of reporters for notes. |
re the flag to turn |
f8ea0db
to
60a01b6
Compare
Rebased onto #2554. Apologies for being a bit slow on this right now, I will try to find some time to look into the other reporters. |
Don't worry, you will have to be waaaay slower before the PR has spent more time waiting on you than it has waiting on me. |
Do you have an idea about when you are going to have time to finish this? I am planning next release and wondering whether I should wait for this or not. |
Tough to say, I have a pretty busy month ahead unfortunately. Maybe I can find some time next weekend. I briefly looked into it yesterday and ran into a couple of issues where I need clarification:
|
No problem, I'll pull in things I want to have in the next release and plan for this to be in a later one.
|
60a01b6
to
2841d77
Compare
Okay, back with some time to work on this! I've rebased onto current devel and added support for skipped tests into all reporters. Here's some notes on each:
|
Nice, just yesterday I was thinking that when I find some time, I should finish this PR. Some preliminary notes
|
Right, it seems that's due to the approval test script being a bit too overzealous in stripping out file paths though. You'll notice that the existing TeamCity baselines already don't include any |
Hmmm, you are right. Should be fixed on devel now 😃 |
I looked at the SonarQube reporter. Do you think the current reporter does not obey the example outside the extended result tag? It was originally contributed by someone working with SonarQube, so I assume that works 🤷 Otherwise I think this is done after a rebase for the new approvals. (nevermind, docs need to be done first) |
This adds a new `SKIP` macro for dynamically skipping tests at runtime. The "skipped" status of a test case is treated as a first-class citizen, like "succeeded" or "failed", and is reported with a new color on the console.
Also extend skip tests to cover a few more use cases.
This isn't great, but is better than the deep blue that was borderline invisible on dark backgrounds. The fix is to redo the colouring a bit, including introducing light-blue that is actually visible.
a411826
to
c1e522a
Compare
I've rebased onto current I've also reformatted
No I think then it's fine, I was referring to the extended result tag. |
c1e522a
to
6309b3c
Compare
I think this is done. I wrote some follow ups into my TODO list, e.g.
Yes, but it needs to be configurable, so the deprecation can be disabled via preprocessor, letting the users deal with this when they can. I'd prefer that to be done later, especially since there is more stuff in Catch2 that will get this treatment. Do you want to clean up the commits, or are you fine with me squashing the PR? |
Fine with me, squash away! :) |
This adds a new
SKIP
macro for dynamically skipping tests at runtime. The "skipped" status of a test case is treated as a first-class citizen, like "succeeded" or "failed", and is reported with a new color on the console.This is useful when the conditions for skipping a test are only known at runtime. For example:
The output will then look like this:
Like other non-assertion type macros (such as
INFO
andWARN
), skipping is still implemented as an "assertion" internally. I've added a new result typeExplicitSkip
(which is currently not treated as a failure) as well as a newskipped
counter inCatch::Totals
. While this initial implementation was surprisingly simple, I've marked the PR as a draft as there are still several outstanding design questions.For example, the result type is called an explicit skip because there already exists the notion of a "skipped" test in the current codebase. In fact, there are at least 3 conditions under which tests could be considered as skipped:
[.]
)--abortx
limit has been reachedThe last one is currently explicitly referred to as "skipped" within the
IStreamingReporter::skipTest
hook. As far as I can tell, only the Automake reporter is actually handling this one though. I'm wondering whether there is an opportunity here for unifying (some) of these concepts in both how they are handled internally as well as the way they are being reported.Open TODOs:
IStreamingReporter::skipTest
)-s
)Catch::Totals::delta
), but the terminology feels a bit weird.Resolves #395.