Ignore leading/trailing whitespace in test/section specs

The leading/trailing whitespace is problematic because of e.g.
`WHEN` macro having preceeding whitespace for alignment, and it is
generally messy.

Credits to Phil who did lot of the original work.

Closes #1708
This commit is contained in:
Martin Hořeňovský
2019-09-09 11:30:45 +02:00
parent a156440b19
commit af8b2538a6
12 changed files with 219 additions and 27 deletions

View File

@@ -8,6 +8,7 @@
#include "catch_test_case_tracker.h"
#include "catch_enforce.h"
#include "catch_string_manip.h"
#include <algorithm>
#include <cassert>
@@ -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<std::string> 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<std::string> 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