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

@@ -40,6 +40,8 @@
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/toolchain.h>
#include <qtsupport/qtkitinformation.h>
#include <utils/executeondestruction.h>
#include <utils/fileutils.h>
@@ -60,9 +62,16 @@ namespace Internal {
void ClangToolsUnitTests::initTestCase()
{
const QList<Kit *> allKits = KitManager::kits();
if (allKits.count() != 1)
QSKIP("This test requires exactly one kit to be present");
const ToolChain *const toolchain = ToolChainKitAspect::cxxToolChain(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("This test requires at least one valid kit with a valid Qt");
const ToolChain *const toolchain = ToolChainKitAspect::cxxToolChain(m_kit);
if (!toolchain)
QSKIP("This test requires that there is a kit with a toolchain.");
@@ -99,14 +108,14 @@ void ClangToolsUnitTests::testProject()
QFETCH(int, expectedDiagCount);
QFETCH(ClangDiagnosticConfig, diagnosticConfig);
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)
QSKIP("This test is mingw specific, does not run for other toolchains");
}
// Open project
Tests::ProjectOpenerAndCloser projectManager;
const ProjectInfo projectInfo = projectManager.open(projectFilePath, true);
const ProjectInfo projectInfo = projectManager.open(projectFilePath, true, m_kit);
const bool isProjectOpen = projectInfo.isValid();
QVERIFY(isProjectOpen);