Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/src/catch2/catch_session.cpp
diff options
context:
space:
mode:
authorMartin Hořeňovský2021-12-12 15:18:50 +0100
committerMartin Hořeňovský2021-12-18 20:49:47 +0100
commit08939cc8bb01ec84ea01d83cf03e4edb8484460c (patch)
treec76fb6b66de1a515f0bb2cbd970602263ad45bfa /src/catch2/catch_session.cpp
parent3bfe900bbc3f2f066737922c7194a8e2e27a2cda (diff)
downloadcatch3-08939cc8bb01ec84ea01d83cf03e4edb8484460c.tar.gz
Error out early if invalid test specs are provided
Diffstat (limited to 'src/catch2/catch_session.cpp')
-rw-r--r--src/catch2/catch_session.cpp41
1 files changed, 26 insertions, 15 deletions
diff --git a/src/catch2/catch_session.cpp b/src/catch2/catch_session.cpp
index ed6479e0..b50d6e48 100644
--- a/src/catch2/catch_session.cpp
+++ b/src/catch2/catch_session.cpp
@@ -25,6 +25,7 @@
#include <catch2/internal/catch_move_and_forward.hpp>
#include <algorithm>
+#include <cassert>
#include <iomanip>
#include <set>
@@ -61,24 +62,30 @@ namespace Catch {
m_config{config},
m_context{config, CATCH_MOVE(reporter)} {
- auto const& allTestCases = getAllTestCasesSorted(*m_config);
- m_matches = m_config->testSpec().matchesByFilter(allTestCases, *m_config);
- auto const& invalidArgs = m_config->testSpec().getInvalidArgs();
+ assert( m_config->testSpec().getInvalidArgs().empty() &&
+ "Invalid test specs should be handled before running tests" );
- if (m_matches.empty() && invalidArgs.empty()) {
- for (auto const& test : allTestCases)
- if (!test.getTestCaseInfo().isHidden())
- m_tests.emplace(&test);
+ auto const& allTestCases = getAllTestCasesSorted(*m_config);
+ auto const& testSpec = m_config->testSpec();
+ if ( !testSpec.hasFilters() ) {
+ for ( auto const& test : allTestCases ) {
+ if ( !test.getTestCaseInfo().isHidden() ) {
+ m_tests.emplace( &test );
+ }
+ }
} else {
- for (auto const& match : m_matches)
- m_tests.insert(match.tests.begin(), match.tests.end());
+ m_matches =
+ testSpec.matchesByFilter( allTestCases, *m_config );
+ for ( auto const& match : m_matches ) {
+ m_tests.insert( match.tests.begin(),
+ match.tests.end() );
+ }
}
m_tests = createShard(m_tests, m_config->shardCount(), m_config->shardIndex());
}
Totals execute() {
- auto const& invalidArgs = m_config->testSpec().getInvalidArgs();
Totals totals;
for (auto const& testCase : m_tests) {
if (!m_context.aborting())
@@ -94,11 +101,6 @@ namespace Catch {
}
}
- if (!invalidArgs.empty()) {
- for (auto const& invalidArg: invalidArgs)
- m_reporter->reportInvalidArguments(invalidArg);
- }
-
return totals;
}
@@ -284,6 +286,15 @@ namespace Catch {
// Create reporter(s) so we can route listings through them
auto reporter = makeReporter(m_config.get());
+ auto const& invalidSpecs = m_config->testSpec().getInvalidArgs();
+ if ( !invalidSpecs.empty() ) {
+ for ( auto const& spec : invalidSpecs ) {
+ reporter->reportInvalidArguments( spec );
+ }
+ return 1;
+ }
+
+
// Handle list request
if (list(*reporter, *m_config)) {
return 0;