2017-07-19 10:13:47 +02:00
|
|
|
/*
|
|
|
|
* Created by Martin on 19/07/2017.
|
|
|
|
*
|
|
|
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
*/
|
|
|
|
|
2017-09-07 12:24:33 +02:00
|
|
|
#include "catch_test_spec.h"
|
2017-07-25 21:57:35 +02:00
|
|
|
#include "catch_string_manip.h"
|
2019-08-06 20:51:19 +02:00
|
|
|
#include "catch_interfaces_config.h"
|
2017-07-19 10:13:47 +02:00
|
|
|
|
2017-07-27 22:31:27 +02:00
|
|
|
#include <algorithm>
|
2017-07-19 10:13:47 +02:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
namespace Catch {
|
|
|
|
|
2019-08-06 20:51:19 +02:00
|
|
|
TestSpec::Pattern::Pattern( std::string const& name )
|
|
|
|
: m_name( name )
|
|
|
|
{}
|
|
|
|
|
2017-09-07 16:51:33 +02:00
|
|
|
TestSpec::Pattern::~Pattern() = default;
|
|
|
|
|
2019-08-06 20:51:19 +02:00
|
|
|
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( toLower( name ), CaseSensitive::No )
|
2017-07-19 10:13:47 +02:00
|
|
|
{}
|
2019-08-06 20:51:19 +02:00
|
|
|
|
2017-07-19 10:13:47 +02:00
|
|
|
bool TestSpec::NamePattern::matches( TestCaseInfo const& testCase ) const {
|
2019-09-09 11:30:45 +02:00
|
|
|
return m_wildcardPattern.matches( testCase.name );
|
2017-07-19 10:13:47 +02:00
|
|
|
}
|
|
|
|
|
2019-08-06 20:51:19 +02:00
|
|
|
|
|
|
|
TestSpec::TagPattern::TagPattern( std::string const& tag, std::string const& filterString )
|
|
|
|
: Pattern( filterString )
|
|
|
|
, m_tag( toLower( tag ) )
|
|
|
|
{}
|
|
|
|
|
2017-07-19 10:13:47 +02:00
|
|
|
bool TestSpec::TagPattern::matches( TestCaseInfo const& testCase ) const {
|
2019-11-07 12:39:07 +01:00
|
|
|
return std::find_if(begin(testCase.tags),
|
|
|
|
end(testCase.tags),
|
|
|
|
[&](Tag const& tag) {
|
|
|
|
return tag.lowerCased == m_tag;
|
|
|
|
}) != end(testCase.tags);
|
2017-07-19 10:13:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool TestSpec::Filter::matches( TestCaseInfo const& testCase ) const {
|
2019-06-22 20:26:03 +02:00
|
|
|
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;
|
2019-08-06 20:51:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string TestSpec::Filter::name() const {
|
|
|
|
std::string name;
|
2019-06-22 20:26:03 +02:00
|
|
|
for (auto const& p : m_required) {
|
2019-08-06 20:51:19 +02:00
|
|
|
name += p->name();
|
2019-06-22 20:26:03 +02:00
|
|
|
}
|
|
|
|
for (auto const& p : m_forbidden) {
|
|
|
|
name += p->name();
|
|
|
|
}
|
2019-08-06 20:51:19 +02:00
|
|
|
return name;
|
2017-07-19 10:13:47 +02:00
|
|
|
}
|
|
|
|
|
2019-08-06 20:51:19 +02:00
|
|
|
|
2017-07-19 10:13:47 +02:00
|
|
|
bool TestSpec::hasFilters() const {
|
|
|
|
return !m_filters.empty();
|
|
|
|
}
|
2019-08-06 20:51:19 +02:00
|
|
|
|
2017-07-19 10:13:47 +02:00
|
|
|
bool TestSpec::matches( TestCaseInfo const& testCase ) const {
|
2019-08-06 20:51:19 +02:00
|
|
|
return std::any_of( m_filters.begin(), m_filters.end(), [&]( Filter const& f ){ return f.matches( testCase ); } );
|
2017-07-19 10:13:47 +02:00
|
|
|
}
|
2019-08-06 20:51:19 +02:00
|
|
|
|
2019-11-04 21:35:57 +01:00
|
|
|
TestSpec::Matches TestSpec::matchesByFilter( std::vector<TestCaseHandle> const& testCases, IConfig const& config ) const
|
2019-08-06 20:51:19 +02:00
|
|
|
{
|
|
|
|
Matches matches( m_filters.size() );
|
|
|
|
std::transform( m_filters.begin(), m_filters.end(), matches.begin(), [&]( Filter const& filter ){
|
2019-11-04 21:35:57 +01:00
|
|
|
std::vector<TestCaseHandle const*> currentMatches;
|
2019-08-06 20:51:19 +02:00
|
|
|
for( auto const& test : testCases )
|
2019-11-04 21:35:57 +01:00
|
|
|
if( isThrowSafe( test, config ) && filter.matches( test.getTestCaseInfo() ) )
|
2019-08-06 20:51:19 +02:00
|
|
|
currentMatches.emplace_back( &test );
|
|
|
|
return FilterMatch{ filter.name(), currentMatches };
|
|
|
|
} );
|
|
|
|
return matches;
|
|
|
|
}
|
2019-06-22 20:26:03 +02:00
|
|
|
|
2019-10-19 15:50:46 +02:00
|
|
|
const TestSpec::vectorStrings& TestSpec::getInvalidArgs() const{
|
|
|
|
return (m_invalidArgs);
|
|
|
|
}
|
2019-08-06 20:51:19 +02:00
|
|
|
|
2017-07-19 10:13:47 +02:00
|
|
|
}
|