forked from qt-creator/qt-creator
Fix plugin unit tests when using projects
The ClangTools and the AutoTest plugins use an internal mechanism to load and configure a project when performing their integrated unit tests. Both assumed to have exactly one kit present for these tests. Make it possible to have more kits present when starting with existing settings or if more kits get automatically generated when starting with clean settings. Change-Id: If2bc66320c4854f1d34a19d17107e8f0b7d64d39 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -61,13 +61,20 @@ AutoTestUnitTests::AutoTestUnitTests(TestTreeModel *model, QObject *parent)
|
|||||||
void AutoTestUnitTests::initTestCase()
|
void AutoTestUnitTests::initTestCase()
|
||||||
{
|
{
|
||||||
const QList<Kit *> allKits = KitManager::kits();
|
const QList<Kit *> allKits = KitManager::kits();
|
||||||
if (allKits.count() != 1)
|
if (allKits.count() == 0)
|
||||||
QSKIP("This test requires exactly one kit to be present");
|
QSKIP("This test requires at least one kit to be present");
|
||||||
if (auto qtVersion = QtSupport::QtKitAspect::qtVersion(allKits.first()))
|
|
||||||
|
m_kit = findOr(allKits, nullptr, [](Kit *k) {
|
||||||
|
return k->isValid() && QtSupport::QtKitAspect::qtVersion(k) != nullptr;
|
||||||
|
});
|
||||||
|
if (!m_kit)
|
||||||
|
QSKIP("The test requires at least one valid kit with a valid Qt");
|
||||||
|
|
||||||
|
if (auto qtVersion = QtSupport::QtKitAspect::qtVersion(m_kit))
|
||||||
m_isQt4 = qtVersion->qtVersionString().startsWith('4');
|
m_isQt4 = qtVersion->qtVersionString().startsWith('4');
|
||||||
else
|
else
|
||||||
QSKIP("Could not figure out which Qt version is used for default kit.");
|
QSKIP("Could not figure out which Qt version is used for default kit.");
|
||||||
const ToolChain * const toolchain = ToolChainKitAspect::cxxToolChain(allKits.first());
|
const ToolChain * const toolchain = ToolChainKitAspect::cxxToolChain(m_kit);
|
||||||
if (!toolchain)
|
if (!toolchain)
|
||||||
QSKIP("This test requires that there is a kit with a toolchain.");
|
QSKIP("This test requires that there is a kit with a toolchain.");
|
||||||
|
|
||||||
@@ -99,7 +106,7 @@ void AutoTestUnitTests::testCodeParser()
|
|||||||
QFETCH(int, expectedDataTagsCount);
|
QFETCH(int, expectedDataTagsCount);
|
||||||
|
|
||||||
CppTools::Tests::ProjectOpenerAndCloser projectManager;
|
CppTools::Tests::ProjectOpenerAndCloser projectManager;
|
||||||
const CppTools::ProjectInfo projectInfo = projectManager.open(projectFilePath, true);
|
const CppTools::ProjectInfo projectInfo = projectManager.open(projectFilePath, true, m_kit);
|
||||||
QVERIFY(projectInfo.isValid());
|
QVERIFY(projectInfo.isValid());
|
||||||
|
|
||||||
QSignalSpy parserSpy(m_model->parser(), SIGNAL(parsingFinished()));
|
QSignalSpy parserSpy(m_model->parser(), SIGNAL(parsingFinished()));
|
||||||
@@ -150,7 +157,7 @@ void AutoTestUnitTests::testCodeParserSwitchStartup()
|
|||||||
CppTools::Tests::ProjectOpenerAndCloser projectManager;
|
CppTools::Tests::ProjectOpenerAndCloser projectManager;
|
||||||
for (int i = 0; i < projectFilePaths.size(); ++i) {
|
for (int i = 0; i < projectFilePaths.size(); ++i) {
|
||||||
qDebug() << "Opening project" << projectFilePaths.at(i);
|
qDebug() << "Opening project" << projectFilePaths.at(i);
|
||||||
CppTools::ProjectInfo projectInfo = projectManager.open(projectFilePaths.at(i), true);
|
CppTools::ProjectInfo projectInfo = projectManager.open(projectFilePaths.at(i), true, m_kit);
|
||||||
QVERIFY(projectInfo.isValid());
|
QVERIFY(projectInfo.isValid());
|
||||||
|
|
||||||
QSignalSpy parserSpy(m_model->parser(), SIGNAL(parsingFinished()));
|
QSignalSpy parserSpy(m_model->parser(), SIGNAL(parsingFinished()));
|
||||||
@@ -198,7 +205,7 @@ void AutoTestUnitTests::testCodeParserGTest()
|
|||||||
|
|
||||||
QFETCH(QString, projectFilePath);
|
QFETCH(QString, projectFilePath);
|
||||||
CppTools::Tests::ProjectOpenerAndCloser projectManager;
|
CppTools::Tests::ProjectOpenerAndCloser projectManager;
|
||||||
CppTools::ProjectInfo projectInfo = projectManager.open(projectFilePath, true);
|
CppTools::ProjectInfo projectInfo = projectManager.open(projectFilePath, true, m_kit);
|
||||||
QVERIFY(projectInfo.isValid());
|
QVERIFY(projectInfo.isValid());
|
||||||
|
|
||||||
QSignalSpy parserSpy(m_model->parser(), SIGNAL(parsingFinished()));
|
QSignalSpy parserSpy(m_model->parser(), SIGNAL(parsingFinished()));
|
||||||
@@ -247,7 +254,7 @@ void AutoTestUnitTests::testCodeParserBoostTest()
|
|||||||
QFETCH(QString, projectFilePath);
|
QFETCH(QString, projectFilePath);
|
||||||
QFETCH(QString, extension);
|
QFETCH(QString, extension);
|
||||||
CppTools::Tests::ProjectOpenerAndCloser projectManager;
|
CppTools::Tests::ProjectOpenerAndCloser projectManager;
|
||||||
CppTools::ProjectInfo projectInfo = projectManager.open(projectFilePath, true);
|
CppTools::ProjectInfo projectInfo = projectManager.open(projectFilePath, true, m_kit);
|
||||||
QVERIFY(projectInfo.isValid());
|
QVERIFY(projectInfo.isValid());
|
||||||
|
|
||||||
QSignalSpy parserSpy(m_model->parser(), SIGNAL(parsingFinished()));
|
QSignalSpy parserSpy(m_model->parser(), SIGNAL(parsingFinished()));
|
||||||
|
@@ -28,6 +28,7 @@
|
|||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
namespace CppTools { namespace Tests { class TemporaryCopiedDir; } }
|
namespace CppTools { namespace Tests { class TemporaryCopiedDir; } }
|
||||||
|
namespace ProjectExplorer { class Kit; }
|
||||||
|
|
||||||
namespace Autotest {
|
namespace Autotest {
|
||||||
|
|
||||||
@@ -60,6 +61,7 @@ private:
|
|||||||
CppTools::Tests::TemporaryCopiedDir *m_tmpDir = nullptr;
|
CppTools::Tests::TemporaryCopiedDir *m_tmpDir = nullptr;
|
||||||
bool m_isQt4 = false;
|
bool m_isQt4 = false;
|
||||||
bool m_checkBoost = false;
|
bool m_checkBoost = false;
|
||||||
|
ProjectExplorer::Kit *m_kit = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
@@ -235,7 +235,7 @@ bool OpenProjectCommand::run()
|
|||||||
QTC_ASSERT(openProjectSucceeded, return false);
|
QTC_ASSERT(openProjectSucceeded, return false);
|
||||||
|
|
||||||
Project *project = openProjectSucceeded.project();
|
Project *project = openProjectSucceeded.project();
|
||||||
project->configureAsExampleProject();
|
project->configureAsExampleProject(nullptr);
|
||||||
|
|
||||||
return CppTools::Tests::TestCase::waitUntilProjectIsFullyOpened(project, timeOutInMs());
|
return CppTools::Tests::TestCase::waitUntilProjectIsFullyOpened(project, timeOutInMs());
|
||||||
}
|
}
|
||||||
|
@@ -40,6 +40,8 @@
|
|||||||
#include <projectexplorer/projectexplorer.h>
|
#include <projectexplorer/projectexplorer.h>
|
||||||
#include <projectexplorer/toolchain.h>
|
#include <projectexplorer/toolchain.h>
|
||||||
|
|
||||||
|
#include <qtsupport/qtkitinformation.h>
|
||||||
|
|
||||||
#include <utils/executeondestruction.h>
|
#include <utils/executeondestruction.h>
|
||||||
#include <utils/fileutils.h>
|
#include <utils/fileutils.h>
|
||||||
|
|
||||||
@@ -60,9 +62,16 @@ namespace Internal {
|
|||||||
void ClangToolsUnitTests::initTestCase()
|
void ClangToolsUnitTests::initTestCase()
|
||||||
{
|
{
|
||||||
const QList<Kit *> allKits = KitManager::kits();
|
const QList<Kit *> allKits = KitManager::kits();
|
||||||
if (allKits.count() != 1)
|
if (allKits.count() == 0)
|
||||||
QSKIP("This test requires exactly one kit to be present");
|
QSKIP("This test requires at least one kit to be present");
|
||||||
const ToolChain *const toolchain = ToolChainKitAspect::cxxToolChain(allKits.first());
|
|
||||||
|
m_kit = findOr(allKits, nullptr, [](Kit *k) {
|
||||||
|
return k->isValid() && QtSupport::QtKitAspect::qtVersion(k) != nullptr;
|
||||||
|
});
|
||||||
|
if (!m_kit)
|
||||||
|
QSKIP("This test requires at least one valid kit with a valid Qt");
|
||||||
|
|
||||||
|
const ToolChain *const toolchain = ToolChainKitAspect::cxxToolChain(m_kit);
|
||||||
if (!toolchain)
|
if (!toolchain)
|
||||||
QSKIP("This test requires that there is a kit with a toolchain.");
|
QSKIP("This test requires that there is a kit with a toolchain.");
|
||||||
|
|
||||||
@@ -99,14 +108,14 @@ void ClangToolsUnitTests::testProject()
|
|||||||
QFETCH(int, expectedDiagCount);
|
QFETCH(int, expectedDiagCount);
|
||||||
QFETCH(ClangDiagnosticConfig, diagnosticConfig);
|
QFETCH(ClangDiagnosticConfig, diagnosticConfig);
|
||||||
if (projectFilePath.contains("mingw")) {
|
if (projectFilePath.contains("mingw")) {
|
||||||
const auto toolchain = ToolChainKitAspect::cxxToolChain(KitManager::kits().constFirst());
|
const auto toolchain = ToolChainKitAspect::cxxToolChain(m_kit);
|
||||||
if (toolchain->typeId() != ProjectExplorer::Constants::MINGW_TOOLCHAIN_TYPEID)
|
if (toolchain->typeId() != ProjectExplorer::Constants::MINGW_TOOLCHAIN_TYPEID)
|
||||||
QSKIP("This test is mingw specific, does not run for other toolchains");
|
QSKIP("This test is mingw specific, does not run for other toolchains");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open project
|
// Open project
|
||||||
Tests::ProjectOpenerAndCloser projectManager;
|
Tests::ProjectOpenerAndCloser projectManager;
|
||||||
const ProjectInfo projectInfo = projectManager.open(projectFilePath, true);
|
const ProjectInfo projectInfo = projectManager.open(projectFilePath, true, m_kit);
|
||||||
const bool isProjectOpen = projectInfo.isValid();
|
const bool isProjectOpen = projectInfo.isValid();
|
||||||
QVERIFY(isProjectOpen);
|
QVERIFY(isProjectOpen);
|
||||||
|
|
||||||
|
@@ -32,6 +32,8 @@ class ClangDiagnosticConfig;
|
|||||||
namespace Tests { class TemporaryCopiedDir; }
|
namespace Tests { class TemporaryCopiedDir; }
|
||||||
} // namespace CppTools
|
} // namespace CppTools
|
||||||
|
|
||||||
|
namespace ProjectExplorer { class Kit; }
|
||||||
|
|
||||||
namespace ClangTools {
|
namespace ClangTools {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
@@ -55,6 +57,7 @@ private:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
CppTools::Tests::TemporaryCopiedDir *m_tmpDir = nullptr;
|
CppTools::Tests::TemporaryCopiedDir *m_tmpDir = nullptr;
|
||||||
|
ProjectExplorer::Kit *m_kit = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
@@ -445,9 +445,11 @@ Utils::FilePath CompilationDatabaseProject::rootPathFromSettings() const
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void CompilationDatabaseProject::configureAsExampleProject()
|
void CompilationDatabaseProject::configureAsExampleProject(Kit *kit)
|
||||||
{
|
{
|
||||||
if (KitManager::defaultKit())
|
if (kit)
|
||||||
|
addTargetForKit(kit);
|
||||||
|
else if (KitManager::defaultKit())
|
||||||
addTargetForKit(KitManager::defaultKit());
|
addTargetForKit(KitManager::defaultKit());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -54,7 +54,7 @@ public:
|
|||||||
Utils::FilePath rootPathFromSettings() const;
|
Utils::FilePath rootPathFromSettings() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void configureAsExampleProject() override;
|
void configureAsExampleProject(ProjectExplorer::Kit *kit) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class CompilationDatabaseBuildSystem : public ProjectExplorer::BuildSystem
|
class CompilationDatabaseBuildSystem : public ProjectExplorer::BuildSystem
|
||||||
|
@@ -277,7 +277,8 @@ ProjectOpenerAndCloser::~ProjectOpenerAndCloser()
|
|||||||
QCoreApplication::processEvents();
|
QCoreApplication::processEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
ProjectInfo ProjectOpenerAndCloser::open(const QString &projectFile, bool configureAsExampleProject)
|
ProjectInfo ProjectOpenerAndCloser::open(const QString &projectFile, bool configureAsExampleProject,
|
||||||
|
Kit *kit)
|
||||||
{
|
{
|
||||||
ProjectExplorerPlugin::OpenProjectResult result = ProjectExplorerPlugin::openProject(projectFile);
|
ProjectExplorerPlugin::OpenProjectResult result = ProjectExplorerPlugin::openProject(projectFile);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
@@ -287,7 +288,7 @@ ProjectInfo ProjectOpenerAndCloser::open(const QString &projectFile, bool config
|
|||||||
|
|
||||||
Project *project = result.project();
|
Project *project = result.project();
|
||||||
if (configureAsExampleProject)
|
if (configureAsExampleProject)
|
||||||
project->configureAsExampleProject();
|
project->configureAsExampleProject(kit);
|
||||||
|
|
||||||
if (TestCase::waitUntilProjectIsFullyOpened(project)) {
|
if (TestCase::waitUntilProjectIsFullyOpened(project)) {
|
||||||
m_openProjects.append(project);
|
m_openProjects.append(project);
|
||||||
|
@@ -38,7 +38,10 @@ class Snapshot;
|
|||||||
}
|
}
|
||||||
|
|
||||||
namespace Core { class IEditor; }
|
namespace Core { class IEditor; }
|
||||||
namespace ProjectExplorer { class Project; }
|
namespace ProjectExplorer {
|
||||||
|
class Kit;
|
||||||
|
class Project;
|
||||||
|
}
|
||||||
|
|
||||||
namespace TextEditor {
|
namespace TextEditor {
|
||||||
class BaseTextEditor;
|
class BaseTextEditor;
|
||||||
@@ -118,7 +121,8 @@ public:
|
|||||||
ProjectOpenerAndCloser();
|
ProjectOpenerAndCloser();
|
||||||
~ProjectOpenerAndCloser(); // Closes opened projects
|
~ProjectOpenerAndCloser(); // Closes opened projects
|
||||||
|
|
||||||
ProjectInfo open(const QString &projectFile, bool configureAsExampleProject = false);
|
ProjectInfo open(const QString &projectFile, bool configureAsExampleProject = false,
|
||||||
|
ProjectExplorer::Kit *kit = nullptr);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<ProjectExplorer::Project *> m_openProjects;
|
QList<ProjectExplorer::Project *> m_openProjects;
|
||||||
|
@@ -910,7 +910,7 @@ bool Project::needsBuildConfigurations() const
|
|||||||
return d->m_needsBuildConfigurations;
|
return d->m_needsBuildConfigurations;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Project::configureAsExampleProject()
|
void Project::configureAsExampleProject(Kit * /*kit*/)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -138,7 +138,7 @@ public:
|
|||||||
|
|
||||||
virtual bool needsConfiguration() const;
|
virtual bool needsConfiguration() const;
|
||||||
bool needsBuildConfigurations() const;
|
bool needsBuildConfigurations() const;
|
||||||
virtual void configureAsExampleProject();
|
virtual void configureAsExampleProject(ProjectExplorer::Kit *kit);
|
||||||
|
|
||||||
virtual ProjectImporter *projectImporter() const;
|
virtual ProjectImporter *projectImporter() const;
|
||||||
|
|
||||||
|
@@ -139,10 +139,14 @@ ProjectImporter *QbsProject::projectImporter() const
|
|||||||
return m_importer;
|
return m_importer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QbsProject::configureAsExampleProject()
|
void QbsProject::configureAsExampleProject(Kit *kit)
|
||||||
{
|
{
|
||||||
QList<BuildInfo> infoList;
|
QList<BuildInfo> infoList;
|
||||||
const QList<Kit *> kits = KitManager::kits();
|
QList<Kit *> kits;
|
||||||
|
if (kit)
|
||||||
|
kits.append(kit);
|
||||||
|
else
|
||||||
|
kits = KitManager::kits();
|
||||||
for (Kit *k : kits) {
|
for (Kit *k : kits) {
|
||||||
if (QtSupport::QtKitAspect::qtVersion(k) != nullptr) {
|
if (QtSupport::QtKitAspect::qtVersion(k) != nullptr) {
|
||||||
if (auto factory = BuildConfigurationFactory::find(k, projectFilePath()))
|
if (auto factory = BuildConfigurationFactory::find(k, projectFilePath()))
|
||||||
|
@@ -64,7 +64,7 @@ public:
|
|||||||
|
|
||||||
ProjectExplorer::DeploymentKnowledge deploymentKnowledge() const override;
|
ProjectExplorer::DeploymentKnowledge deploymentKnowledge() const override;
|
||||||
|
|
||||||
void configureAsExampleProject() final;
|
void configureAsExampleProject(ProjectExplorer::Kit *kit) final;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
mutable ProjectExplorer::ProjectImporter *m_importer = nullptr;
|
mutable ProjectExplorer::ProjectImporter *m_importer = nullptr;
|
||||||
|
@@ -1012,10 +1012,14 @@ void CentralizedFolderWatcher::delayedFolderChanged(const QString &folder)
|
|||||||
m_buildSystem->updateCodeModels();
|
m_buildSystem->updateCodeModels();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmakeProject::configureAsExampleProject()
|
void QmakeProject::configureAsExampleProject(Kit *kit)
|
||||||
{
|
{
|
||||||
QList<BuildInfo> infoList;
|
QList<BuildInfo> infoList;
|
||||||
const QList<Kit *> kits = KitManager::kits();
|
QList<Kit *> kits;
|
||||||
|
if (kit)
|
||||||
|
kits.append(kit);
|
||||||
|
else
|
||||||
|
kits = KitManager::kits();
|
||||||
for (Kit *k : kits) {
|
for (Kit *k : kits) {
|
||||||
if (QtSupport::QtKitAspect::qtVersion(k) != nullptr) {
|
if (QtSupport::QtKitAspect::qtVersion(k) != nullptr) {
|
||||||
if (auto factory = BuildConfigurationFactory::find(k, projectFilePath()))
|
if (auto factory = BuildConfigurationFactory::find(k, projectFilePath()))
|
||||||
|
@@ -63,7 +63,7 @@ public:
|
|||||||
|
|
||||||
ProjectExplorer::Tasks projectIssues(const ProjectExplorer::Kit *k) const final;
|
ProjectExplorer::Tasks projectIssues(const ProjectExplorer::Kit *k) const final;
|
||||||
|
|
||||||
void configureAsExampleProject() final;
|
void configureAsExampleProject(ProjectExplorer::Kit *kit) final;
|
||||||
|
|
||||||
ProjectExplorer::ProjectImporter *projectImporter() const final;
|
ProjectExplorer::ProjectImporter *projectImporter() const final;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user