forked from qt-creator/qt-creator
ClangStaticAnalyzer: Tests: Rely on projects telling when they finished parsing
We relied on the CppModelManager to tell us whether a project was reparsed after a kit change. While this worked, it was not guaranteed that the project is really finished (and ready for e.g. building) after pushing new ProjectInfos to the CppModelManager. Rely on the projects telling when they are finished with parsing. This is more accurate and future-proof. The introduced signals in Project and SessionManager are (at the moment) only for tests. Change-Id: I1b368ec4585ffa8755eb28fac6d187cce31243ee Reviewed-by: Tobias Hunger <tobias.hunger@qt.io> Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -129,6 +129,8 @@ void AppManagerProject::populateProject()
|
||||
foreach (ProjectExplorer::Target *target, targets())
|
||||
targetUpdateDeployableFiles(target, files);
|
||||
}
|
||||
|
||||
emit parsingFinished();
|
||||
}
|
||||
|
||||
void AppManagerProject::recursiveScanDirectory(const QDir &dir, QSet<QString> &container)
|
||||
|
@@ -231,6 +231,8 @@ void AutotoolsProject::makefileParsingFinished()
|
||||
|
||||
m_makefileParserThread->deleteLater();
|
||||
m_makefileParserThread = 0;
|
||||
|
||||
emit parsingFinished();
|
||||
}
|
||||
|
||||
void AutotoolsProject::onFileChanged(const QString &file)
|
||||
|
@@ -29,7 +29,6 @@
|
||||
#include "clangstaticanalyzertool.h"
|
||||
#include "clangstaticanalyzerutils.h"
|
||||
|
||||
#include <cpptools/cppmodelmanager.h>
|
||||
#include <cpptools/projectinfo.h>
|
||||
#include <projectexplorer/kitinformation.h>
|
||||
#include <projectexplorer/kitmanager.h>
|
||||
@@ -44,6 +43,7 @@
|
||||
#include <QSignalSpy>
|
||||
#include <QTimer>
|
||||
#include <QtTest>
|
||||
#include <QVariant>
|
||||
|
||||
#include <functional>
|
||||
|
||||
@@ -66,6 +66,35 @@ static bool processEventsUntil(const std::function<bool()> condition, int timeOu
|
||||
}
|
||||
}
|
||||
|
||||
class WaitForParsedProjects : public QObject
|
||||
{
|
||||
public:
|
||||
WaitForParsedProjects(ProjectExplorer::SessionManager &sessionManager,
|
||||
const QStringList &projects)
|
||||
: m_sessionManager(sessionManager)
|
||||
, m_projectsToWaitFor(projects)
|
||||
{
|
||||
connect(&m_sessionManager, &ProjectExplorer::SessionManager::projectFinishedParsing,
|
||||
this, &WaitForParsedProjects::onProjectFinishedParsing);
|
||||
}
|
||||
|
||||
void onProjectFinishedParsing(ProjectExplorer::Project *project)
|
||||
{
|
||||
m_projectsToWaitFor.removeOne(project->projectFilePath().toString());
|
||||
}
|
||||
|
||||
bool wait()
|
||||
{
|
||||
return processEventsUntil([this]() {
|
||||
return m_projectsToWaitFor.isEmpty();
|
||||
});
|
||||
}
|
||||
|
||||
private:
|
||||
ProjectExplorer::SessionManager &m_sessionManager;
|
||||
QStringList m_projectsToWaitFor;
|
||||
};
|
||||
|
||||
namespace ClangStaticAnalyzer {
|
||||
namespace Internal {
|
||||
|
||||
@@ -84,16 +113,14 @@ void ClangStaticAnalyzerPreconfiguredSessionTests::initTestCase()
|
||||
if (!m_sessionManager.sessions().contains(preconfiguredSessionName))
|
||||
QSKIP("Manually preconfigured session 'ClangStaticAnalyzerPreconfiguredSession' needed.");
|
||||
|
||||
// Load session
|
||||
if (m_sessionManager.activeSession() != preconfiguredSessionName)
|
||||
QVERIFY(m_sessionManager.loadSession(preconfiguredSessionName));
|
||||
if (m_sessionManager.activeSession() == preconfiguredSessionName)
|
||||
QSKIP("Session must not be already active.");
|
||||
|
||||
// Wait until all projects are loaded.
|
||||
const int sessionManagerProjects = m_sessionManager.projects().size();
|
||||
const auto allProjectsLoaded = [sessionManagerProjects]() {
|
||||
return CppModelManager::instance()->projectInfos().size() == sessionManagerProjects;
|
||||
};
|
||||
QVERIFY(processEventsUntil(allProjectsLoaded));
|
||||
// Load session
|
||||
const QStringList projects = m_sessionManager.projectsForSessionName(preconfiguredSessionName);
|
||||
WaitForParsedProjects waitForParsedProjects(m_sessionManager, projects);
|
||||
QVERIFY(m_sessionManager.loadSession(preconfiguredSessionName));
|
||||
QVERIFY(waitForParsedProjects.wait());
|
||||
}
|
||||
|
||||
void ClangStaticAnalyzerPreconfiguredSessionTests::testPreconfiguredSession()
|
||||
@@ -201,15 +228,15 @@ bool ClangStaticAnalyzerPreconfiguredSessionTests::switchToProjectAndTarget(Proj
|
||||
m_sessionManager.setStartupProject(project);
|
||||
|
||||
if (target != project->activeTarget()) {
|
||||
QSignalSpy waitUntilProjectUpdated(CppModelManager::instance(),
|
||||
&CppModelManager::projectPartsUpdated);
|
||||
QSignalSpy spyFinishedParsing(ProjectExplorer::SessionManager::instance(),
|
||||
&ProjectExplorer::SessionManager::projectFinishedParsing);
|
||||
m_sessionManager.setActiveTarget(project, target, ProjectExplorer::SetActive::NoCascade);
|
||||
QTC_ASSERT(spyFinishedParsing.wait(30000), return false);
|
||||
|
||||
const bool waitResult = waitUntilProjectUpdated.wait(30000);
|
||||
if (!waitResult) {
|
||||
qWarning() << "waitUntilProjectUpdated() failed";
|
||||
return false;
|
||||
}
|
||||
const QVariant projectArgument = spyFinishedParsing.takeFirst().takeFirst();
|
||||
QTC_ASSERT(projectArgument.canConvert<ProjectExplorer::Project *>(), return false);
|
||||
|
||||
return projectArgument.value<ProjectExplorer::Project *>() == project;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@@ -145,6 +145,8 @@ void CMakeProject::updateProjectData()
|
||||
emit fileListChanged();
|
||||
|
||||
emit cmakeBc->emitBuildTypeChanged();
|
||||
|
||||
emit parsingFinished();
|
||||
}
|
||||
|
||||
void CMakeProject::updateQmlJSCodeModel()
|
||||
|
@@ -286,6 +286,7 @@ void GenericProject::refresh(RefreshOptions options)
|
||||
}
|
||||
|
||||
refreshCppCodeModel();
|
||||
emit parsingFinished();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -112,6 +112,8 @@ void NimProject::populateProject()
|
||||
rootProjectNode()->buildTree(fileNodes);
|
||||
|
||||
emit fileListChanged();
|
||||
|
||||
emit parsingFinished();
|
||||
}
|
||||
|
||||
void NimProject::recursiveScanDirectory(const QDir &dir, QSet<QString> &container)
|
||||
|
@@ -168,6 +168,9 @@ signals:
|
||||
void projectContextUpdated();
|
||||
void projectLanguagesUpdated();
|
||||
|
||||
signals: // for tests only
|
||||
void parsingFinished();
|
||||
|
||||
protected:
|
||||
virtual RestoreResult fromMap(const QVariantMap &map, QString *errorMessage);
|
||||
virtual bool setupTarget(Target *t);
|
||||
|
@@ -1684,6 +1684,9 @@ ProjectExplorerPlugin::OpenProjectResult ProjectExplorerPlugin::openProjects(con
|
||||
foundProjectManager = true;
|
||||
QString tmp;
|
||||
if (Project *pro = manager->openProject(filePath, &tmp)) {
|
||||
QObject::connect(pro, &Project::parsingFinished, [pro]() {
|
||||
emit SessionManager::instance()->projectFinishedParsing(pro);
|
||||
});
|
||||
QString restoreError;
|
||||
Project::RestoreResult restoreResult = pro->restoreSettings(&restoreError);
|
||||
if (restoreResult == Project::RestoreResult::Ok) {
|
||||
|
@@ -138,6 +138,9 @@ signals:
|
||||
void aboutToSaveSession();
|
||||
void dependencyChanged(ProjectExplorer::Project *a, ProjectExplorer::Project *b);
|
||||
|
||||
signals: // for tests only
|
||||
void projectFinishedParsing(ProjectExplorer::Project *project);
|
||||
|
||||
private:
|
||||
static void saveActiveMode(Core::Id mode);
|
||||
void clearProjectFileCache();
|
||||
|
@@ -619,6 +619,8 @@ void PythonProject::refresh()
|
||||
return new PythonFileNode(FileName::fromString(f), displayName);
|
||||
});
|
||||
rootProjectNode()->buildTree(fileNodes);
|
||||
|
||||
emit parsingFinished();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -503,6 +503,7 @@ void QbsProject::handleQbsParsingDone(bool success)
|
||||
if (dataChanged)
|
||||
updateAfterParse();
|
||||
emit projectParsingDone(success);
|
||||
emit parsingFinished();
|
||||
}
|
||||
|
||||
void QbsProject::handleRuleExecutionDone()
|
||||
|
@@ -753,6 +753,7 @@ void QmakeProject::decrementPendingEvaluateFutures()
|
||||
activeTarget()->updateDefaultDeployConfigurations();
|
||||
updateRunConfigurations();
|
||||
emit proFilesEvaluated();
|
||||
emit parsingFinished();
|
||||
if (debug)
|
||||
qDebug()<<" Setting state to Base";
|
||||
}
|
||||
|
@@ -198,6 +198,8 @@ void QmlProject::refresh(RefreshOptions options)
|
||||
QmlJS::Dialect::Qml);
|
||||
|
||||
modelManager()->updateProjectInfo(projectInfo, this);
|
||||
|
||||
emit parsingFinished();
|
||||
}
|
||||
|
||||
QStringList QmlProject::convertToAbsoluteFiles(const QStringList &paths) const
|
||||
|
Reference in New Issue
Block a user