forked from qt-creator/qt-creator
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:
@@ -102,12 +102,14 @@ void CatchCodeParser::handleIdentifier()
|
||||
|| identifier == "TEMPLATE_PRODUCT_TEST_CASE_SIG") {
|
||||
handleParameterizedTestCase(false);
|
||||
} else if (identifier == "TEST_CASE_METHOD") {
|
||||
handleFixtureTestCase();
|
||||
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") {
|
||||
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);
|
||||
}
|
||||
|
||||
void CatchCodeParser::handleFixtureTestCase()
|
||||
void CatchCodeParser::handleFixtureOrRegisteredTestCase(bool isFixture)
|
||||
{
|
||||
if (!skipCommentsUntil(T_LPAREN))
|
||||
return;
|
||||
|
||||
if (!skipFixtureParameter())
|
||||
return;
|
||||
if (isFixture) {
|
||||
if (!skipFixtureParameter())
|
||||
return;
|
||||
} else {
|
||||
if (!skipFunctionParameter())
|
||||
return;
|
||||
}
|
||||
|
||||
CatchTestCodeLocationAndType locationAndType
|
||||
= locationAndTypeFromToken(m_tokens.at(m_currentIndex));
|
||||
@@ -201,7 +208,8 @@ void CatchCodeParser::handleFixtureTestCase()
|
||||
|
||||
locationAndType.m_name = testCaseName;
|
||||
locationAndType.tags = parseTags(tagsString);
|
||||
locationAndType.states = CatchTreeItem::Fixture;
|
||||
if (isFixture)
|
||||
locationAndType.states = CatchTreeItem::Fixture;
|
||||
m_testCases.append(locationAndType);
|
||||
}
|
||||
|
||||
@@ -267,5 +275,15 @@ bool CatchCodeParser::skipFixtureParameter()
|
||||
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 Autotest
|
||||
|
@@ -46,12 +46,13 @@ private:
|
||||
void handleIdentifier();
|
||||
void handleTestCase(bool isScenario);
|
||||
void handleParameterizedTestCase(bool isFixture);
|
||||
void handleFixtureTestCase();
|
||||
void handleFixtureOrRegisteredTestCase(bool isFixture);
|
||||
|
||||
QString getStringLiteral(CPlusPlus::Kind &stoppedAtKind);
|
||||
bool skipCommentsUntil(CPlusPlus::Kind nextExpectedKind); // moves currentIndex if succeeds
|
||||
CPlusPlus::Kind skipUntilCorrespondingRParen(); // moves currentIndex
|
||||
bool skipFixtureParameter();
|
||||
bool skipFunctionParameter();
|
||||
|
||||
const QByteArray &m_source;
|
||||
const CPlusPlus::LanguageFeatures &m_features;
|
||||
|
@@ -48,7 +48,8 @@ static bool isCatchTestCaseMacro(const QString ¯oName)
|
||||
QStringLiteral("TEST_CASE_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")
|
||||
QStringLiteral("TEMPLATE_LIST_TEST_CASE_METHOD"),
|
||||
QStringLiteral("METHOD_AS_TEST_CASE"), QStringLiteral("REGISTER_TEST_CASE")
|
||||
};
|
||||
return validTestCaseMacros.contains(macroName);
|
||||
}
|
||||
|
Reference in New Issue
Block a user