Commit 9a3a0fa7 authored by Christian Stenger's avatar Christian Stenger

AutoTest: Fix detection of gtests inside namespaces

Task-number: QTCREATORBUG-16535
Change-Id: I3285d2545e2861607b6e1406ee24f950405c4367
Reviewed-by: Nikolai Kosjar's avatarNikolai Kosjar <nikolai.kosjar@qt.io>
parent 38484d46
......@@ -204,7 +204,7 @@ void AutoTestUnitTests::testCodeParserGTest()
QVERIFY(parserSpy.wait(20000));
QVERIFY(modelUpdateSpy.wait());
QCOMPARE(m_model->gtestNamesCount(), 6);
QCOMPARE(m_model->gtestNamesCount(), 7);
QMultiMap<QString, int> expectedNamesAndSets;
expectedNamesAndSets.insert(QStringLiteral("FactorialTest"), 3);
......@@ -213,6 +213,7 @@ void AutoTestUnitTests::testCodeParserGTest()
expectedNamesAndSets.insert(QStringLiteral("QueueTest"), 2);
expectedNamesAndSets.insert(QStringLiteral("DummyTest"), 1); // used as parameterized test
expectedNamesAndSets.insert(QStringLiteral("DummyTest"), 1); // used as 'normal' test
expectedNamesAndSets.insert(QStringLiteral("NamespaceTest"), 1);
QMultiMap<QString, int> foundNamesAndSets = m_model->gtestNamesAndSets();
QCOMPARE(expectedNamesAndSets.size(), foundNamesAndSets.size());
......
......@@ -27,6 +27,7 @@
#include "gtest_utils.h"
#include <cplusplus/LookupContext.h>
#include <utils/qtcassert.h>
namespace Autotest {
namespace Internal {
......@@ -48,7 +49,15 @@ bool GTestVisitor::visit(CPlusPlus::FunctionDefinitionAST *ast)
return false;
CPlusPlus::LookupContext lc;
const QString prettyName = m_overview.prettyName(lc.fullyQualifiedName(ast->symbol));
QString prettyName = m_overview.prettyName(lc.fullyQualifiedName(ast->symbol));
// get surrounding namespace(s) and strip them out
const QString namespaces = enclosingNamespaces(ast->symbol);
if (!namespaces.isEmpty()) {
QTC_CHECK(prettyName.startsWith(namespaces));
prettyName = prettyName.mid(namespaces.length());
}
if (!GTestUtils::isGTestMacro(prettyName))
return false;
......@@ -83,5 +92,20 @@ bool GTestVisitor::visit(CPlusPlus::FunctionDefinitionAST *ast)
return false;
}
QString GTestVisitor::enclosingNamespaces(CPlusPlus::Symbol *symbol) const
{
QString enclosing;
if (!symbol)
return enclosing;
CPlusPlus::Symbol *currentSymbol = symbol;
while (CPlusPlus::Namespace *ns = currentSymbol->enclosingNamespace()) {
if (ns->name()) // handle anonymous namespaces as well
enclosing.prepend(m_overview.prettyName(ns->name()).append("::"));
currentSymbol = ns;
}
return enclosing;
}
} // namespace Internal
} // namespace Autotest
......@@ -63,6 +63,8 @@ public:
QMap<GTestCaseSpec, GTestCodeLocationList> gtestFunctions() const { return m_gtestFunctions; }
private:
QString enclosingNamespaces(CPlusPlus::Symbol *symbol) const;
CPlusPlus::Document::Ptr m_document;
CPlusPlus::Overview m_overview;
QMap<GTestCaseSpec, GTestCodeLocationList> m_gtestFunctions;
......
......@@ -46,3 +46,16 @@ TEST(FactorialTest, DISABLED_Fake)
{
EXPECT_EQ(-4, sum(-2, -2));
}
namespace Dummy {
namespace {
namespace Internal {
TEST(NamespaceTest, Valid)
{
EXPECT_EQ(1, 1);
}
} // namespace Internal
} // anon namespace
} // namespace Dummy
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