AutoTest: Fix environment for ctest execution

The build environment may or may not contain the respective
paths to get the tests running, but the run environment
usually must have them correctly.

Change-Id: I392f6b61551b5927646daf3055134628f6d4f536
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Stenger
2021-06-30 09:44:15 +02:00
parent 2971aac8c2
commit 4430c33458

View File

@@ -32,6 +32,7 @@
#include "../testsettings.h" #include "../testsettings.h"
#include <projectexplorer/buildsystem.h> #include <projectexplorer/buildsystem.h>
#include <projectexplorer/environmentaspect.h>
#include <projectexplorer/project.h> #include <projectexplorer/project.h>
#include <projectexplorer/session.h> #include <projectexplorer/session.h>
#include <projectexplorer/target.h> #include <projectexplorer/target.h>
@@ -115,13 +116,17 @@ QList<ITestConfiguration *> CTestTreeItem::testConfigurationsFor(const QStringLi
CTestConfiguration *config = new CTestConfiguration(testBase()); CTestConfiguration *config = new CTestConfiguration(testBase());
config->setProject(project); config->setProject(project);
config->setCommandLine(command); config->setCommandLine(command);
const QList<ProjectExplorer::BuildConfiguration *> buildConfigs = target->buildConfigurations(); const ProjectExplorer::RunConfiguration *runConfig = target->activeRunConfiguration();
if (QTC_GUARD(!buildConfigs.isEmpty())) { if (QTC_GUARD(runConfig)) {
config->setEnvironment(buildConfigs.first()->environment()); if (auto envAspect = runConfig->aspect<ProjectExplorer::EnvironmentAspect>())
config->setWorkingDirectory(buildConfigs.first()->buildDirectory().toString()); config->setEnvironment(envAspect->environment());
} else { else
config->setEnvironment(Utils::Environment::systemEnvironment()); config->setEnvironment(Utils::Environment::systemEnvironment());
} }
const ProjectExplorer::BuildConfiguration *buildConfig = target->activeBuildConfiguration();
if (QTC_GUARD(buildConfig))
config->setWorkingDirectory(buildConfig->buildDirectory().toString());
if (selected.isEmpty()) if (selected.isEmpty())
config->setTestCaseCount(testBase()->asTestTool()->rootNode()->childCount()); config->setTestCaseCount(testBase()->asTestTool()->rootNode()->childCount());
else else