AutoTest: Fix bugs on catch2 fixture

Fix the integration of SCENARIO_METHOD.
Allow the catch2 fixture to have namespace before the class.

Fixes: QTCREATORBUG-30454
Change-Id: I27b0578fae12715e6a4466289ed4cc34351f3112
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Aurele Faure
2023-12-15 13:22:38 +01:00
committed by Christian Stenger
parent f20fc9132f
commit a2be1e9692
3 changed files with 18 additions and 24 deletions

View File

@@ -79,14 +79,16 @@ void CatchCodeParser::handleIdentifier()
|| unprefixed == "TEMPLATE_PRODUCT_TEST_CASE_SIG") { || unprefixed == "TEMPLATE_PRODUCT_TEST_CASE_SIG") {
handleParameterizedTestCase(false); handleParameterizedTestCase(false);
} else if (unprefixed == "TEST_CASE_METHOD") { } else if (unprefixed == "TEST_CASE_METHOD") {
handleFixtureOrRegisteredTestCase(true); handleFixtureOrRegisteredTestCase(/*fixture=*/true, /*scenario=*/false);
} else if (unprefixed == "SCENARIO_METHOD") {
handleFixtureOrRegisteredTestCase(/*fixture=*/true, /*scenario=*/true);
} else if (unprefixed == "TEMPLATE_TEST_CASE_METHOD_SIG" } else if (unprefixed == "TEMPLATE_TEST_CASE_METHOD_SIG"
|| unprefixed == "TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG" || unprefixed == "TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG"
|| unprefixed == "TEMPLATE_TEST_CASE_METHOD" || unprefixed == "TEMPLATE_TEST_CASE_METHOD"
|| unprefixed == "TEMPLATE_LIST_TEST_CASE_METHOD") { || unprefixed == "TEMPLATE_LIST_TEST_CASE_METHOD") {
handleParameterizedTestCase(true); handleParameterizedTestCase(true);
} else if (unprefixed == "METHOD_AS_TEST_CASE" || unprefixed == "REGISTER_TEST_CASE") { } else if (unprefixed == "METHOD_AS_TEST_CASE" || unprefixed == "REGISTER_TEST_CASE") {
handleFixtureOrRegisteredTestCase(false); handleFixtureOrRegisteredTestCase(/*fixture=*/false, /*scenario=*/false);
} }
} }
@@ -124,7 +126,7 @@ void CatchCodeParser::handleParameterizedTestCase(bool isFixture)
if (!skipCommentsUntil(T_LPAREN)) if (!skipCommentsUntil(T_LPAREN))
return; return;
if (isFixture && !skipFixtureParameter()) if (isFixture && !skipParameter())
return; return;
CatchTestCodeLocationAndType locationAndType CatchTestCodeLocationAndType locationAndType
@@ -154,18 +156,13 @@ void CatchCodeParser::handleParameterizedTestCase(bool isFixture)
m_testCases.append(locationAndType); m_testCases.append(locationAndType);
} }
void CatchCodeParser::handleFixtureOrRegisteredTestCase(bool isFixture) void CatchCodeParser::handleFixtureOrRegisteredTestCase(bool isFixture, bool isScenario)
{ {
if (!skipCommentsUntil(T_LPAREN)) if (!skipCommentsUntil(T_LPAREN))
return; return;
if (isFixture) { if (!skipParameter())
if (!skipFixtureParameter())
return; return;
} else {
if (!skipFunctionParameter())
return;
}
CatchTestCodeLocationAndType locationAndType CatchTestCodeLocationAndType locationAndType
= locationAndTypeFromToken(m_tokens.at(m_currentIndex)); = locationAndTypeFromToken(m_tokens.at(m_currentIndex));
@@ -183,6 +180,9 @@ void CatchCodeParser::handleFixtureOrRegisteredTestCase(bool isFixture)
if (stoppedAt != T_RPAREN) if (stoppedAt != T_RPAREN)
return; return;
if (isScenario)
testCaseName.prepend("Scenario: "); // use a flag?
locationAndType.m_name = testCaseName; locationAndType.m_name = testCaseName;
locationAndType.tags = parseTags(tagsString); locationAndType.tags = parseTags(tagsString);
if (isFixture) if (isFixture)
@@ -245,19 +245,12 @@ Kind CatchCodeParser::skipUntilCorrespondingRParen()
return T_ERROR; return T_ERROR;
} }
bool CatchCodeParser::skipFixtureParameter() bool CatchCodeParser::skipParameter()
{
if (!skipCommentsUntil(T_IDENTIFIER))
return false;
return skipCommentsUntil(T_COMMA);
}
bool CatchCodeParser::skipFunctionParameter()
{ {
if (!skipCommentsUntil(T_IDENTIFIER)) if (!skipCommentsUntil(T_IDENTIFIER))
return false; return false;
if (skipCommentsUntil(T_COLON_COLON)) if (skipCommentsUntil(T_COLON_COLON))
return skipFunctionParameter(); return skipParameter();
return skipCommentsUntil(T_COMMA); return skipCommentsUntil(T_COMMA);
} }

View File

@@ -22,13 +22,12 @@ private:
void handleIdentifier(); void handleIdentifier();
void handleTestCase(bool isScenario); void handleTestCase(bool isScenario);
void handleParameterizedTestCase(bool isFixture); void handleParameterizedTestCase(bool isFixture);
void handleFixtureOrRegisteredTestCase(bool isFixture); void handleFixtureOrRegisteredTestCase(bool isFixture, bool isScenario);
QString getStringLiteral(CPlusPlus::Kind &stoppedAtKind); QString getStringLiteral(CPlusPlus::Kind &stoppedAtKind);
bool skipCommentsUntil(CPlusPlus::Kind nextExpectedKind); // moves currentIndex if succeeds bool skipCommentsUntil(CPlusPlus::Kind nextExpectedKind); // moves currentIndex if succeeds
CPlusPlus::Kind skipUntilCorrespondingRParen(); // moves currentIndex CPlusPlus::Kind skipUntilCorrespondingRParen(); // moves currentIndex
bool skipFixtureParameter(); bool skipParameter();
bool skipFunctionParameter();
const QByteArray &m_source; const QByteArray &m_source;
const CPlusPlus::LanguageFeatures &m_features; const CPlusPlus::LanguageFeatures &m_features;

View File

@@ -29,7 +29,9 @@ static bool isCatchTestCaseMacro(const QString &macroName)
QStringLiteral("TEMPLATE_TEST_CASE_SIG"), QStringLiteral("TEMPLATE_PRODUCT_TEST_CASE_SIG"), QStringLiteral("TEMPLATE_TEST_CASE_SIG"), QStringLiteral("TEMPLATE_PRODUCT_TEST_CASE_SIG"),
QStringLiteral("TEST_CASE_METHOD"), QStringLiteral("TEMPLATE_TEST_CASE_METHOD"), QStringLiteral("TEST_CASE_METHOD"), QStringLiteral("TEMPLATE_TEST_CASE_METHOD"),
QStringLiteral("TEMPLATE_PRODUCT_TEST_CASE_METHOD"), QStringLiteral("TEMPLATE_PRODUCT_TEST_CASE_METHOD"),
QStringLiteral("TEST_CASE_METHOD"), QStringLiteral("TEMPLATE_TEST_CASE_METHOD_SIG"), QStringLiteral("TEST_CASE_METHOD"),
QStringLiteral("SCENARIO_METHOD"),
QStringLiteral("TEMPLATE_TEST_CASE_METHOD_SIG"),
QStringLiteral("TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG"), QStringLiteral("TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG"),
QStringLiteral("TEMPLATE_TEST_CASE_METHOD"), QStringLiteral("TEMPLATE_TEST_CASE_METHOD"),
QStringLiteral("TEMPLATE_LIST_TEST_CASE_METHOD"), QStringLiteral("TEMPLATE_LIST_TEST_CASE_METHOD"),
@@ -105,7 +107,7 @@ bool CatchTestParser::processDocument(QPromise<TestParseResultPtr> &promise,
if (!hasCatchNames(doc)) { if (!hasCatchNames(doc)) {
static const QRegularExpression regex("\\b(CATCH_)?" static const QRegularExpression regex("\\b(CATCH_)?"
"(SCENARIO|(TEMPLATE_(PRODUCT_)?)?TEST_CASE(_METHOD)?|" "(SCENARIO(_METHOD)?|(TEMPLATE_(PRODUCT_)?)?TEST_CASE(_METHOD)?|"
"TEMPLATE_TEST_CASE(_METHOD)?_SIG|" "TEMPLATE_TEST_CASE(_METHOD)?_SIG|"
"TEMPLATE_PRODUCT_TEST_CASE(_METHOD)?_SIG|" "TEMPLATE_PRODUCT_TEST_CASE(_METHOD)?_SIG|"
"TEMPLATE_LIST_TEST_CASE_METHOD|METHOD_AS_TEST_CASE|" "TEMPLATE_LIST_TEST_CASE_METHOD|METHOD_AS_TEST_CASE|"