diff options
author | Aurele Faure <aurele.faure@pollen-metrology.com> | 2023-12-15 13:22:38 +0100 |
---|---|---|
committer | Christian Stenger <christian.stenger@qt.io> | 2024-02-29 08:39:33 +0000 |
commit | a2be1e96927dac4f009bae30a68e75c78528c9fa (patch) | |
tree | ddc22f6768505724f5993b75a2fda7e5915cb1db /src/plugins/autotest | |
parent | f20fc9132fdc92eb13e9fe49d73d82f37b8724d3 (diff) |
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>
Diffstat (limited to 'src/plugins/autotest')
-rw-r--r-- | src/plugins/autotest/catch/catchcodeparser.cpp | 31 | ||||
-rw-r--r-- | src/plugins/autotest/catch/catchcodeparser.h | 5 | ||||
-rw-r--r-- | src/plugins/autotest/catch/catchtestparser.cpp | 6 |
3 files changed, 18 insertions, 24 deletions
diff --git a/src/plugins/autotest/catch/catchcodeparser.cpp b/src/plugins/autotest/catch/catchcodeparser.cpp index 186dde5ea1b..f9d6b19ed04 100644 --- a/src/plugins/autotest/catch/catchcodeparser.cpp +++ b/src/plugins/autotest/catch/catchcodeparser.cpp @@ -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); } diff --git a/src/plugins/autotest/catch/catchcodeparser.h b/src/plugins/autotest/catch/catchcodeparser.h index 9315b3ccc2c..4bebb16bce8 100644 --- a/src/plugins/autotest/catch/catchcodeparser.h +++ b/src/plugins/autotest/catch/catchcodeparser.h @@ -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; diff --git a/src/plugins/autotest/catch/catchtestparser.cpp b/src/plugins/autotest/catch/catchtestparser.cpp index 96f536a9055..bc2f4e0644e 100644 --- a/src/plugins/autotest/catch/catchtestparser.cpp +++ b/src/plugins/autotest/catch/catchtestparser.cpp @@ -29,7 +29,9 @@ static bool isCatchTestCaseMacro(const QString ¯oName) 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|" |