From ca82019cf0febe6f58d7aab53e2e99a56d69004d Mon Sep 17 00:00:00 2001 From: Christian Stenger Date: Wed, 25 Mar 2020 16:29:04 +0100 Subject: [PATCH] AutoTest: Fix flakyness of plugin test Relying on the order of tests of the underlying tree model is bad as we order the model for the user with a QSortFilterProxyModel. Using non-unique keys is not wise either. Ensure the keys are unique to have reliable results. Change-Id: I556371d018c16e7b03a8ec85d60afc850056a94a Reviewed-by: David Schulz --- src/plugins/autotest/autotestunittests.cpp | 29 +++++++++++++++------- src/plugins/autotest/testtreemodel.cpp | 6 ++--- src/plugins/autotest/testtreemodel.h | 2 +- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/plugins/autotest/autotestunittests.cpp b/src/plugins/autotest/autotestunittests.cpp index 4897e98efae..767aee6a137 100644 --- a/src/plugins/autotest/autotestunittests.cpp +++ b/src/plugins/autotest/autotestunittests.cpp @@ -246,6 +246,7 @@ void AutoTestUnitTests::testCodeParserBoostTest() QSKIP("This test needs boost - set BOOST_INCLUDE_DIR (or have it installed)"); QFETCH(QString, projectFilePath); + QFETCH(QString, extension); CppTools::Tests::ProjectOpenerAndCloser projectManager; CppTools::ProjectInfo projectInfo = projectManager.open(projectFilePath, true); QVERIFY(projectInfo.isValid()); @@ -257,14 +258,23 @@ void AutoTestUnitTests::testCodeParserBoostTest() QCOMPARE(m_model->boostTestNamesCount(), 5); - QMultiMap expectedSuitesAndTests; - expectedSuitesAndTests.insert(QStringLiteral("Master Test Suite"), 2); // decorators w/o suite - expectedSuitesAndTests.insert(QStringLiteral("Master Test Suite"), 2); // fixtures - expectedSuitesAndTests.insert(QStringLiteral("Master Test Suite"), 3); // functions - expectedSuitesAndTests.insert(QStringLiteral("Suite1"), 4); - expectedSuitesAndTests.insert(QStringLiteral("SuiteOuter"), 5); // 2 sub suites + 3 tests + QString basePath; + if (auto project = projectInfo.project()) + basePath = project->projectFilePath().toFileInfo().absolutePath(); + QVERIFY(!basePath.isEmpty()); - QMultiMap foundNamesAndSets = m_model->boostTestSuitesAndTests(); + QMap expectedSuitesAndTests; + + auto pathConstructor = [basePath, extension](const QString &name, const QString &subPath) { + return QString(name + '|' + basePath + subPath + extension); + }; + expectedSuitesAndTests.insert(pathConstructor("Master Test Suite", "/tests/deco/deco"), 2); // decorators w/o suite + expectedSuitesAndTests.insert(pathConstructor("Master Test Suite", "/tests/fix/fix"), 2); // fixtures + expectedSuitesAndTests.insert(pathConstructor("Master Test Suite", "/tests/params/params"), 3); // functions + expectedSuitesAndTests.insert(pathConstructor("Suite1", "/tests/deco/deco"), 4); + expectedSuitesAndTests.insert(pathConstructor("SuiteOuter", "/tests/deco/deco"), 5); // 2 sub suites + 3 tests + + QMap foundNamesAndSets = m_model->boostTestSuitesAndTests(); QCOMPARE(expectedSuitesAndTests.size(), foundNamesAndSets.size()); for (const QString &name : expectedSuitesAndTests.keys()) QCOMPARE(expectedSuitesAndTests.values(name), foundNamesAndSets.values(name)); @@ -280,10 +290,11 @@ void AutoTestUnitTests::testCodeParserBoostTest() void AutoTestUnitTests::testCodeParserBoostTest_data() { QTest::addColumn("projectFilePath"); + QTest::addColumn("extension"); QTest::newRow("simpleBoostTest") - << QString(m_tmpDir->path() + "/simple_boost/simple_boost.pro"); + << QString(m_tmpDir->path() + "/simple_boost/simple_boost.pro") << QString(".pro"); QTest::newRow("simpleBoostTestQbs") - << QString(m_tmpDir->path() + "/simple_boost/simple_boost.qbs"); + << QString(m_tmpDir->path() + "/simple_boost/simple_boost.qbs") << QString(".qbs"); } } // namespace Internal diff --git a/src/plugins/autotest/testtreemodel.cpp b/src/plugins/autotest/testtreemodel.cpp index b4f3e06d892..22d4b3921e9 100644 --- a/src/plugins/autotest/testtreemodel.cpp +++ b/src/plugins/autotest/testtreemodel.cpp @@ -615,13 +615,13 @@ int TestTreeModel::boostTestNamesCount() const return rootNode ? rootNode->childCount() : 0; } -QMultiMap TestTreeModel::boostTestSuitesAndTests() const +QMap TestTreeModel::boostTestSuitesAndTests() const { - QMultiMap result; + QMap result; if (TestTreeItem *rootNode = boostTestRootNode()) { rootNode->forFirstLevelChildren([&result](TestTreeItem *child) { - result.insert(child->name(), child->childCount()); + result.insert(child->name() + '|' + child->proFile(), child->childCount()); }); } return result; diff --git a/src/plugins/autotest/testtreemodel.h b/src/plugins/autotest/testtreemodel.h index c22a8f8d493..895d71bbacb 100644 --- a/src/plugins/autotest/testtreemodel.h +++ b/src/plugins/autotest/testtreemodel.h @@ -71,7 +71,7 @@ public: int gtestNamesCount() const; QMultiMap gtestNamesAndSets() const; int boostTestNamesCount() const; - QMultiMap boostTestSuitesAndTests() const; + QMap boostTestSuitesAndTests() const; #endif void markAllForRemoval();