forked from qt-creator/qt-creator
AutoTest: Fix catch2 parsing when using prefixed commands
If Catch2 is used with CATCH_CONFIG_PREFIX_ALL the relevant macros get a prefix. This patch enhances the respective parser to be able to handle these appropriate. This does not really take into account whether the define is set or not, so the parse results will only be correct if the project can be built. Fixes: QTCREATORBUG-27704 Change-Id: I935de752ac6106524c45c027af3e0f43673c4578 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -90,22 +90,24 @@ void CatchCodeParser::handleIdentifier()
|
||||
QTC_ASSERT(m_currentIndex < m_tokens.size(), return);
|
||||
const Token &token = m_tokens.at(m_currentIndex);
|
||||
const QByteArray &identifier = m_source.mid(int(token.bytesBegin()), int(token.bytes()));
|
||||
if (identifier == "TEST_CASE") {
|
||||
const QByteArray unprefixed = identifier.startsWith("CATCH_") ? identifier.mid(6) : identifier;
|
||||
|
||||
if (unprefixed == "TEST_CASE") {
|
||||
handleTestCase(false);
|
||||
} else if (identifier == "SCENARIO") {
|
||||
} else if (unprefixed == "SCENARIO") {
|
||||
handleTestCase(true);
|
||||
} else if (identifier == "TEMPLATE_TEST_CASE" || identifier == "TEMPLATE_PRODUCT_TEST_CASE"
|
||||
|| identifier == "TEMPLATE_LIST_TEST_CASE" || identifier == "TEMPLATE_TEST_CASE_SIG"
|
||||
|| identifier == "TEMPLATE_PRODUCT_TEST_CASE_SIG") {
|
||||
} else if (unprefixed == "TEMPLATE_TEST_CASE" || unprefixed == "TEMPLATE_PRODUCT_TEST_CASE"
|
||||
|| unprefixed == "TEMPLATE_LIST_TEST_CASE" || unprefixed == "TEMPLATE_TEST_CASE_SIG"
|
||||
|| unprefixed == "TEMPLATE_PRODUCT_TEST_CASE_SIG") {
|
||||
handleParameterizedTestCase(false);
|
||||
} else if (identifier == "TEST_CASE_METHOD") {
|
||||
} else if (unprefixed == "TEST_CASE_METHOD") {
|
||||
handleFixtureOrRegisteredTestCase(true);
|
||||
} else if (identifier == "TEMPLATE_TEST_CASE_METHOD_SIG"
|
||||
|| identifier == "TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG"
|
||||
|| identifier == "TEMPLATE_TEST_CASE_METHOD"
|
||||
|| identifier == "TEMPLATE_LIST_TEST_CASE_METHOD") {
|
||||
} else if (unprefixed == "TEMPLATE_TEST_CASE_METHOD_SIG"
|
||||
|| unprefixed == "TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG"
|
||||
|| unprefixed == "TEMPLATE_TEST_CASE_METHOD"
|
||||
|| unprefixed == "TEMPLATE_LIST_TEST_CASE_METHOD") {
|
||||
handleParameterizedTestCase(true);
|
||||
} else if (identifier == "METHOD_AS_TEST_CASE" || identifier == "REGISTER_TEST_CASE") {
|
||||
} else if (unprefixed == "METHOD_AS_TEST_CASE" || unprefixed == "REGISTER_TEST_CASE") {
|
||||
handleFixtureOrRegisteredTestCase(false);
|
||||
}
|
||||
}
|
||||
|
@@ -57,10 +57,11 @@ static bool isCatchTestCaseMacro(const QString ¯oName)
|
||||
|
||||
static bool isCatchMacro(const QString ¯oName)
|
||||
{
|
||||
QString unprefixed = macroName.startsWith("CATCH_") ? macroName.mid(6) : macroName;
|
||||
const QStringList validSectionMacros = {
|
||||
QStringLiteral("SECTION"), QStringLiteral("WHEN")
|
||||
};
|
||||
return isCatchTestCaseMacro(macroName) || validSectionMacros.contains(macroName);
|
||||
return isCatchTestCaseMacro(unprefixed) || validSectionMacros.contains(unprefixed);
|
||||
}
|
||||
|
||||
static bool includesCatchHeader(const CPlusPlus::Document::Ptr &doc,
|
||||
@@ -123,7 +124,8 @@ bool CatchTestParser::processDocument(QFutureInterface<TestParseResultPtr> &futu
|
||||
const QByteArray &fileContent = getFileContent(fileName);
|
||||
|
||||
if (!hasCatchNames(doc)) {
|
||||
const QRegularExpression regex("\\b(SCENARIO|(TEMPLATE_(PRODUCT_)?)?TEST_CASE(_METHOD)?|"
|
||||
const QRegularExpression regex("\\b(CATCH_)?"
|
||||
"(SCENARIO|(TEMPLATE_(PRODUCT_)?)?TEST_CASE(_METHOD)?|"
|
||||
"TEMPLATE_TEST_CASE(_METHOD)?_SIG|"
|
||||
"TEMPLATE_PRODUCT_TEST_CASE(_METHOD)?_SIG|"
|
||||
"TEMPLATE_LIST_TEST_CASE_METHOD|METHOD_AS_TEST_CASE|"
|
||||
|
Reference in New Issue
Block a user