Commit 25d63d85 authored by Christian Stenger's avatar Christian Stenger

AutoTest: Support typed gtests as well

Change-Id: I5e904ef50c76560df8b63fc766a2b78b90bf73cc
Reviewed-by: default avatarDavid Schulz <david.schulz@theqtcompany.com>
parent 8e5af55b
......@@ -37,14 +37,20 @@ public:
static bool isGTestMacro(const QString &macro)
{
static QStringList valid = {
QStringLiteral("TEST"), QStringLiteral("TEST_F"), QStringLiteral("TEST_P")
QStringLiteral("TEST"), QStringLiteral("TEST_F"), QStringLiteral("TEST_P"),
QStringLiteral("TYPED_TEST"), QStringLiteral("TYPED_TEST_P")
};
return valid.contains(macro);
}
static bool isGTestParameterized(const QString &macro)
{
return macro == QStringLiteral("TEST_P");
return macro == QStringLiteral("TEST_P") || macro == QStringLiteral("TYPED_TEST_P");
}
static bool isGTestTyped(const QString &macro)
{
return macro == QStringLiteral("TYPED_TEST") || macro == QStringLiteral("TYPED_TEST_P");
}
static bool isQTestMacro(const QByteArray &macro)
......
......@@ -497,6 +497,7 @@ static void handleGTest(QFutureInterface<TestParseResult> futureInterface, const
parseResult.fileName = filePath;
parseResult.testCaseName = testSpec.testCaseName;
parseResult.parameterized = testSpec.parameterized;
parseResult.typed = testSpec.typed;
parseResult.proFile = proFile;
parseResult.dataTagsOrTestSets.insert(QString(), result.value(testSpec));
futureInterface.reportResult(parseResult);
......
......@@ -386,6 +386,8 @@ GoogleTestTreeItem *GoogleTestTreeItem::createTestItem(const TestParseResult &re
item->setProFile(result.proFile);
if (result.parameterized)
item->setState(Parameterized);
if (result.typed)
item->setState(Typed);
foreach (const TestCodeLocationAndType &location, result.dataTagsOrTestSets.first())
item->appendChild(createTestSetItem(result, location));
return item;
......@@ -407,11 +409,8 @@ QVariant GoogleTestTreeItem::data(int column, int role) const
{
switch (role) {
case Qt::DisplayRole:
if (type() == TestCase) {
if (m_state & Parameterized)
return QString(name() + QObject::tr(" [parameterized]"));
return name();
}
if (type() == TestCase)
return QVariant(name() + nameSuffix());
break;
case StateRole:
return (int)m_state;
......@@ -445,6 +444,18 @@ TestTreeItem *GoogleTestTreeItem::findChildByNameStateAndFile(const QString &nam
});
}
QString GoogleTestTreeItem::nameSuffix() const
{
static QString markups[] = { QObject::tr("parameterized"), QObject::tr("typed") };
QString suffix;
if (m_state & Parameterized)
suffix = QLatin1String(" [") + markups[0];
if (m_state & Typed)
suffix += (suffix.isEmpty() ? QLatin1String(" [") : QLatin1String(", ")) + markups[1];
if (!suffix.isEmpty())
suffix += QLatin1Char(']');
return suffix;
}
} // namespace Internal
} // namespace Autotest
......@@ -168,6 +168,7 @@ public:
Enabled = 0x00,
Disabled = 0x01,
Parameterized = 0x02,
Typed = 0x04,
};
Q_FLAGS(TestState)
......@@ -192,6 +193,7 @@ public:
TestTreeItem *findChildByNameStateAndFile(const QString &name,
GoogleTestTreeItem::TestStates state,
const QString &proFile);
QString nameSuffix() const;
private:
GoogleTestTreeItem::TestStates m_state;
......@@ -209,6 +211,7 @@ struct GTestCaseSpec
{
QString testCaseName;
bool parameterized;
bool typed;
};
} // namespace Internal
......
......@@ -257,6 +257,17 @@ QList<TestConfiguration *> TestTreeModel::getAllTestCases() const
return result;
}
static QString gtestFilter(GoogleTestTreeItem::TestStates states)
{
if ((states & GoogleTestTreeItem::Parameterized) && (states & GoogleTestTreeItem::Typed))
return QLatin1String("*/%1/*.%2");
if (states & GoogleTestTreeItem::Parameterized)
return QLatin1String("*/%1.%2/*");
if (states & GoogleTestTreeItem::Typed)
return QLatin1String("%1/*.%2");
return QLatin1String("%1.%2");
}
QList<TestConfiguration *> TestTreeModel::getSelectedTests() const
{
QList<TestConfiguration *> result;
......@@ -385,16 +396,10 @@ QList<TestConfiguration *> TestTreeModel::getSelectedTests() const
for (int grandChildRow = 0; grandChildRow < grandChildCount; ++grandChildRow) {
const TestTreeItem *grandChild = child->childItem(grandChildRow);
const QString &proFile = grandChild->proFile();
QStringList enabled = proFilesWithEnabledTestSets.value(proFile);
if (grandChild->checked() == Qt::Checked) {
QString testSpecifier = child->name() + QLatin1Char('.') + grandChild->name();
if (child->state() & GoogleTestTreeItem::Parameterized) {
testSpecifier.prepend(QLatin1String("*/"));
testSpecifier.append(QLatin1String("/*"));
}
enabled << testSpecifier;
proFilesWithEnabledTestSets[proFile].append(
gtestFilter(child->state()).arg(child->name()).arg(grandChild->name()));
}
proFilesWithEnabledTestSets.insert(proFile, enabled);
}
}
......@@ -435,9 +440,8 @@ TestConfiguration *TestTreeModel::getTestConfiguration(const TestTreeItem *item)
config->setProFile(item->proFile());
config->setProject(project);
} else if (auto gtestItem = item->asGoogleTestTreeItem()) {
QString testSpecifier = item->name() + QLatin1String(".*");
if (gtestItem->state() & GoogleTestTreeItem::Parameterized)
testSpecifier.prepend(QLatin1String("*/"));
const QString &testSpecifier
= gtestFilter(gtestItem->state()).arg(item->name()).arg(QLatin1Char('*'));
if (int childCount = item->childCount()) {
config = new TestConfiguration(QString(), QStringList(testSpecifier));
......@@ -463,12 +467,9 @@ TestConfiguration *TestTreeModel::getTestConfiguration(const TestTreeItem *item)
config->setProFile(parent->proFile());
config->setProject(project);
} else if (auto gtestParent = parent->asGoogleTestTreeItem()) {
QString testSpecifier = parent->name() + QLatin1Char('.') + item->name();
const QString &testSpecifier
= gtestFilter(gtestParent->state()).arg(parent->name()).arg(item->name());
if (gtestParent->state() & GoogleTestTreeItem::Parameterized) {
testSpecifier.prepend(QLatin1String("*/"));
testSpecifier.append(QLatin1String("/*"));
}
config = new TestConfiguration(QString(), QStringList(testSpecifier));
config->setProFile(item->proFile());
config->setProject(project);
......@@ -733,6 +734,8 @@ void TestTreeModel::handleGTestParseResult(const TestParseResult &result)
GoogleTestTreeItem::TestStates states = GoogleTestTreeItem::Enabled;
if (result.parameterized)
states |= GoogleTestTreeItem::Parameterized;
if (result.typed)
states |= GoogleTestTreeItem::Typed;
TestTreeItem *toBeModified = m_googleTestRootItem->findChildByNameStateAndFile(
result.testCaseName, states, result.proFile);
if (!toBeModified) {
......
......@@ -156,6 +156,7 @@ struct TestParseResult
unsigned line = 0;
unsigned column = 0;
bool parameterized = false;
bool typed = false;
QMap<QString, TestCodeLocationAndType> functions;
QMap<QString, TestCodeLocationList> dataTagsOrTestSets;
};
......
......@@ -392,6 +392,7 @@ bool GTestVisitor::visit(CPlusPlus::FunctionDefinitionAST *ast)
GTestCaseSpec spec;
spec.testCaseName = disabledCase ? testCaseName.mid(9) : testCaseName;
spec.parameterized = TestUtils::isGTestParameterized(prettyName);
spec.typed = TestUtils::isGTestTyped(prettyName);
m_gtestFunctions[spec].append(locationAndType);
}
......
......@@ -133,7 +133,14 @@ inline bool operator<(const GTestCaseSpec &spec1, const GTestCaseSpec &spec2)
{
if (spec1.testCaseName != spec2.testCaseName)
return spec1.testCaseName < spec2.testCaseName;
return spec1.parameterized == spec2.parameterized ? false : !spec1.parameterized;
if (spec1.parameterized == spec2.parameterized) {
if (spec1.typed == spec2.typed)
return false;
else
return !spec1.typed;
} else {
return !spec1.parameterized;
}
}
class GTestVisitor : public CPlusPlus::ASTVisitor
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment