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") {
handleParameterizedTestCase(false);
} 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"
|| unprefixed == "TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG"
|| unprefixed == "TEMPLATE_TEST_CASE_METHOD"
|| unprefixed == "TEMPLATE_LIST_TEST_CASE_METHOD") {
handleParameterizedTestCase(true);
} 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))
return;
if (isFixture && !skipFixtureParameter())
if (isFixture && !skipParameter())
return;
CatchTestCodeLocationAndType locationAndType
@@ -154,18 +156,13 @@ void CatchCodeParser::handleParameterizedTestCase(bool isFixture)
m_testCases.append(locationAndType);
}
void CatchCodeParser::handleFixtureOrRegisteredTestCase(bool isFixture)
void CatchCodeParser::handleFixtureOrRegisteredTestCase(bool isFixture, bool isScenario)
{
if (!skipCommentsUntil(T_LPAREN))
return;
if (isFixture) {
if (!skipFixtureParameter())
if (!skipParameter())
return;
} else {
if (!skipFunctionParameter())
return;
}
CatchTestCodeLocationAndType locationAndType
= locationAndTypeFromToken(m_tokens.at(m_currentIndex));
@@ -183,6 +180,9 @@ void CatchCodeParser::handleFixtureOrRegisteredTestCase(bool isFixture)
if (stoppedAt != T_RPAREN)
return;
if (isScenario)
testCaseName.prepend("Scenario: "); // use a flag?
locationAndType.m_name = testCaseName;
locationAndType.tags = parseTags(tagsString);
if (isFixture)
@@ -245,19 +245,12 @@ Kind CatchCodeParser::skipUntilCorrespondingRParen()
return T_ERROR;
}
bool CatchCodeParser::skipFixtureParameter()
{
if (!skipCommentsUntil(T_IDENTIFIER))
return false;
return skipCommentsUntil(T_COMMA);
}
bool CatchCodeParser::skipFunctionParameter()
bool CatchCodeParser::skipParameter()
{
if (!skipCommentsUntil(T_IDENTIFIER))
return false;
if (skipCommentsUntil(T_COLON_COLON))
return skipFunctionParameter();
return skipParameter();
return skipCommentsUntil(T_COMMA);
}

View File

@@ -22,13 +22,12 @@ private:
void handleIdentifier();
void handleTestCase(bool isScenario);
void handleParameterizedTestCase(bool isFixture);
void handleFixtureOrRegisteredTestCase(bool isFixture);
void handleFixtureOrRegisteredTestCase(bool isFixture, bool isScenario);
QString getStringLiteral(CPlusPlus::Kind &stoppedAtKind);
bool skipCommentsUntil(CPlusPlus::Kind nextExpectedKind); // moves currentIndex if succeeds
CPlusPlus::Kind skipUntilCorrespondingRParen(); // moves currentIndex
bool skipFixtureParameter();
bool skipFunctionParameter();
bool skipParameter();
const QByteArray &m_source;
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("TEST_CASE_METHOD"), QStringLiteral("TEMPLATE_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_TEST_CASE_METHOD"),
QStringLiteral("TEMPLATE_LIST_TEST_CASE_METHOD"),
@@ -105,7 +107,7 @@ bool CatchTestParser::processDocument(QPromise<TestParseResultPtr> &promise,
if (!hasCatchNames(doc)) {
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_PRODUCT_TEST_CASE(_METHOD)?_SIG|"
"TEMPLATE_LIST_TEST_CASE_METHOD|METHOD_AS_TEST_CASE|"