diff options
| author | Martin Hořeňovský | 2019-11-05 23:28:47 +0100 |
|---|---|---|
| committer | Martin Hořeňovský | 2020-02-13 13:35:10 +0100 |
| commit | c50ba09cdef4e9d8764868a1a67f0ec3850b5d04 (patch) | |
| tree | 0612abe0b87c85be5109f7445cbaaf09cc784b71 /src/catch2/catch_test_spec_parser.cpp | |
| parent | c165bd15c5017137db38e149c8c8b68f1233fa96 (diff) | |
| download | catch3-c50ba09cdef4e9d8764868a1a67f0ec3850b5d04.tar.gz | |
Split [.foo] into [.][foo] when parsing test specs
b77cec05c0 fixed this problem for tagging tests, so that a test
case tagged with `[.foo]` would be parsed as tagged with `[.][foo]`.
This does the same for the test spec parsing.
Fixes #1798
Diffstat (limited to 'src/catch2/catch_test_spec_parser.cpp')
| -rw-r--r-- | src/catch2/catch_test_spec_parser.cpp | 61 |
1 files changed, 59 insertions, 2 deletions
diff --git a/src/catch2/catch_test_spec_parser.cpp b/src/catch2/catch_test_spec_parser.cpp index 5c3df3b6..d8de256c 100644 --- a/src/catch2/catch_test_spec_parser.cpp +++ b/src/catch2/catch_test_spec_parser.cpp @@ -113,9 +113,9 @@ namespace Catch { switch( m_mode ) { case Name: case QuotedName: - return addPattern<TestSpec::NamePattern>(); + return addNamePattern(); case Tag: - return addPattern<TestSpec::TagPattern>(); + return addTagPattern(); case EscapedName: revertBackToLastMode(); return; @@ -175,6 +175,63 @@ namespace Catch { return true; //success } + std::string TestSpecParser::preprocessPattern() { + std::string token = m_patternName; + for (std::size_t i = 0; i < m_escapeChars.size(); ++i) + token = token.substr(0, m_escapeChars[i] - i) + token.substr(m_escapeChars[i] - i + 1); + m_escapeChars.clear(); + if (startsWith(token, "exclude:")) { + m_exclusion = true; + token = token.substr(8); + } + + m_patternName.clear(); + + return token; + } + + void TestSpecParser::addNamePattern() { + auto token = preprocessPattern(); + + if (!token.empty()) { + if (m_exclusion) { + m_currentFilter.m_forbidden.emplace_back(std::make_unique<TestSpec::NamePattern>(token, m_substring)); + } else { + m_currentFilter.m_required.emplace_back(std::make_unique<TestSpec::NamePattern>(token, m_substring)); + } + } + m_substring.clear(); + m_exclusion = false; + m_mode = None; + } + + void TestSpecParser::addTagPattern() { + auto token = preprocessPattern(); + + if (!token.empty()) { + // If the tag pattern is the "hide and tag" shorthand (e.g. [.foo]) + // we have to create a separate hide tag and shorten the real one + if (token.size() > 1 && token[0] == '.') { + token.erase(token.begin()); + if (m_exclusion) { + m_currentFilter.m_forbidden.emplace_back(std::make_unique<TestSpec::TagPattern>(".", m_substring)); + m_currentFilter.m_forbidden.emplace_back(std::make_unique<TestSpec::TagPattern>(token, m_substring)); + } else { + m_currentFilter.m_required.emplace_back(std::make_unique<TestSpec::TagPattern>(".", m_substring)); + m_currentFilter.m_required.emplace_back(std::make_unique<TestSpec::TagPattern>(token, m_substring)); + } + } + if (m_exclusion) { + m_currentFilter.m_forbidden.emplace_back(std::make_unique<TestSpec::TagPattern>(token, m_substring)); + } else { + m_currentFilter.m_required.emplace_back(std::make_unique<TestSpec::TagPattern>(token, m_substring)); + } + } + m_substring.clear(); + m_exclusion = false; + m_mode = None; + } + TestSpec parseTestSpec( std::string const& arg ) { return TestSpecParser( ITagAliasRegistry::get() ).parse( arg ).testSpec(); } |