AutoTest: Add support for templated boost tests

Change-Id: I393d20f186a47d7d1d18775a8f1102890c9de9f4
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Stenger
2019-06-03 14:47:54 +02:00
parent c20824f5ff
commit 679b31f841
4 changed files with 27 additions and 5 deletions

View File

@@ -115,6 +115,13 @@ void BoostCodeParser::handleIdentifier()
} else if (identifier == "BOOST_DATA_TEST_CASE_F") { } else if (identifier == "BOOST_DATA_TEST_CASE_F") {
m_currentState.setFlag(BoostTestTreeItem::Fixture); m_currentState.setFlag(BoostTestTreeItem::Fixture);
handleTestCase(TestCaseType::Data); handleTestCase(TestCaseType::Data);
} else if (identifier == "BOOST_AUTO_TEST_CASE_TEMPLATE") {
m_currentState.setFlag(BoostTestTreeItem::Templated);
handleTestCase(TestCaseType::Auto);
} else if (identifier == "BOOST_FIXTURE_TEST_CASE_TEMPLATE") {
m_currentState.setFlag(BoostTestTreeItem::Fixture);
m_currentState.setFlag(BoostTestTreeItem::Templated);
handleTestCase(TestCaseType::Auto);
} else if (identifier == "BOOST_TEST_DECORATOR") { } else if (identifier == "BOOST_TEST_DECORATOR") {
handleDecorator(); handleDecorator();
} }
@@ -237,6 +244,7 @@ void BoostCodeParser::handleTestCase(TestCaseType testCaseType)
m_currentState = BoostTestTreeItem::Enabled; m_currentState = BoostTestTreeItem::Enabled;
} }
} else { } else {
if (!m_currentState.testFlag(BoostTestTreeItem::Templated))
handleDecorators(); handleDecorators();
locationAndType = locationAndTypeFromToken(token, m_source, m_currentState, m_suites); locationAndType = locationAndTypeFromToken(token, m_source, m_currentState, m_suites);
m_testCases.append(locationAndType); m_testCases.append(locationAndType);

View File

@@ -40,7 +40,9 @@ namespace BoostTestUtils {
static const QStringList relevant = { static const QStringList relevant = {
QStringLiteral("BOOST_AUTO_TEST_CASE"), QStringLiteral("BOOST_TEST_CASE"), QStringLiteral("BOOST_AUTO_TEST_CASE"), QStringLiteral("BOOST_TEST_CASE"),
QStringLiteral("BOOST_DATA_TEST_CASE"), QStringLiteral("BOOST_FIXTURE_TEST_CASE"), QStringLiteral("BOOST_DATA_TEST_CASE"), QStringLiteral("BOOST_FIXTURE_TEST_CASE"),
QStringLiteral("BOOST_PARAM_TEST_CASE"), QStringLiteral("BOOST_DATA_TEST_CASE_F") QStringLiteral("BOOST_PARAM_TEST_CASE"), QStringLiteral("BOOST_DATA_TEST_CASE_F"),
QStringLiteral("BOOST_AUTO_TEST_CASE_TEMPLATE"),
QStringLiteral("BOOST_FIXTURE_TEST_CASE_TEMPLATE"),
}; };
bool isBoostTestMacro(const QString &macro) bool isBoostTestMacro(const QString &macro)

View File

@@ -233,7 +233,10 @@ QList<TestConfiguration *> BoostTestTreeItem::getSelectedTestConfigurations() co
if (!item->enabled()) // ignore child tests known to be disabled when using run selected if (!item->enabled()) // ignore child tests known to be disabled when using run selected
return; return;
if (item->checked() == Qt::Checked) { if (item->checked() == Qt::Checked) {
QString tcName = handleSpecialFunctionNames(item->name()); QString tcName = item->name();
if (item->state().testFlag(BoostTestTreeItem::Templated))
tcName.append("<*");
tcName = handleSpecialFunctionNames(tcName);
testCasesForProjectFile[item->proFile()].testCases.append( testCasesForProjectFile[item->proFile()].testCases.append(
item->prependWithParentsSuitePaths(tcName)); item->prependWithParentsSuitePaths(tcName));
testCasesForProjectFile[item->proFile()].internalTargets.unite(item->internalTargets()); testCasesForProjectFile[item->proFile()].internalTargets.unite(item->internalTargets());
@@ -268,12 +271,17 @@ TestConfiguration *BoostTestTreeItem::testConfiguration() const
QString tcName = handleSpecialFunctionNames(boostItem->name()); QString tcName = handleSpecialFunctionNames(boostItem->name());
if (boostItem->type() == TestSuite) // execute everything below a suite if (boostItem->type() == TestSuite) // execute everything below a suite
tcName.append("/*"); tcName.append("/*");
else if (boostItem->state().testFlag(BoostTestTreeItem::Templated))
tcName.append("<*");
testCases.append(boostItem->prependWithParentsSuitePaths(tcName)); testCases.append(boostItem->prependWithParentsSuitePaths(tcName));
} }
} }
}); });
} else { } else {
testCases.append(prependWithParentsSuitePaths(handleSpecialFunctionNames(name()))); QString tcName = name();
if (state().testFlag(BoostTestTreeItem::Templated))
tcName.append("<*");
testCases.append(prependWithParentsSuitePaths(handleSpecialFunctionNames(tcName)));
} }
BoostTestConfiguration *config = new BoostTestConfiguration; BoostTestConfiguration *config = new BoostTestConfiguration;
@@ -297,12 +305,15 @@ TestConfiguration *BoostTestTreeItem::debugConfiguration() const
QString BoostTestTreeItem::nameSuffix() const QString BoostTestTreeItem::nameSuffix() const
{ {
static QString markups[] = {QCoreApplication::translate("BoostTestTreeItem", "parameterized"), static QString markups[] = {QCoreApplication::translate("BoostTestTreeItem", "parameterized"),
QCoreApplication::translate("BoostTestTreeItem", "fixture")}; QCoreApplication::translate("BoostTestTreeItem", "fixture"),
QCoreApplication::translate("BoostTestTreeItem", "templated")};
QString suffix; QString suffix;
if (m_state & Parameterized) if (m_state & Parameterized)
suffix = QString(" [") + markups[0]; suffix = QString(" [") + markups[0];
if (m_state & Fixture) if (m_state & Fixture)
suffix += (suffix.isEmpty() ? QString(" [") : QString(", ")) + markups[1]; suffix += (suffix.isEmpty() ? QString(" [") : QString(", ")) + markups[1];
if (m_state & Templated)
suffix += (suffix.isEmpty() ? QString(" [") : QString(", ")) + markups[2];
if (!suffix.isEmpty()) if (!suffix.isEmpty())
suffix += ']'; suffix += ']';
return suffix; return suffix;

View File

@@ -43,6 +43,7 @@ public:
Parameterized = 0x10, Parameterized = 0x10,
Fixture = 0x20, Fixture = 0x20,
Templated = 0x40,
}; };
Q_FLAGS(TestState) Q_FLAGS(TestState)
Q_DECLARE_FLAGS(TestStates, TestState) Q_DECLARE_FLAGS(TestStates, TestState)