forked from qt-creator/qt-creator
AutoTest: Try harder to find relevant build targets
If there are tests defined or registered inside libraries we ended up trying to execute the library or nothing at all. If possible try to find correct build targets for such cases. Change-Id: I58e9edb7f858e3e5407ece6fcb8782f5a129acd0 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
@@ -296,13 +296,13 @@ QSet<QString> GTestTreeItem::internalTargets() const
|
||||
const auto projectInfo = cppMM->projectInfo(ProjectExplorer::SessionManager::startupProject());
|
||||
const QString file = filePath();
|
||||
for (const CppTools::ProjectPart::Ptr projectPart : projectInfo.projectParts()) {
|
||||
if (projectPart->buildTargetType != CppTools::ProjectPart::Executable)
|
||||
continue;
|
||||
if (projectPart->projectFile == proFile()
|
||||
&& Utils::anyOf(projectPart->files, [&file] (const CppTools::ProjectFile &pf) {
|
||||
return pf.path == file;
|
||||
})) {
|
||||
result.insert(projectPart->buildSystemTarget + '|' + projectPart->projectFile);
|
||||
if (projectPart->buildTargetType != CppTools::ProjectPart::Executable)
|
||||
result.unite(TestTreeItem::dependingInternalTargets(cppMM, file));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
|
||||
#include <cplusplus/Icons.h>
|
||||
#include <cpptools/cppmodelmanager.h>
|
||||
#include <cpptools/cpptoolsreuse.h>
|
||||
#include <texteditor/texteditor.h>
|
||||
|
||||
#include <QIcon>
|
||||
@@ -286,12 +287,12 @@ bool TestTreeItem::lessThan(const TestTreeItem *other, SortMode mode) const
|
||||
QSet<QString> TestTreeItem::internalTargets() const
|
||||
{
|
||||
auto cppMM = CppTools::CppModelManager::instance();
|
||||
const QList<CppTools::ProjectPart::Ptr> projectParts = cppMM->projectPart(filePath());
|
||||
const QList<CppTools::ProjectPart::Ptr> projectParts = cppMM->projectPart(m_filePath);
|
||||
QSet<QString> targets;
|
||||
for (const CppTools::ProjectPart::Ptr part : projectParts) {
|
||||
if (part->buildTargetType != CppTools::ProjectPart::Executable)
|
||||
continue;
|
||||
targets.insert(part->buildSystemTarget + '|' + part->projectFile);
|
||||
if (part->buildTargetType != CppTools::ProjectPart::Executable)
|
||||
targets.unite(TestTreeItem::dependingInternalTargets(cppMM, m_filePath));
|
||||
}
|
||||
return targets;
|
||||
}
|
||||
@@ -359,5 +360,28 @@ TestTreeItem *TestTreeItem::findChildBy(CompareFunction compare) const
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/*
|
||||
* try to find build system target that depends on the given file - if the file is no header
|
||||
* try to find the corresponding header and use this instead to find the respective target
|
||||
*/
|
||||
QSet<QString> TestTreeItem::dependingInternalTargets(CppTools::CppModelManager *cppMM,
|
||||
const QString &file)
|
||||
{
|
||||
QSet<QString> result;
|
||||
QTC_ASSERT(cppMM, return result);
|
||||
const CPlusPlus::Snapshot snapshot = cppMM->snapshot();
|
||||
QTC_ASSERT(snapshot.contains(file), return result);
|
||||
bool wasHeader;
|
||||
const QString correspondingFile
|
||||
= CppTools::correspondingHeaderOrSource(file, &wasHeader, CppTools::CacheUsage::ReadOnly);
|
||||
const Utils::FileNameList dependingFiles = snapshot.filesDependingOn(
|
||||
wasHeader ? file : correspondingFile);
|
||||
for (const Utils::FileName &fn : dependingFiles) {
|
||||
for (const CppTools::ProjectPart::Ptr part : cppMM->projectPart(fn))
|
||||
result.insert(part->buildSystemTarget + '|' + part->projectFile);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace Autotest
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include <utils/treemodel.h>
|
||||
|
||||
#include <QList>
|
||||
#include <QSet>
|
||||
#include <QString>
|
||||
#include <QMetaType>
|
||||
|
||||
@@ -40,6 +41,8 @@ namespace {
|
||||
};
|
||||
}
|
||||
|
||||
namespace CppTools { class CppModelManager; }
|
||||
|
||||
namespace Autotest {
|
||||
namespace Internal {
|
||||
|
||||
@@ -114,6 +117,8 @@ public:
|
||||
protected:
|
||||
typedef std::function<bool(const TestTreeItem *)> CompareFunction;
|
||||
TestTreeItem *findChildBy(CompareFunction compare) const;
|
||||
static QSet<QString> dependingInternalTargets(CppTools::CppModelManager *cppMM,
|
||||
const QString &file);
|
||||
|
||||
private:
|
||||
void revalidateCheckState();
|
||||
|
||||
@@ -357,7 +357,8 @@ static int commonFilePathLength(const QString &s1, const QString &s2)
|
||||
|
||||
static QString correspondingHeaderOrSourceInProject(const QFileInfo &fileInfo,
|
||||
const QStringList &candidateFileNames,
|
||||
const ProjectExplorer::Project *project)
|
||||
const ProjectExplorer::Project *project,
|
||||
CacheUsage cacheUsage)
|
||||
{
|
||||
QString bestFileName;
|
||||
int compareValue = 0;
|
||||
@@ -376,8 +377,10 @@ static QString correspondingHeaderOrSourceInProject(const QFileInfo &fileInfo,
|
||||
if (!bestFileName.isEmpty()) {
|
||||
const QFileInfo candidateFi(bestFileName);
|
||||
QTC_ASSERT(candidateFi.isFile(), return QString());
|
||||
m_headerSourceMapping[fileInfo.absoluteFilePath()] = candidateFi.absoluteFilePath();
|
||||
m_headerSourceMapping[candidateFi.absoluteFilePath()] = fileInfo.absoluteFilePath();
|
||||
if (cacheUsage == CacheUsage::ReadWrite) {
|
||||
m_headerSourceMapping[fileInfo.absoluteFilePath()] = candidateFi.absoluteFilePath();
|
||||
m_headerSourceMapping[candidateFi.absoluteFilePath()] = fileInfo.absoluteFilePath();
|
||||
}
|
||||
return candidateFi.absoluteFilePath();
|
||||
}
|
||||
|
||||
@@ -386,7 +389,7 @@ static QString correspondingHeaderOrSourceInProject(const QFileInfo &fileInfo,
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
QString correspondingHeaderOrSource(const QString &fileName, bool *wasHeader)
|
||||
QString correspondingHeaderOrSource(const QString &fileName, bool *wasHeader, CacheUsage cacheUsage)
|
||||
{
|
||||
using namespace Internal;
|
||||
|
||||
@@ -437,9 +440,11 @@ QString correspondingHeaderOrSource(const QString &fileName, bool *wasHeader)
|
||||
const QString normalized = Utils::FileUtils::normalizePathName(candidateFilePath);
|
||||
const QFileInfo candidateFi(normalized);
|
||||
if (candidateFi.isFile()) {
|
||||
m_headerSourceMapping[fi.absoluteFilePath()] = candidateFi.absoluteFilePath();
|
||||
if (!isHeader || !baseName.endsWith(privateHeaderSuffix))
|
||||
m_headerSourceMapping[candidateFi.absoluteFilePath()] = fi.absoluteFilePath();
|
||||
if (cacheUsage == CacheUsage::ReadWrite) {
|
||||
m_headerSourceMapping[fi.absoluteFilePath()] = candidateFi.absoluteFilePath();
|
||||
if (!isHeader || !baseName.endsWith(privateHeaderSuffix))
|
||||
m_headerSourceMapping[candidateFi.absoluteFilePath()] = fi.absoluteFilePath();
|
||||
}
|
||||
return candidateFi.absoluteFilePath();
|
||||
}
|
||||
}
|
||||
@@ -449,7 +454,7 @@ QString correspondingHeaderOrSource(const QString &fileName, bool *wasHeader)
|
||||
ProjectExplorer::Project *currentProject = ProjectExplorer::ProjectTree::currentProject();
|
||||
if (currentProject) {
|
||||
const QString path = correspondingHeaderOrSourceInProject(fi, candidateFileNames,
|
||||
currentProject);
|
||||
currentProject, cacheUsage);
|
||||
if (!path.isEmpty())
|
||||
return path;
|
||||
|
||||
@@ -462,7 +467,8 @@ QString correspondingHeaderOrSource(const QString &fileName, bool *wasHeader)
|
||||
if (project == currentProject)
|
||||
continue; // We have already checked the current project.
|
||||
|
||||
const QString path = correspondingHeaderOrSourceInProject(fi, candidateFileNames, project);
|
||||
const QString path = correspondingHeaderOrSourceInProject(fi, candidateFileNames,
|
||||
project, cacheUsage);
|
||||
if (!path.isEmpty())
|
||||
return path;
|
||||
}
|
||||
|
||||
@@ -68,7 +68,10 @@ bool CPPTOOLS_EXPORT isOwnershipRAIIType(CPlusPlus::Symbol *symbol,
|
||||
const CPlusPlus::Macro CPPTOOLS_EXPORT *findCanonicalMacro(const QTextCursor &cursor,
|
||||
CPlusPlus::Document::Ptr document);
|
||||
|
||||
QString CPPTOOLS_EXPORT correspondingHeaderOrSource(const QString &fileName, bool *wasHeader = 0);
|
||||
enum class CacheUsage { ReadWrite, ReadOnly };
|
||||
|
||||
QString CPPTOOLS_EXPORT correspondingHeaderOrSource(const QString &fileName, bool *wasHeader = 0,
|
||||
CacheUsage cacheUsage = CacheUsage::ReadWrite);
|
||||
void CPPTOOLS_EXPORT switchHeaderSource();
|
||||
|
||||
class CppCodeModelSettings;
|
||||
|
||||
Reference in New Issue
Block a user