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

summaryrefslogtreecommitdiffhomepage
path: root/src/Progmasoft/Catch3/TestSpec.cpp
diff options
context:
space:
mode:
authorLeitwolf2026-10-25 10:31:36 +0300
committerGitHub2026-10-25 10:31:36 +0300
commitd2e3e074bb2e1b8ffd9fc990d0b87667ea602f58 (patch)
tree0bce4462b2e190c39b3e1c5f697e3e4abd1a5e2a /src/Progmasoft/Catch3/TestSpec.cpp
parent13f81a480a93807c14dddb5abdb97355ced4d4c5 (diff)
parent126dc333564cb72b5115d9a9242d66694694b6d0 (diff)
downloadcatch3-d2e3e074bb2e1b8ffd9fc990d0b87667ea602f58.tar.gz
Merge pull request #18 from Progmasoft/build/catch3-identity
Give Catch3 its own build names and headers
Diffstat (limited to 'src/Progmasoft/Catch3/TestSpec.cpp')
-rw-r--r--src/Progmasoft/Catch3/TestSpec.cpp143
1 files changed, 143 insertions, 0 deletions
diff --git a/src/Progmasoft/Catch3/TestSpec.cpp b/src/Progmasoft/Catch3/TestSpec.cpp
new file mode 100644
index 00000000..5b789e66
--- /dev/null
+++ b/src/Progmasoft/Catch3/TestSpec.cpp
@@ -0,0 +1,143 @@
+
+// Copyright Catch2 Authors
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE.txt or copy at
+// https://www.boost.org/LICENSE_1_0.txt)
+
+// SPDX-License-Identifier: BSL-1.0
+#include <Progmasoft/Catch3/TestSpec.hpp>
+#include <Progmasoft/Catch3/Interfaces/ITestCaseRegistry.hpp>
+#include <Progmasoft/Catch3/Internal/TestCaseRegistryImpl.hpp>
+#include <Progmasoft/Catch3/Internal/ReusableStringStream.hpp>
+#include <Progmasoft/Catch3/Internal/StringManip.hpp>
+#include <Progmasoft/Catch3/TestCaseInfo.hpp>
+
+#include <algorithm>
+#include <string>
+#include <vector>
+#include <ostream>
+
+namespace Catch {
+
+ TestSpec::Pattern::Pattern( std::string const& name )
+ : m_name( name )
+ {}
+
+ TestSpec::Pattern::~Pattern() = default;
+
+ std::string const& TestSpec::Pattern::name() const {
+ return m_name;
+ }
+
+
+ TestSpec::NamePattern::NamePattern( std::string const& name, std::string const& filterString )
+ : Pattern( filterString )
+ , m_wildcardPattern( name, CaseSensitive::No )
+ {}
+
+ bool TestSpec::NamePattern::matches( TestCaseInfo const& testCase ) const {
+ return m_wildcardPattern.matches( testCase.name );
+ }
+
+ void TestSpec::NamePattern::serializeTo( std::ostream& out ) const {
+ out << '"' << name() << '"';
+ }
+
+
+ TestSpec::TagPattern::TagPattern( std::string const& tag, std::string const& filterString )
+ : Pattern( filterString )
+ , m_tag( tag )
+ {}
+
+ bool TestSpec::TagPattern::matches( TestCaseInfo const& testCase ) const {
+ return std::find( begin( testCase.tags ),
+ end( testCase.tags ),
+ Tag( m_tag ) ) != end( testCase.tags );
+ }
+
+ void TestSpec::TagPattern::serializeTo( std::ostream& out ) const {
+ out << name();
+ }
+
+ bool TestSpec::Filter::matches( TestCaseInfo const& testCase ) const {
+ bool should_use = !testCase.isHidden();
+ for (auto const& pattern : m_required) {
+ should_use = true;
+ if (!pattern->matches(testCase)) {
+ return false;
+ }
+ }
+ for (auto const& pattern : m_forbidden) {
+ if (pattern->matches(testCase)) {
+ return false;
+ }
+ }
+ return should_use;
+ }
+
+ void TestSpec::Filter::serializeTo( std::ostream& out ) const {
+ bool first = true;
+ for ( auto const& pattern : m_required ) {
+ if ( !first ) {
+ out << ' ';
+ }
+ out << *pattern;
+ first = false;
+ }
+ for ( auto const& pattern : m_forbidden ) {
+ if ( !first ) {
+ out << ' ';
+ }
+ out << *pattern;
+ first = false;
+ }
+ }
+
+
+ std::string TestSpec::extractFilterName( Filter const& filter ) {
+ Catch::ReusableStringStream sstr;
+ sstr << filter;
+ return sstr.str();
+ }
+
+ bool TestSpec::hasFilters() const {
+ return !m_filters.empty();
+ }
+
+ bool TestSpec::matches( TestCaseInfo const& testCase ) const {
+ return std::any_of( m_filters.begin(), m_filters.end(), [&]( Filter const& f ){ return f.matches( testCase ); } );
+ }
+
+ TestSpec::Matches TestSpec::matchesByFilter( std::vector<TestCaseHandle> const& testCases, IConfig const& config ) const {
+ Matches matches;
+ matches.reserve( m_filters.size() );
+ for ( auto const& filter : m_filters ) {
+ std::vector<TestCaseHandle const*> currentMatches;
+ for ( auto const& test : testCases ) {
+ if ( isThrowSafe( test, config ) &&
+ filter.matches( test.getTestCaseInfo() ) ) {
+ currentMatches.emplace_back( &test );
+ }
+ }
+ matches.push_back( FilterMatch{ extractFilterName( filter ),
+ CATCH_MOVE( currentMatches ) } );
+ }
+ return matches;
+ }
+
+ const TestSpec::vectorStrings& TestSpec::getInvalidSpecs() const {
+ return m_invalidSpecs;
+ }
+
+ void TestSpec::serializeTo( std::ostream& out ) const {
+ bool first = true;
+ for ( auto const& filter : m_filters ) {
+ if ( !first ) {
+ out << ',';
+ }
+ out << filter;
+ first = false;
+ }
+ }
+
+}