AutoTest: Support registering functions as catch test cases

Task-number: QTCREATORBUG-19740
Change-Id: I60a59d3902e1202d4cf18635bae3ef31806b0aac
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Stenger
2020-04-16 11:49:49 +02:00
parent 4e0fa78752
commit ae3bb43dd1
3 changed files with 27 additions and 7 deletions

View File

@@ -102,12 +102,14 @@ void CatchCodeParser::handleIdentifier()
|| identifier == "TEMPLATE_PRODUCT_TEST_CASE_SIG") { || identifier == "TEMPLATE_PRODUCT_TEST_CASE_SIG") {
handleParameterizedTestCase(false); handleParameterizedTestCase(false);
} else if (identifier == "TEST_CASE_METHOD") { } else if (identifier == "TEST_CASE_METHOD") {
handleFixtureTestCase(); handleFixtureOrRegisteredTestCase(true);
} else if (identifier == "TEMPLATE_TEST_CASE_METHOD_SIG" } else if (identifier == "TEMPLATE_TEST_CASE_METHOD_SIG"
|| identifier == "TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG" || identifier == "TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG"
|| identifier == "TEMPLATE_TEST_CASE_METHOD" || identifier == "TEMPLATE_TEST_CASE_METHOD"
|| identifier == "TEMPLATE_LIST_TEST_CASE_METHOD") { || identifier == "TEMPLATE_LIST_TEST_CASE_METHOD") {
handleParameterizedTestCase(true); handleParameterizedTestCase(true);
} else if (identifier == "METHOD_AS_TEST_CASE" || identifier == "REGISTER_TEST_CASE") {
handleFixtureOrRegisteredTestCase(false);
} }
} }
@@ -175,13 +177,18 @@ void CatchCodeParser::handleParameterizedTestCase(bool isFixture)
m_testCases.append(locationAndType); m_testCases.append(locationAndType);
} }
void CatchCodeParser::handleFixtureTestCase() void CatchCodeParser::handleFixtureOrRegisteredTestCase(bool isFixture)
{ {
if (!skipCommentsUntil(T_LPAREN)) if (!skipCommentsUntil(T_LPAREN))
return; return;
if (!skipFixtureParameter()) if (isFixture) {
return; if (!skipFixtureParameter())
return;
} else {
if (!skipFunctionParameter())
return;
}
CatchTestCodeLocationAndType locationAndType CatchTestCodeLocationAndType locationAndType
= locationAndTypeFromToken(m_tokens.at(m_currentIndex)); = locationAndTypeFromToken(m_tokens.at(m_currentIndex));
@@ -201,7 +208,8 @@ void CatchCodeParser::handleFixtureTestCase()
locationAndType.m_name = testCaseName; locationAndType.m_name = testCaseName;
locationAndType.tags = parseTags(tagsString); locationAndType.tags = parseTags(tagsString);
locationAndType.states = CatchTreeItem::Fixture; if (isFixture)
locationAndType.states = CatchTreeItem::Fixture;
m_testCases.append(locationAndType); m_testCases.append(locationAndType);
} }
@@ -267,5 +275,15 @@ bool CatchCodeParser::skipFixtureParameter()
return skipCommentsUntil(T_COMMA); return skipCommentsUntil(T_COMMA);
} }
bool CatchCodeParser::skipFunctionParameter()
{
if (!skipCommentsUntil(T_IDENTIFIER))
return false;
if (skipCommentsUntil(T_COLON_COLON))
return skipFunctionParameter();
return skipCommentsUntil(T_COMMA);
}
} // namespace Internal } // namespace Internal
} // namespace Autotest } // namespace Autotest

View File

@@ -46,12 +46,13 @@ private:
void handleIdentifier(); void handleIdentifier();
void handleTestCase(bool isScenario); void handleTestCase(bool isScenario);
void handleParameterizedTestCase(bool isFixture); void handleParameterizedTestCase(bool isFixture);
void handleFixtureTestCase(); void handleFixtureOrRegisteredTestCase(bool isFixture);
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 skipFixtureParameter();
bool skipFunctionParameter();
const QByteArray &m_source; const QByteArray &m_source;
const CPlusPlus::LanguageFeatures &m_features; const CPlusPlus::LanguageFeatures &m_features;

View File

@@ -48,7 +48,8 @@ static bool isCatchTestCaseMacro(const QString &macroName)
QStringLiteral("TEST_CASE_METHOD"), QStringLiteral("TEMPLATE_TEST_CASE_METHOD_SIG"), QStringLiteral("TEST_CASE_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"),
QStringLiteral("METHOD_AS_TEST_CASE"), QStringLiteral("REGISTER_TEST_CASE")
}; };
return validTestCaseMacros.contains(macroName); return validTestCaseMacros.contains(macroName);
} }