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 <nikolai.kosjar@qt.io>
This commit is contained in:
Christian Stenger
2017-10-10 10:05:10 +02:00
parent 094f7120c1
commit fe5ab8da81
2 changed files with 7 additions and 1 deletions

View File

@@ -295,7 +295,10 @@ QSet<QString> GTestTreeItem::internalTargets() const
const auto cppMM = CppTools::CppModelManager::instance(); const auto cppMM = CppTools::CppModelManager::instance();
const auto projectInfo = cppMM->projectInfo(ProjectExplorer::SessionManager::startupProject()); const auto projectInfo = cppMM->projectInfo(ProjectExplorer::SessionManager::startupProject());
const QString file = filePath(); const QString file = filePath();
for (const CppTools::ProjectPart::Ptr projectPart : projectInfo.projectParts()) { const QVector<CppTools::ProjectPart::Ptr> projectParts = projectInfo.projectParts();
if (projectParts.isEmpty())
return TestTreeItem::dependingInternalTargets(cppMM, file);
for (const CppTools::ProjectPart::Ptr projectPart : projectParts) {
if (projectPart->projectFile == proFile() if (projectPart->projectFile == proFile()
&& Utils::anyOf(projectPart->files, [&file] (const CppTools::ProjectFile &pf) { && Utils::anyOf(projectPart->files, [&file] (const CppTools::ProjectFile &pf) {
return pf.path == file; return pf.path == file;

View File

@@ -288,6 +288,9 @@ QSet<QString> TestTreeItem::internalTargets() const
{ {
auto cppMM = CppTools::CppModelManager::instance(); auto cppMM = CppTools::CppModelManager::instance();
const QList<CppTools::ProjectPart::Ptr> projectParts = cppMM->projectPart(m_filePath); const QList<CppTools::ProjectPart::Ptr> 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<QString> targets; QSet<QString> targets;
for (const CppTools::ProjectPart::Ptr part : projectParts) { for (const CppTools::ProjectPart::Ptr part : projectParts) {
targets.insert(part->buildSystemTarget + '|' + part->projectFile); targets.insert(part->buildSystemTarget + '|' + part->projectFile);