From fe5ab8da815434d43da85df45bf7425a85dce5f0 Mon Sep 17 00:00:00 2001 From: Christian Stenger Date: Tue, 10 Oct 2017 10:05:10 +0200 Subject: [PATCH] AutoTest: Fix retrieval of build system target If we failed to find a project part for the respective file it is most likely that we had a header with declarations only but we can still find depending targets for this file. Task-number: QTCREATORBUG-18922 Change-Id: I80d0af569bbd6c2a41bf498fb55283704f16439c Reviewed-by: Nikolai Kosjar --- src/plugins/autotest/gtest/gtesttreeitem.cpp | 5 ++++- src/plugins/autotest/testtreeitem.cpp | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/plugins/autotest/gtest/gtesttreeitem.cpp b/src/plugins/autotest/gtest/gtesttreeitem.cpp index 3b2c680fe98..b0f11830383 100644 --- a/src/plugins/autotest/gtest/gtesttreeitem.cpp +++ b/src/plugins/autotest/gtest/gtesttreeitem.cpp @@ -295,7 +295,10 @@ QSet GTestTreeItem::internalTargets() const const auto cppMM = CppTools::CppModelManager::instance(); const auto projectInfo = cppMM->projectInfo(ProjectExplorer::SessionManager::startupProject()); const QString file = filePath(); - for (const CppTools::ProjectPart::Ptr projectPart : projectInfo.projectParts()) { + const QVector projectParts = projectInfo.projectParts(); + if (projectParts.isEmpty()) + return TestTreeItem::dependingInternalTargets(cppMM, file); + for (const CppTools::ProjectPart::Ptr projectPart : projectParts) { if (projectPart->projectFile == proFile() && Utils::anyOf(projectPart->files, [&file] (const CppTools::ProjectFile &pf) { return pf.path == file; diff --git a/src/plugins/autotest/testtreeitem.cpp b/src/plugins/autotest/testtreeitem.cpp index d27c689e5b0..05eab8439fd 100644 --- a/src/plugins/autotest/testtreeitem.cpp +++ b/src/plugins/autotest/testtreeitem.cpp @@ -288,6 +288,9 @@ QSet TestTreeItem::internalTargets() const { auto cppMM = CppTools::CppModelManager::instance(); const QList projectParts = cppMM->projectPart(m_filePath); + // if we have no project parts it's most likely a header with declarations only and CMake based + if (projectParts.isEmpty()) + return TestTreeItem::dependingInternalTargets(cppMM, m_filePath); QSet targets; for (const CppTools::ProjectPart::Ptr part : projectParts) { targets.insert(part->buildSystemTarget + '|' + part->projectFile);