diff --git a/include/internal/catch_config.cpp b/include/internal/catch_config.cpp index 076ae718..e222328b 100644 --- a/include/internal/catch_config.cpp +++ b/include/internal/catch_config.cpp @@ -15,11 +15,23 @@ namespace Catch { : m_data( data ), m_stream( openStream() ) { + // We need to trim filter specs to avoid trouble with superfluous + // whitespace (esp. important for bdd macros, as those are manually + // aligned with whitespace). + + for (auto& elem : m_data.testsOrTags) { + elem = trim(elem); + } + for (auto& elem : m_data.sectionsToRun) { + elem = trim(elem); + } + TestSpecParser parser(ITagAliasRegistry::get()); - if (!data.testsOrTags.empty()) { + if (!m_data.testsOrTags.empty()) { m_hasTestFilters = true; - for( auto const& testOrTags : data.testsOrTags ) - parser.parse( testOrTags ); + for (auto const& testOrTags : m_data.testsOrTags) { + parser.parse(testOrTags); + } } m_testSpec = parser.testSpec(); } @@ -32,7 +44,7 @@ namespace Catch { bool Config::listTestNamesOnly() const { return m_data.listTestNamesOnly; } bool Config::listTags() const { return m_data.listTags; } bool Config::listReporters() const { return m_data.listReporters; } - + std::string Config::getProcessName() const { return m_data.processName; } std::string const& Config::getReporterName() const { return m_data.reporterName; } diff --git a/include/internal/catch_test_case_tracker.cpp b/include/internal/catch_test_case_tracker.cpp index 9e75590c..77bd65cb 100644 --- a/include/internal/catch_test_case_tracker.cpp +++ b/include/internal/catch_test_case_tracker.cpp @@ -8,6 +8,7 @@ #include "catch_test_case_tracker.h" #include "catch_enforce.h" +#include "catch_string_manip.h" #include #include @@ -174,7 +175,8 @@ namespace TestCaseTracking { } SectionTracker::SectionTracker( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent ) - : TrackerBase( nameAndLocation, ctx, parent ) + : TrackerBase( nameAndLocation, ctx, parent ), + m_trimmed_name(trim(nameAndLocation.name)) { if( parent ) { while( !parent->isSectionTracker() ) @@ -188,12 +190,11 @@ namespace TestCaseTracking { bool SectionTracker::isComplete() const { bool complete = true; - if ((m_filters.empty() || m_filters[0] == "") || - std::find(m_filters.begin(), m_filters.end(), - m_nameAndLocation.name) != m_filters.end()) + if ((m_filters.empty() || m_filters[0] == "") + || std::find(m_filters.begin(), m_filters.end(), m_trimmed_name) != m_filters.end()) { complete = TrackerBase::isComplete(); + } return complete; - } bool SectionTracker::isSectionTracker() const { return true; } @@ -217,12 +218,13 @@ namespace TestCaseTracking { } void SectionTracker::tryOpen() { - if( !isComplete() && (m_filters.empty() || m_filters[0].empty() || m_filters[0] == m_nameAndLocation.name ) ) + if( !isComplete() ) open(); } void SectionTracker::addInitialFilters( std::vector const& filters ) { if( !filters.empty() ) { + m_filters.reserve( m_filters.size() + filters.size() + 2 ); m_filters.push_back(""); // Root - should never be consulted m_filters.push_back(""); // Test Case - not a section filter m_filters.insert( m_filters.end(), filters.begin(), filters.end() ); @@ -230,7 +232,7 @@ namespace TestCaseTracking { } void SectionTracker::addNextFilters( std::vector const& filters ) { if( filters.size() > 1 ) - m_filters.insert( m_filters.end(), ++filters.begin(), filters.end() ); + m_filters.insert( m_filters.end(), filters.begin()+1, filters.end() ); } } // namespace TestCaseTracking diff --git a/include/internal/catch_test_case_tracker.h b/include/internal/catch_test_case_tracker.h index 97b63b8b..563dbef2 100644 --- a/include/internal/catch_test_case_tracker.h +++ b/include/internal/catch_test_case_tracker.h @@ -133,6 +133,7 @@ namespace TestCaseTracking { class SectionTracker : public TrackerBase { std::vector m_filters; + std::string m_trimmed_name; public: SectionTracker( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent ); diff --git a/include/internal/catch_test_spec.cpp b/include/internal/catch_test_spec.cpp index 54b638c4..4c80c56e 100644 --- a/include/internal/catch_test_spec.cpp +++ b/include/internal/catch_test_spec.cpp @@ -33,7 +33,7 @@ namespace Catch { {} bool TestSpec::NamePattern::matches( TestCaseInfo const& testCase ) const { - return m_wildcardPattern.matches( toLower( testCase.name ) ); + return m_wildcardPattern.matches( testCase.name ); } diff --git a/include/internal/catch_wildcard_pattern.cpp b/include/internal/catch_wildcard_pattern.cpp index 9bf20f04..95e5d3f0 100644 --- a/include/internal/catch_wildcard_pattern.cpp +++ b/include/internal/catch_wildcard_pattern.cpp @@ -9,14 +9,12 @@ #include "catch_enforce.h" #include "catch_string_manip.h" -#include - namespace Catch { WildcardPattern::WildcardPattern( std::string const& pattern, CaseSensitive::Choice caseSensitivity ) : m_caseSensitivity( caseSensitivity ), - m_pattern( adjustCase( pattern ) ) + m_pattern( normaliseString( pattern ) ) { if( startsWith( m_pattern, '*' ) ) { m_pattern = m_pattern.substr( 1 ); @@ -31,19 +29,19 @@ namespace Catch { bool WildcardPattern::matches( std::string const& str ) const { switch( m_wildcard ) { case NoWildcard: - return m_pattern == adjustCase( str ); + return m_pattern == normaliseString( str ); case WildcardAtStart: - return endsWith( adjustCase( str ), m_pattern ); + return endsWith( normaliseString( str ), m_pattern ); case WildcardAtEnd: - return startsWith( adjustCase( str ), m_pattern ); + return startsWith( normaliseString( str ), m_pattern ); case WildcardAtBothEnds: - return contains( adjustCase( str ), m_pattern ); + return contains( normaliseString( str ), m_pattern ); default: CATCH_INTERNAL_ERROR( "Unknown enum" ); } } - std::string WildcardPattern::adjustCase( std::string const& str ) const { - return m_caseSensitivity == CaseSensitive::No ? toLower( str ) : str; + std::string WildcardPattern::normaliseString( std::string const& str ) const { + return trim( m_caseSensitivity == CaseSensitive::No ? toLower( str ) : str ); } } diff --git a/include/internal/catch_wildcard_pattern.h b/include/internal/catch_wildcard_pattern.h index 4dae7171..5d508f7b 100644 --- a/include/internal/catch_wildcard_pattern.h +++ b/include/internal/catch_wildcard_pattern.h @@ -28,7 +28,7 @@ namespace Catch virtual bool matches( std::string const& str ) const; private: - std::string adjustCase( std::string const& str ) const; + std::string normaliseString( std::string const& str ) const; CaseSensitive::Choice m_caseSensitivity; WildcardPosition m_wildcard = NoWildcard; std::string m_pattern; diff --git a/projects/SelfTest/Baselines/compact.sw.approved.txt b/projects/SelfTest/Baselines/compact.sw.approved.txt index fccf52ca..9a7abcef 100644 --- a/projects/SelfTest/Baselines/compact.sw.approved.txt +++ b/projects/SelfTest/Baselines/compact.sw.approved.txt @@ -866,6 +866,16 @@ CmdLine.tests.cpp:: passed: spec.matches( tcA ) == false for: false CmdLine.tests.cpp:: passed: spec.matches( tcB ) == false for: false == false CmdLine.tests.cpp:: passed: spec.matches( tcC ) == false for: false == false CmdLine.tests.cpp:: passed: spec.matches( tcD ) == true for: true == true +CmdLine.tests.cpp:: passed: spec.matches( fakeTestCase( " aardvark " ) ) for: true +CmdLine.tests.cpp:: passed: spec.matches( fakeTestCase( " aardvark" ) ) for: true +CmdLine.tests.cpp:: passed: spec.matches( fakeTestCase( " aardvark " ) ) for: true +CmdLine.tests.cpp:: passed: spec.matches( fakeTestCase( "aardvark " ) ) for: true +CmdLine.tests.cpp:: passed: spec.matches( fakeTestCase( "aardvark" ) ) for: true +CmdLine.tests.cpp:: passed: spec.matches( fakeTestCase( " aardvark " ) ) for: true +CmdLine.tests.cpp:: passed: spec.matches( fakeTestCase( " aardvark" ) ) for: true +CmdLine.tests.cpp:: passed: spec.matches( fakeTestCase( " aardvark " ) ) for: true +CmdLine.tests.cpp:: passed: spec.matches( fakeTestCase( "aardvark " ) ) for: true +CmdLine.tests.cpp:: passed: spec.matches( fakeTestCase( "aardvark" ) ) for: true Condition.tests.cpp:: passed: p == 0 for: 0 == 0 Condition.tests.cpp:: passed: p == pNULL for: 0 == 0 Condition.tests.cpp:: passed: p != 0 for: 0x != 0 diff --git a/projects/SelfTest/Baselines/console.std.approved.txt b/projects/SelfTest/Baselines/console.std.approved.txt index a52bb9a5..d2b2165f 100644 --- a/projects/SelfTest/Baselines/console.std.approved.txt +++ b/projects/SelfTest/Baselines/console.std.approved.txt @@ -1381,5 +1381,5 @@ due to unexpected exception with message: =============================================================================== test cases: 300 | 226 passed | 70 failed | 4 failed as expected -assertions: 1558 | 1406 passed | 131 failed | 21 failed as expected +assertions: 1568 | 1416 passed | 131 failed | 21 failed as expected diff --git a/projects/SelfTest/Baselines/console.sw.approved.txt b/projects/SelfTest/Baselines/console.sw.approved.txt index 1fca8cf3..6eabf307 100644 --- a/projects/SelfTest/Baselines/console.sw.approved.txt +++ b/projects/SelfTest/Baselines/console.sw.approved.txt @@ -6366,6 +6366,70 @@ CmdLine.tests.cpp:: PASSED: with expansion: true == true +------------------------------------------------------------------------------- +Parse test names and tags + Leading and trailing spaces in test spec +------------------------------------------------------------------------------- +CmdLine.tests.cpp: +............................................................................... + +CmdLine.tests.cpp:: PASSED: + CHECK( spec.matches( fakeTestCase( " aardvark " ) ) ) +with expansion: + true + +CmdLine.tests.cpp:: PASSED: + CHECK( spec.matches( fakeTestCase( " aardvark" ) ) ) +with expansion: + true + +CmdLine.tests.cpp:: PASSED: + CHECK( spec.matches( fakeTestCase( " aardvark " ) ) ) +with expansion: + true + +CmdLine.tests.cpp:: PASSED: + CHECK( spec.matches( fakeTestCase( "aardvark " ) ) ) +with expansion: + true + +CmdLine.tests.cpp:: PASSED: + CHECK( spec.matches( fakeTestCase( "aardvark" ) ) ) +with expansion: + true + +------------------------------------------------------------------------------- +Parse test names and tags + Leading and trailing spaces in test name +------------------------------------------------------------------------------- +CmdLine.tests.cpp: +............................................................................... + +CmdLine.tests.cpp:: PASSED: + CHECK( spec.matches( fakeTestCase( " aardvark " ) ) ) +with expansion: + true + +CmdLine.tests.cpp:: PASSED: + CHECK( spec.matches( fakeTestCase( " aardvark" ) ) ) +with expansion: + true + +CmdLine.tests.cpp:: PASSED: + CHECK( spec.matches( fakeTestCase( " aardvark " ) ) ) +with expansion: + true + +CmdLine.tests.cpp:: PASSED: + CHECK( spec.matches( fakeTestCase( "aardvark " ) ) ) +with expansion: + true + +CmdLine.tests.cpp:: PASSED: + CHECK( spec.matches( fakeTestCase( "aardvark" ) ) ) +with expansion: + true + ------------------------------------------------------------------------------- Pointers can be compared to null ------------------------------------------------------------------------------- @@ -12457,5 +12521,5 @@ Misc.tests.cpp:: PASSED: =============================================================================== test cases: 300 | 210 passed | 86 failed | 4 failed as expected -assertions: 1575 | 1406 passed | 148 failed | 21 failed as expected +assertions: 1585 | 1416 passed | 148 failed | 21 failed as expected diff --git a/projects/SelfTest/Baselines/junit.sw.approved.txt b/projects/SelfTest/Baselines/junit.sw.approved.txt index ca1998ed..e764d1f6 100644 --- a/projects/SelfTest/Baselines/junit.sw.approved.txt +++ b/projects/SelfTest/Baselines/junit.sw.approved.txt @@ -1,7 +1,7 @@ - + @@ -620,6 +620,8 @@ Message.tests.cpp: + + diff --git a/projects/SelfTest/Baselines/xml.sw.approved.txt b/projects/SelfTest/Baselines/xml.sw.approved.txt index c406d061..b58684d7 100644 --- a/projects/SelfTest/Baselines/xml.sw.approved.txt +++ b/projects/SelfTest/Baselines/xml.sw.approved.txt @@ -7901,6 +7901,92 @@ Nor would this +
+ + + spec.matches( fakeTestCase( " aardvark " ) ) + + + true + + + + + spec.matches( fakeTestCase( " aardvark" ) ) + + + true + + + + + spec.matches( fakeTestCase( " aardvark " ) ) + + + true + + + + + spec.matches( fakeTestCase( "aardvark " ) ) + + + true + + + + + spec.matches( fakeTestCase( "aardvark" ) ) + + + true + + + +
+
+ + + spec.matches( fakeTestCase( " aardvark " ) ) + + + true + + + + + spec.matches( fakeTestCase( " aardvark" ) ) + + + true + + + + + spec.matches( fakeTestCase( " aardvark " ) ) + + + true + + + + + spec.matches( fakeTestCase( "aardvark " ) ) + + + true + + + + + spec.matches( fakeTestCase( "aardvark" ) ) + + + true + + + +
@@ -14826,7 +14912,7 @@ loose text artifact - + - + diff --git a/projects/SelfTest/IntrospectiveTests/CmdLine.tests.cpp b/projects/SelfTest/IntrospectiveTests/CmdLine.tests.cpp index f4d1299a..6ecc3a14 100644 --- a/projects/SelfTest/IntrospectiveTests/CmdLine.tests.cpp +++ b/projects/SelfTest/IntrospectiveTests/CmdLine.tests.cpp @@ -262,7 +262,24 @@ TEST_CASE( "Parse test names and tags" ) { CHECK( spec.matches( tcC ) == false ); CHECK( spec.matches( tcD ) == true ); } + SECTION( "Leading and trailing spaces in test spec" ) { + TestSpec spec = parseTestSpec( "\" aardvark \"" ); + CHECK( spec.matches( fakeTestCase( " aardvark " ) ) ); + CHECK( spec.matches( fakeTestCase( " aardvark" ) ) ); + CHECK( spec.matches( fakeTestCase( " aardvark " ) ) ); + CHECK( spec.matches( fakeTestCase( "aardvark " ) ) ); + CHECK( spec.matches( fakeTestCase( "aardvark" ) ) ); + } + SECTION( "Leading and trailing spaces in test name" ) { + TestSpec spec = parseTestSpec( "aardvark" ); + CHECK( spec.matches( fakeTestCase( " aardvark " ) ) ); + CHECK( spec.matches( fakeTestCase( " aardvark" ) ) ); + CHECK( spec.matches( fakeTestCase( " aardvark " ) ) ); + CHECK( spec.matches( fakeTestCase( "aardvark " ) ) ); + CHECK( spec.matches( fakeTestCase( "aardvark" ) ) ); + + } } TEST_CASE( "Process can be configured on command line", "[config][command-line]" ) {