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:
Christian Stenger
2020-06-16 13:11:10 +02:00
parent c6db1c29d6
commit 6e798401a0
15 changed files with 65 additions and 29 deletions

View File

@@ -61,13 +61,20 @@ AutoTestUnitTests::AutoTestUnitTests(TestTreeModel *model, QObject *parent)
void AutoTestUnitTests::initTestCase()
{
const QList<Kit *> allKits = KitManager::kits();
if (allKits.count() != 1)
QSKIP("This test requires exactly one kit to be present");
if (auto qtVersion = QtSupport::QtKitAspect::qtVersion(allKits.first()))
if (allKits.count() == 0)
QSKIP("This test requires at least one kit to be present");
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');
else
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)
QSKIP("This test requires that there is a kit with a toolchain.");
@@ -99,7 +106,7 @@ void AutoTestUnitTests::testCodeParser()
QFETCH(int, expectedDataTagsCount);
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());
QSignalSpy parserSpy(m_model->parser(), SIGNAL(parsingFinished()));
@@ -150,7 +157,7 @@ void AutoTestUnitTests::testCodeParserSwitchStartup()
CppTools::Tests::ProjectOpenerAndCloser projectManager;
for (int i = 0; i < projectFilePaths.size(); ++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());
QSignalSpy parserSpy(m_model->parser(), SIGNAL(parsingFinished()));
@@ -198,7 +205,7 @@ void AutoTestUnitTests::testCodeParserGTest()
QFETCH(QString, projectFilePath);
CppTools::Tests::ProjectOpenerAndCloser projectManager;
CppTools::ProjectInfo projectInfo = projectManager.open(projectFilePath, true);
CppTools::ProjectInfo projectInfo = projectManager.open(projectFilePath, true, m_kit);
QVERIFY(projectInfo.isValid());
QSignalSpy parserSpy(m_model->parser(), SIGNAL(parsingFinished()));
@@ -247,7 +254,7 @@ void AutoTestUnitTests::testCodeParserBoostTest()
QFETCH(QString, projectFilePath);
QFETCH(QString, extension);
CppTools::Tests::ProjectOpenerAndCloser projectManager;
CppTools::ProjectInfo projectInfo = projectManager.open(projectFilePath, true);
CppTools::ProjectInfo projectInfo = projectManager.open(projectFilePath, true, m_kit);
QVERIFY(projectInfo.isValid());
QSignalSpy parserSpy(m_model->parser(), SIGNAL(parsingFinished()));