ITestConfiguration: Introduce testExecutable() helper

Reuse it in TestRunner.

Change-Id: I59ffd256a7e84f0d0726261496d73bc4f622d666
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
Jarek Kobus
2023-01-16 23:41:47 +01:00
parent 040ef3b7d3
commit 49f3b8efd7
3 changed files with 18 additions and 36 deletions

View File

@@ -38,6 +38,7 @@ public:
Utils::FilePath workingDirectory() const; Utils::FilePath workingDirectory() const;
bool hasExecutable() const; bool hasExecutable() const;
Utils::FilePath executableFilePath() const; Utils::FilePath executableFilePath() const;
virtual Utils::FilePath testExecutable() const { return executableFilePath(); };
virtual TestOutputReader *createOutputReader(const QFutureInterface<TestResult> &fi, virtual TestOutputReader *createOutputReader(const QFutureInterface<TestResult> &fi,
Utils::QtcProcess *app) const = 0; Utils::QtcProcess *app) const = 0;
@@ -124,6 +125,7 @@ public:
explicit TestToolConfiguration(ITestBase *testBase) : ITestConfiguration(testBase) {} explicit TestToolConfiguration(ITestBase *testBase) : ITestConfiguration(testBase) {}
Utils::CommandLine commandLine() const { return m_commandLine; } Utils::CommandLine commandLine() const { return m_commandLine; }
void setCommandLine(const Utils::CommandLine &cmdline) { m_commandLine = cmdline; } void setCommandLine(const Utils::CommandLine &cmdline) { m_commandLine = cmdline; }
virtual Utils::FilePath testExecutable() const override { return m_commandLine.executable(); };
private: private:
Utils::CommandLine m_commandLine; Utils::CommandLine m_commandLine;

View File

@@ -146,42 +146,22 @@ static QString constructOmittedVariablesDetailsString(const EnvironmentItems &di
bool TestRunner::currentConfigValid() bool TestRunner::currentConfigValid()
{ {
FilePath commandFilePath; const FilePath commandFilePath = m_currentConfig->testExecutable();
if (m_currentConfig->testBase()->type() == ITestBase::Framework) { if (!commandFilePath.isEmpty())
TestConfiguration *current = static_cast<TestConfiguration *>(m_currentConfig); return true;
commandFilePath = current->executableFilePath();
} else {
TestToolConfiguration *current = static_cast<TestToolConfiguration *>(m_currentConfig);
commandFilePath = current->commandLine().executable();
}
if (commandFilePath.isEmpty()) {
reportResult(ResultType::MessageFatal,
Tr::tr("Executable path is empty. (%1)").arg(m_currentConfig->displayName()));
delete m_currentConfig;
m_currentConfig = nullptr;
if (m_selectedTests.isEmpty()) {
if (m_fakeFutureInterface)
m_fakeFutureInterface->reportFinished();
onFinished();
} else {
onProcessDone();
}
return false;
}
return true;
}
void TestRunner::setUpProcess() reportResult(ResultType::MessageFatal,
{ Tr::tr("Executable path is empty. (%1)").arg(m_currentConfig->displayName()));
QTC_ASSERT(m_currentConfig, return); delete m_currentConfig;
m_currentProcess = new QtcProcess; m_currentConfig = nullptr;
if (m_currentConfig->testBase()->type() == ITestBase::Framework) { if (m_selectedTests.isEmpty()) {
TestConfiguration *current = static_cast<TestConfiguration *>(m_currentConfig); if (m_fakeFutureInterface)
m_currentProcess->setCommand({current->executableFilePath(), {}}); m_fakeFutureInterface->reportFinished();
onFinished();
} else { } else {
TestToolConfiguration *current = static_cast<TestToolConfiguration *>(m_currentConfig); onProcessDone();
m_currentProcess->setCommand({current->commandLine().executable(), {}});
} }
return false;
} }
void TestRunner::setUpProcessEnv() void TestRunner::setUpProcessEnv()
@@ -232,8 +212,9 @@ void TestRunner::scheduleNext()
if (!m_currentConfig->project()) if (!m_currentConfig->project())
onProcessDone(); onProcessDone();
setUpProcess(); m_currentProcess = new QtcProcess;
QTC_ASSERT(m_currentProcess, onProcessDone(); return); m_currentProcess->setCommand({m_currentConfig->testExecutable(), {}});
QTC_ASSERT(!m_currentOutputReader, delete m_currentOutputReader); QTC_ASSERT(!m_currentOutputReader, delete m_currentOutputReader);
m_currentOutputReader = m_currentConfig->createOutputReader(*m_fakeFutureInterface, m_currentProcess); m_currentOutputReader = m_currentConfig->createOutputReader(*m_fakeFutureInterface, m_currentProcess);
QTC_ASSERT(m_currentOutputReader, onProcessDone(); return); QTC_ASSERT(m_currentOutputReader, onProcessDone(); return);

View File

@@ -62,7 +62,6 @@ private:
int precheckTestConfigurations(); int precheckTestConfigurations();
bool currentConfigValid(); bool currentConfigValid();
void setUpProcess();
void setUpProcessEnv(); void setUpProcessEnv();
void scheduleNext(); void scheduleNext();
void cancelCurrent(CancelReason reason); void cancelCurrent(CancelReason reason);