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 | |
parent | abe3dde5d6af4c1400e19aa3a849812564739c63 (diff) | |
download | qt-creator-8cd7a119262c226e575c0beda45a1af71a32baf5.tar.gz |
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>
6 files changed, 37 insertions, 10 deletions
diff --git a/src/plugins/autotest/autotestunittests.cpp b/src/plugins/autotest/autotestunittests.cpp index b571ed1354..4897e98efa 100644 --- a/src/plugins/autotest/autotestunittests.cpp +++ b/src/plugins/autotest/autotestunittests.cpp @@ -131,13 +131,13 @@ void AutoTestUnitTests::testCodeParser_data() << 1 << 0 << 0 << 0; QTest::newRow("mixedAutoTestAndQuickTests") << QString(m_tmpDir->path() + "/mixed_atp/mixed_atp.pro") - << 4 << 10 << 4 << 10; + << 4 << 10 << 5 << 10; QTest::newRow("plainAutoTestQbs") << QString(m_tmpDir->path() + "/plain/plain.qbs") << 1 << 0 << 0 << 0; QTest::newRow("mixedAutoTestAndQuickTestsQbs") << QString(m_tmpDir->path() + "/mixed_atp/mixed_atp.qbs") - << 4 << 10 << 4 << 10; + << 4 << 10 << 5 << 10; } void AutoTestUnitTests::testCodeParserSwitchStartup() @@ -184,7 +184,7 @@ void AutoTestUnitTests::testCodeParserSwitchStartup_data() QList<int> expectedAutoTests = QList<int>() << 1 << 4 << 1 << 4; QList<int> expectedNamedQuickTests = QList<int>() << 0 << 10 << 0 << 10; - QList<int> expectedUnnamedQuickTests = QList<int>() << 0 << 4 << 0 << 4; + QList<int> expectedUnnamedQuickTests = QList<int>() << 0 << 5 << 0 << 5; QList<int> expectedDataTagsCount = QList<int>() << 0 << 10 << 0 << 10; QTest::newRow("loadMultipleProjects") diff --git a/src/plugins/autotest/qtest/qttestresult.cpp b/src/plugins/autotest/qtest/qttestresult.cpp index 3e85c36e68..65ec0c8270 100644 --- a/src/plugins/autotest/qtest/qttestresult.cpp +++ b/src/plugins/autotest/qtest/qttestresult.cpp @@ -95,7 +95,8 @@ bool QtTestResult::isDirectParentOf(const TestResult *other, bool *needsIntermed return qtOther->m_dataTag == m_dataTag; } } else if (qtOther->isTestFunction()) { - return isTestCase() || m_function == qtOther->m_function; + return isTestCase() || (m_function == qtOther->m_function + && qtOther->result() != ResultType::TestStart); } } return false; diff --git a/src/plugins/autotest/quick/quicktesttreeitem.cpp b/src/plugins/autotest/quick/quicktesttreeitem.cpp index c18de0ee9e..85f459ea01 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 a9e48fca94..551d0865a2 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 f60b59b368..486356f13b 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; } diff --git a/src/plugins/autotest/unit_test/mixed_atp/tests/auto/quickauto/tst_test2.qml b/src/plugins/autotest/unit_test/mixed_atp/tests/auto/quickauto/tst_test2.qml index b6330ac4ea..68fd193c52 100644 --- a/src/plugins/autotest/unit_test/mixed_atp/tests/auto/quickauto/tst_test2.qml +++ b/src/plugins/autotest/unit_test/mixed_atp/tests/auto/quickauto/tst_test2.qml @@ -67,5 +67,11 @@ TestCase { verify(true); } } + + TestCase { // 2nd unnamed with same function name - legal as long it's a different TestCase + function test_func() { + verify(true); + } + } } |