forked from qt-creator/qt-creator
AutoTest: Introduce TestToolConfiguration
Preparation for having code based and build system based test items. Task-number: QTCREATORBUG-23332 Change-Id: I4d21142d74b40b988d82c69d02f5c6633c8cebe4 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -102,6 +102,11 @@ QString ITestConfiguration::executableFilePath() const
|
|||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Environment ITestConfiguration::filteredEnvironment(const Environment &original) const
|
||||||
|
{
|
||||||
|
return original;
|
||||||
|
}
|
||||||
|
|
||||||
TestConfiguration::TestConfiguration(ITestFramework *framework)
|
TestConfiguration::TestConfiguration(ITestFramework *framework)
|
||||||
: ITestConfiguration(framework)
|
: ITestConfiguration(framework)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ public:
|
|||||||
|
|
||||||
virtual TestOutputReader *outputReader(const QFutureInterface<TestResultPtr> &fi,
|
virtual TestOutputReader *outputReader(const QFutureInterface<TestResultPtr> &fi,
|
||||||
QProcess *app) const = 0;
|
QProcess *app) const = 0;
|
||||||
virtual Utils::Environment filteredEnvironment(const Utils::Environment &original) const = 0;
|
virtual Utils::Environment filteredEnvironment(const Utils::Environment &original) const;
|
||||||
|
|
||||||
ITestBase *testBase() const { return m_testBase; }
|
ITestBase *testBase() const { return m_testBase; }
|
||||||
void setProject(ProjectExplorer::Project *project) { m_project = project; }
|
void setProject(ProjectExplorer::Project *project) { m_project = project; }
|
||||||
@@ -145,4 +145,15 @@ private:
|
|||||||
bool m_mixedDebugging = false;
|
bool m_mixedDebugging = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class TestToolConfiguration : public ITestConfiguration
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit TestToolConfiguration(ITestBase *testBase) : ITestConfiguration(testBase) {}
|
||||||
|
Utils::CommandLine commandLine() const { return m_commandLine; }
|
||||||
|
void setCommandLine(const Utils::CommandLine &cmdline) { m_commandLine = cmdline; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
Utils::CommandLine m_commandLine;
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace Autotest
|
} // namespace Autotest
|
||||||
|
|||||||
@@ -148,7 +148,8 @@ static QString processInformation(const QProcess *proc)
|
|||||||
|
|
||||||
static QString rcInfo(const ITestConfiguration * const config)
|
static QString rcInfo(const ITestConfiguration * const config)
|
||||||
{
|
{
|
||||||
// FIXME early return for test tools
|
if (config->testBase()->asTestTool())
|
||||||
|
return {};
|
||||||
const TestConfiguration *current = static_cast<const TestConfiguration *>(config);
|
const TestConfiguration *current = static_cast<const TestConfiguration *>(config);
|
||||||
QString info;
|
QString info;
|
||||||
if (current->isDeduced())
|
if (current->isDeduced())
|
||||||
@@ -175,44 +176,48 @@ static QString constructOmittedVariablesDetailsString(const Utils::EnvironmentIt
|
|||||||
|
|
||||||
bool TestRunner::currentConfigValid()
|
bool TestRunner::currentConfigValid()
|
||||||
{
|
{
|
||||||
if (true) { // FIXME do this for frameworks
|
QString commandFilePath;
|
||||||
|
if (m_currentConfig->testBase()->asFramework()) {
|
||||||
TestConfiguration *current = static_cast<TestConfiguration *>(m_currentConfig);
|
TestConfiguration *current = static_cast<TestConfiguration *>(m_currentConfig);
|
||||||
QString commandFilePath = current->executableFilePath();
|
commandFilePath = current->executableFilePath();
|
||||||
if (commandFilePath.isEmpty()) {
|
} else {
|
||||||
reportResult(ResultType::MessageFatal,
|
TestToolConfiguration *current = static_cast<TestToolConfiguration *>(m_currentConfig);
|
||||||
tr("Executable path is empty. (%1)").arg(current->displayName()));
|
commandFilePath = current->commandLine().executable().toString();
|
||||||
delete m_currentConfig;
|
|
||||||
m_currentConfig = nullptr;
|
|
||||||
if (m_selectedTests.isEmpty()) {
|
|
||||||
if (m_fakeFutureInterface)
|
|
||||||
m_fakeFutureInterface->reportFinished();
|
|
||||||
onFinished();
|
|
||||||
} else {
|
|
||||||
onProcessFinished();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
// FIXME check TestTools as well
|
if (commandFilePath.isEmpty()) {
|
||||||
return false;
|
reportResult(ResultType::MessageFatal,
|
||||||
|
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 {
|
||||||
|
onProcessFinished();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestRunner::setUpProcess()
|
void TestRunner::setUpProcess()
|
||||||
{
|
{
|
||||||
QTC_ASSERT(m_currentConfig, return);
|
QTC_ASSERT(m_currentConfig, return);
|
||||||
if (true) { // FIXME do this for frameworks
|
m_currentProcess = new QProcess;
|
||||||
|
m_currentProcess->setReadChannel(QProcess::StandardOutput);
|
||||||
|
if (m_currentConfig->testBase()->asFramework()) {
|
||||||
TestConfiguration *current = static_cast<TestConfiguration *>(m_currentConfig);
|
TestConfiguration *current = static_cast<TestConfiguration *>(m_currentConfig);
|
||||||
m_currentProcess = new QProcess;
|
|
||||||
m_currentProcess->setReadChannel(QProcess::StandardOutput);
|
|
||||||
m_currentProcess->setProgram(current->executableFilePath());
|
m_currentProcess->setProgram(current->executableFilePath());
|
||||||
|
} else {
|
||||||
|
TestToolConfiguration *current = static_cast<TestToolConfiguration *>(m_currentConfig);
|
||||||
|
m_currentProcess->setProgram(current->commandLine().executable().toString());
|
||||||
}
|
}
|
||||||
// FIXME prepare for TestTools as well
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestRunner::setUpProcessEnv()
|
void TestRunner::setUpProcessEnv()
|
||||||
{
|
{
|
||||||
if (true) { // do this for frameworks
|
if (m_currentConfig->testBase()->asFramework()) {
|
||||||
TestConfiguration *current = static_cast<TestConfiguration *>(m_currentConfig);
|
TestConfiguration *current = static_cast<TestConfiguration *>(m_currentConfig);
|
||||||
|
|
||||||
QStringList omitted;
|
QStringList omitted;
|
||||||
@@ -221,21 +226,24 @@ void TestRunner::setUpProcessEnv()
|
|||||||
const QString &details = constructOmittedDetailsString(omitted);
|
const QString &details = constructOmittedDetailsString(omitted);
|
||||||
reportResult(ResultType::MessageWarn, details.arg(current->displayName()));
|
reportResult(ResultType::MessageWarn, details.arg(current->displayName()));
|
||||||
}
|
}
|
||||||
m_currentProcess->setWorkingDirectory(current->workingDirectory());
|
} else {
|
||||||
const Utils::Environment &original = current->environment();
|
TestToolConfiguration *current = static_cast<TestToolConfiguration *>(m_currentConfig);
|
||||||
Utils::Environment environment = current->filteredEnvironment(original);
|
m_currentProcess->setArguments(current->commandLine().splitArguments());
|
||||||
const Utils::EnvironmentItems removedVariables = Utils::filtered(
|
|
||||||
original.diff(environment), [](const Utils::EnvironmentItem &it) {
|
|
||||||
return it.operation == Utils::EnvironmentItem::Unset;
|
|
||||||
});
|
|
||||||
if (!removedVariables.isEmpty()) {
|
|
||||||
const QString &details = constructOmittedVariablesDetailsString(removedVariables)
|
|
||||||
.arg(current->displayName());
|
|
||||||
reportResult(ResultType::MessageWarn, details);
|
|
||||||
}
|
|
||||||
m_currentProcess->setProcessEnvironment(environment.toProcessEnvironment());
|
|
||||||
}
|
}
|
||||||
// FIXME prepare for TestTools as well
|
|
||||||
|
m_currentProcess->setWorkingDirectory(m_currentConfig->workingDirectory());
|
||||||
|
const Utils::Environment &original = m_currentConfig->environment();
|
||||||
|
Utils::Environment environment = m_currentConfig->filteredEnvironment(original);
|
||||||
|
const Utils::EnvironmentItems removedVariables = Utils::filtered(
|
||||||
|
original.diff(environment), [](const Utils::EnvironmentItem &it) {
|
||||||
|
return it.operation == Utils::EnvironmentItem::Unset;
|
||||||
|
});
|
||||||
|
if (!removedVariables.isEmpty()) {
|
||||||
|
const QString &details = constructOmittedVariablesDetailsString(removedVariables)
|
||||||
|
.arg(m_currentConfig->displayName());
|
||||||
|
reportResult(ResultType::MessageWarn, details);
|
||||||
|
}
|
||||||
|
m_currentProcess->setProcessEnvironment(environment.toProcessEnvironment());
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestRunner::scheduleNext()
|
void TestRunner::scheduleNext()
|
||||||
@@ -469,7 +477,16 @@ int TestRunner::precheckTestConfigurations()
|
|||||||
const bool omitWarnings = AutotestPlugin::settings()->omitRunConfigWarn;
|
const bool omitWarnings = AutotestPlugin::settings()->omitRunConfigWarn;
|
||||||
int testCaseCount = 0;
|
int testCaseCount = 0;
|
||||||
for (ITestConfiguration *itc : qAsConst(m_selectedTests)) {
|
for (ITestConfiguration *itc : qAsConst(m_selectedTests)) {
|
||||||
// FIXME handle test tools
|
if (itc->testBase()->asTestTool()) {
|
||||||
|
if (itc->project()) {
|
||||||
|
testCaseCount += itc->testCaseCount();
|
||||||
|
} else {
|
||||||
|
reportResult(ResultType::MessageWarn,
|
||||||
|
tr("Project is null for \"%1\". Removing from test run.\n"
|
||||||
|
"Check the test environment.").arg(itc->displayName()));
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
TestConfiguration *config = static_cast<TestConfiguration *>(itc);
|
TestConfiguration *config = static_cast<TestConfiguration *>(itc);
|
||||||
config->completeTestInformation(TestRunMode::Run);
|
config->completeTestInformation(TestRunMode::Run);
|
||||||
if (config->project()) {
|
if (config->project()) {
|
||||||
@@ -507,7 +524,13 @@ void TestRunner::runTests()
|
|||||||
QList<ITestConfiguration *> toBeRemoved;
|
QList<ITestConfiguration *> toBeRemoved;
|
||||||
bool projectChanged = false;
|
bool projectChanged = false;
|
||||||
for (ITestConfiguration *itc : qAsConst(m_selectedTests)) {
|
for (ITestConfiguration *itc : qAsConst(m_selectedTests)) {
|
||||||
// FIXME handle test tools
|
if (itc->testBase()->asTestTool()) {
|
||||||
|
if (itc->project() != SessionManager::startupProject()) {
|
||||||
|
projectChanged = true;
|
||||||
|
toBeRemoved.append(itc);
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
TestConfiguration *config = static_cast<TestConfiguration *>(itc);
|
TestConfiguration *config = static_cast<TestConfiguration *>(itc);
|
||||||
config->completeTestInformation(TestRunMode::Run);
|
config->completeTestInformation(TestRunMode::Run);
|
||||||
if (!config->project()) {
|
if (!config->project()) {
|
||||||
@@ -581,7 +604,8 @@ void TestRunner::debugTests()
|
|||||||
QTC_ASSERT(m_selectedTests.size() == 1, onFinished();return);
|
QTC_ASSERT(m_selectedTests.size() == 1, onFinished();return);
|
||||||
|
|
||||||
ITestConfiguration *itc = m_selectedTests.first();
|
ITestConfiguration *itc = m_selectedTests.first();
|
||||||
// FIXME handle test tools as well
|
QTC_ASSERT(itc->testBase()->asFramework(), onFinished();return);
|
||||||
|
|
||||||
TestConfiguration *config = static_cast<TestConfiguration *>(itc);
|
TestConfiguration *config = static_cast<TestConfiguration *>(itc);
|
||||||
config->completeTestInformation(TestRunMode::Debug);
|
config->completeTestInformation(TestRunMode::Debug);
|
||||||
if (!config->project()) {
|
if (!config->project()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user