aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/autotest
diff options
context:
space:
mode:
authorChristian Stenger <christian.stenger@qt.io>2020-04-16 11:49:49 +0200
committerChristian Stenger <christian.stenger@qt.io>2020-04-20 08:43:19 +0000
commitae3bb43dd17826ec8bca045cc6cd31f20a0a1f0c (patch)
tree83992e38e51eaccd59984a5d6b82ddcfd5c7db3a /src/plugins/autotest
parent4e0fa78752b0c96030f9a0e98c6fb53b210f5430 (diff)
AutoTest: Support registering functions as catch test cases
Task-number: QTCREATORBUG-19740 Change-Id: I60a59d3902e1202d4cf18635bae3ef31806b0aac Reviewed-by: David Schulz <david.schulz@qt.io>
Diffstat (limited to 'src/plugins/autotest')
-rw-r--r--src/plugins/autotest/catch/catchcodeparser.cpp28
-rw-r--r--src/plugins/autotest/catch/catchcodeparser.h3
-rw-r--r--src/plugins/autotest/catch/catchtestparser.cpp3
3 files changed, 27 insertions, 7 deletions
diff --git a/src/plugins/autotest/catch/catchcodeparser.cpp b/src/plugins/autotest/catch/catchcodeparser.cpp
index 719f268d0d..f5dc8fcab4 100644
--- a/src/plugins/autotest/catch/catchcodeparser.cpp
+++ b/src/plugins/autotest/catch/catchcodeparser.cpp
@@ -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
diff --git a/src/plugins/autotest/catch/catchcodeparser.h b/src/plugins/autotest/catch/catchcodeparser.h
index b10a682087..005c704a07 100644
--- a/src/plugins/autotest/catch/catchcodeparser.h
+++ b/src/plugins/autotest/catch/catchcodeparser.h
@@ -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;
diff --git a/src/plugins/autotest/catch/catchtestparser.cpp b/src/plugins/autotest/catch/catchtestparser.cpp
index ddfa6de2e8..b4ced8882d 100644
--- a/src/plugins/autotest/catch/catchtestparser.cpp
+++ b/src/plugins/autotest/catch/catchtestparser.cpp
@@ -48,7 +48,8 @@ static bool isCatchTestCaseMacro(const QString &macroName)
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);
}