forked from qt-creator/qt-creator
AutoTest: Fix detection of gtests inside namespaces
Task-number: QTCREATORBUG-16535 Change-Id: I3285d2545e2861607b6e1406ee24f950405c4367 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user