catch2 run all untagged tests plus hidden ones with specific tags

Viewed 28

I'm trying to tag all tests that send real network requests with [.network] so that they don't run by default. My hope was that I could optionally include them to be ran in addition to all my untagged tests; but I have not been able to figure out how to do this or if it is even possible.

Say I organize my tests like this:

TEST_CASE("Foo") { ... }
TEST_CASE("Bar") { ... }
TEST_CASE("Baz", [.optional]) { ... }
TEST_CASE("Qux", [.different-optional]) { ... }

When my test exe is run without any additional parameters, I want Foo and Bar to run. This is working correctly.

However I would like to invoke my test exe such that I can still run all untagged tests, but also include specific tags

E.g.:

  • ./tests include:[.optional] would run Foo Bar and Baz
  • ./tests include:[.different-optional] would run Foo Bar and Qux
  • ./tests include:[.optional],include:[.different-optional] would run Foo Bar Baz and Qux

(I know include: isn't a keyword, I'm just illustrating the behavior I'm looking for)

Is this possible without having to add some [all] or [default] tag to all my other tests?

Edit:

I had a brief moment of hope, turns out catch2 has support for the empty tag []

So in the example above, running ./tests [] will run Foo and Bar.

Unfortunately, the empty tag seems to be ignored when combined with the comma , separator.

So ./tests [],[.optional] still only runs Baz

0 Answers
Related