diff options
author | Christian Stenger <christian.stenger@qt.io> | 2019-07-30 15:14:40 +0200 |
---|---|---|
committer | Christian Stenger <christian.stenger@qt.io> | 2019-08-22 06:50:05 +0000 |
commit | 8cd7a119262c226e575c0beda45a1af71a32baf5 (patch) | |
tree | d44fc052dc8bbc8ed0dfd4bbe69deea3e38e4de6 /src/plugins/autotest/quick | |
parent | abe3dde5d6af4c1400e19aa3a849812564739c63 (diff) |
AutoTest: Fix handling of unnamed QuickTests
..now that the parser understands multiple TestCase items
inside a single qml file.
As long a test function is located inside a different TestCase
it is considered as a different one, so treat test functions
even of unnamed test cases correct.
Change-Id: I5cbfe1f63f896317523d51bbf67ea59169481a71
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: David Schulz <david.schulz@qt.io>
Diffstat (limited to 'src/plugins/autotest/quick')
-rw-r--r-- | src/plugins/autotest/quick/quicktesttreeitem.cpp | 17 | ||||
-rw-r--r-- | src/plugins/autotest/quick/quicktesttreeitem.h | 2 | ||||
-rw-r--r-- | src/plugins/autotest/quick/quicktestvisitors.cpp | 13 |
3 files changed, 26 insertions, 6 deletions
diff --git a/src/plugins/autotest/quick/quicktesttreeitem.cpp b/src/plugins/autotest/quick/quicktesttreeitem.cpp index c18de0ee9e2..85f459ea019 100644 --- a/src/plugins/autotest/quick/quicktesttreeitem.cpp +++ b/src/plugins/autotest/quick/quicktesttreeitem.cpp @@ -329,7 +329,8 @@ TestTreeItem *QuickTestTreeItem::find(const TestParseResult *result) case GroupNode: return findChildByNameAndFile(result->name, result->fileName); case TestCase: - return name().isEmpty() ? findChildByNameAndFile(result->name, result->fileName) + return name().isEmpty() ? findChildByNameFileAndLine(result->name, result->fileName, + result->line) : findChildByName(result->name); default: return nullptr; @@ -351,7 +352,8 @@ TestTreeItem *QuickTestTreeItem::findChild(const TestTreeItem *other) case TestCase: if (otherType != TestFunction && otherType != TestDataFunction && otherType != TestSpecialFunction) return nullptr; - return name().isEmpty() ? findChildByNameAndFile(other->name(), other->filePath()) + return name().isEmpty() ? findChildByNameFileAndLine(other->name(), other->filePath(), + other->line()) : findChildByName(other->name()); default: return nullptr; @@ -368,8 +370,7 @@ bool QuickTestTreeItem::modify(const TestParseResult *result) case TestFunction: case TestDataFunction: case TestSpecialFunction: - return name().isEmpty() ? modifyLineAndColumn(result) - : modifyTestFunctionContent(result); + return modifyTestFunctionContent(result); default: return false; } @@ -454,6 +455,14 @@ TestTreeItem *QuickTestTreeItem::findChildByFileNameAndType(const QString &fileP }); } +TestTreeItem *QuickTestTreeItem::findChildByNameFileAndLine(const QString &name, + const QString &filePath, unsigned line) +{ + return findFirstLevelChild([name, filePath, line](const TestTreeItem *other) { + return other->filePath() == filePath && other->line() == line && other->name() == name; + }); +} + TestTreeItem *QuickTestTreeItem::unnamedQuickTests() const { if (type() != Root) diff --git a/src/plugins/autotest/quick/quicktesttreeitem.h b/src/plugins/autotest/quick/quicktesttreeitem.h index a9e48fca940..551d0865a21 100644 --- a/src/plugins/autotest/quick/quicktesttreeitem.h +++ b/src/plugins/autotest/quick/quicktesttreeitem.h @@ -59,6 +59,8 @@ public: private: TestTreeItem *findChildByFileNameAndType(const QString &filePath, const QString &name, Type tType); + TestTreeItem *findChildByNameFileAndLine(const QString &name, const QString &filePath, + unsigned line); TestTreeItem *unnamedQuickTests() const; }; diff --git a/src/plugins/autotest/quick/quicktestvisitors.cpp b/src/plugins/autotest/quick/quicktestvisitors.cpp index f60b59b3684..486356f13b2 100644 --- a/src/plugins/autotest/quick/quicktestvisitors.cpp +++ b/src/plugins/autotest/quick/quicktestvisitors.cpp @@ -152,8 +152,17 @@ bool TestQmlVisitor::visit(QmlJS::AST::FunctionDeclaration *ast) else locationAndType.m_type = TestTreeItem::TestFunction; - m_caseParseStack.top().m_functions.append( - QuickTestFunctionSpec{name.toString(), locationAndType}); + const QString nameStr = name.toString(); + // identical test functions inside the same file are not working - will fail at runtime + if (!Utils::anyOf(m_caseParseStack.top().m_functions, + [nameStr, locationAndType](const QuickTestFunctionSpec func) { + return func.m_locationAndType.m_type == locationAndType.m_type + && func.m_functionName == nameStr + && func.m_locationAndType.m_name == locationAndType.m_name; + })) { + m_caseParseStack.top().m_functions.append( + QuickTestFunctionSpec{nameStr, locationAndType}); + } } return false; } |