Catch2 icon indicating copy to clipboard operation
Catch2 copied to clipboard

Support for the number of test cases running inside IEventListener

Open dansandu opened this issue 2 years ago • 0 comments

Description I'm writing a progress bar for the tests and it would be nice to have the total number of test cases to be executed inside the IEventListener constructor or IEventListener::testRunStarting method.

Additional context I was able to achieve this by copy/pasting code from the TestGroup constructor to the IEventListener implementation but this is not a nice solution.

auto tests = std::set<Catch::TestCaseHandle const*>{};
auto const& allTestCases = getAllTestCasesSorted(*m_config);
auto const& testSpec = m_config->testSpec();
if (!testSpec.hasFilters())
{
    for (auto const& test : allTestCases)
    {
        if (!test.getTestCaseInfo().isHidden())
        {
            tests.emplace(&test);
        }
    }
}
else
{
    auto matches = testSpec.matchesByFilter(allTestCases, *m_config);
    for (auto const& match : matches)
    {
        tests.insert(match.tests.begin(), match.tests.end());
    }
}
m_testCount = tests.size();

dansandu avatar Apr 20 '23 01:04 dansandu