Skip to content
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

Skip subcase #304

Closed
websocket98765 opened this issue Oct 18, 2019 · 4 comments
Closed

Skip subcase #304

websocket98765 opened this issue Oct 18, 2019 · 4 comments

Comments

@websocket98765
Copy link

websocket98765 commented Oct 18, 2019

Description

This is a question and possible feature request.

Is it possible to skip subcases?

From the docs, it appears that only TEST_SUIT and TEST_CASE can be skipped. https://github.com/onqtam/doctest/blob/master/doc/markdown/testcases.md#decorators

The use case for this is the ability to skip the smallest unit of test, as opposed to needing to skip a TEST_CASE which may contain multiple SUBCASE's.

Extra information

  • doctest version: 2.3.5
  • Operating System: Linux
  • Compiler+version: gcc 9.2
@onqtam
Copy link
Member

onqtam commented Oct 18, 2019

You could do that using the --subcase-exclude=<pattern> command line option to filter specific subcases by name (and could also provide your own main() where you set that filter by default).

Let me know if this helps :)

@websocket98765
Copy link
Author

Very helpful! I'll probably set up something like this to have consistency and brevity for all three:

./test --test-suite-exclude="*_SKIP_*" --test-case-exclude="*_SKIP_*" --subcase-exclude="*_SKIP_*"

(Something like that could make a good default filter. From a user perspective, it would make test code a tad cleaner than * doctest::skip(true) and is super easy to remember how to skip tests.)

Thanks for the tip!

@amdjachenko
Copy link

I have similar needs, but I would like to skip subcase conditionally based on the result of previous subcase(s). More specifically, I have a static variable in a WHEN section that contains 2 THEN sections. When first THEN passes at the last statement is sets data to the static variable. The following THEN section should only run if that variable is set. The first idea that came to my mind was like THEN("name" * doctest::skip(!!staticVar)) but decorators only work with TEST_CASE but not with subcases.

In my case I test serialization/deserialization pair of method. So if serialization fails then there is no sence to test deserialization. Also I uses output made by serialization as input for deserialization. I understand it is not easy to pass data from one subcase to another so static variable is ok for me as a workaround. Sure I can add simple check of static variable inside the second THEN and just return if it is not set, but I would like that the subcases isn't run instead to not polute/lie in output about success of the second THEN subcase.

@obewan
Copy link

obewan commented Apr 27, 2024

I've try to do SUBCASE("My test" * doctest::skip(true)) thinking it will work but it doesn't, could be great if it could work.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants