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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user