Search code examples
catch2catch-unit-test

Combining AND and OR in Catch2 test tags


I have a set of Catch2 test cases, segregated by language and by type. For example:

TEST_CASE("zh-CN CPU test", "[zh-CN][cpu]")
{
    REQUIRE(result);
}

TEST_CASE("zh-CN verification test", "[zh-CN][ModelVerification]")
{
    REQUIRE(result);
}

TEST_CASE("zh-HK CPU test", "[zh-HK][cpu]")
{
    REQUIRE(result);
}

TEST_CASE("zh-HK verification test", "[zh-HK][ModelVerification]")
{
    REQUIRE(result);
}

TEST_CASE("zh-TW CPU test", "[zh-TW][cpu]")
{
    REQUIRE(result);
}

TEST_CASE("zh-TW verification test", "[zh-TW][ModelVerification]")
{
    REQUIRE(result);
}

What I'd like to make happen is to run just the zh-HK and zh-TW ModelVerification tests.

But from my reading of the docs, this doesn't seem to be possible.

If I say [zh-HK],[zh-TW] [ModelVerification], Catch2 will run all the zh-HK tests, all the zh-TW tests, and all the ModelVerification tests.

How can I make this happen?


Solution

  • Based on the documentation (updated since your question) it is possible.

    In stead of the (zh-HK OR zh-TW) AND ModelVerification logic you could use a (zh-HK AND ModelVerification) OR (zh-TW AND ModelVerification). In your case it would be:

    [zh-HK][ModelVerification], [zh-TW][ModelVerification]
    

    P.S. Take care of the spaces and the commas. Catch is sensitive to those.