AutoTest: Extract code into function

Part of a later refactoring.

Change-Id: I8321b344ff333195905be68131aab508d1a87aee
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Stenger
2018-05-17 08:34:03 +02:00
parent 21974a4bcb
commit 2557e685e5
2 changed files with 32 additions and 24 deletions

View File

@@ -148,32 +148,10 @@ static QString constructOmittedDetailsString(const QStringList &omitted)
static void performTestRun(QFutureInterface<TestResultPtr> &futureInterface, static void performTestRun(QFutureInterface<TestResultPtr> &futureInterface,
const QList<TestConfiguration *> selectedTests, const QList<TestConfiguration *> selectedTests,
const TestSettings &settings) const TestSettings &settings, int testCaseCount)
{ {
const int timeout = settings.timeout; const int timeout = settings.timeout;
const bool omitRunConfigWarnings = settings.omitRunConfigWarn;
QEventLoop eventLoop; QEventLoop eventLoop;
int testCaseCount = 0;
for (TestConfiguration *config : selectedTests) {
config->completeTestInformation(TestRunMode::Run);
if (config->project()) {
testCaseCount += config->testCaseCount();
if (!omitRunConfigWarnings && config->isGuessed()) {
QString message = TestRunner::tr(
"Project's run configuration was guessed for \"%1\".\n"
"This might cause trouble during execution.\n"
"(guessed from \"%2\")");
message = message.arg(config->displayName()).arg(config->runConfigDisplayName());
futureInterface.reportResult(
TestResultPtr(new FaultyTestResult(Result::MessageWarn, message)));
}
} else {
futureInterface.reportResult(TestResultPtr(new FaultyTestResult(Result::MessageWarn,
TestRunner::tr("Project is null for \"%1\". Removing from test run.\n"
"Check the test environment.").arg(config->displayName()))));
}
}
QProcess testProcess; QProcess testProcess;
testProcess.setReadChannel(QProcess::StandardOutput); testProcess.setReadChannel(QProcess::StandardOutput);
@@ -355,6 +333,32 @@ static ProjectExplorer::RunConfiguration *getRunConfiguration(const QString &dia
return runConfig; return runConfig;
} }
int TestRunner::precheckTestConfigurations()
{
const bool omitWarnings = AutotestPlugin::settings()->omitRunConfigWarn;
int testCaseCount = 0;
for (TestConfiguration *config : m_selectedTests) {
config->completeTestInformation(TestRunMode::Run);
if (config->project()) {
testCaseCount += config->testCaseCount();
if (!omitWarnings && config->isGuessed()) {
QString message = tr(
"Project's run configuration was guessed for \"%1\".\n"
"This might cause trouble during execution.\n"
"(guessed from \"%2\")");
message = message.arg(config->displayName()).arg(config->runConfigDisplayName());
emit testResultReady(
TestResultPtr(new FaultyTestResult(Result::MessageWarn, message)));
}
} else {
emit testResultReady(TestResultPtr(new FaultyTestResult(Result::MessageWarn,
tr("Project is null for \"%1\". Removing from test run.\n"
"Check the test environment.").arg(config->displayName()))));
}
}
return testCaseCount;
}
void TestRunner::runTests() void TestRunner::runTests()
{ {
QList<TestConfiguration *> toBeRemoved; QList<TestConfiguration *> toBeRemoved;
@@ -378,8 +382,10 @@ void TestRunner::runTests()
return; return;
} }
int testCaseCount = precheckTestConfigurations();
QFuture<TestResultPtr> future = Utils::runAsync(&performTestRun, m_selectedTests, QFuture<TestResultPtr> future = Utils::runAsync(&performTestRun, m_selectedTests,
*AutotestPlugin::settings()); *AutotestPlugin::settings(), testCaseCount);
m_futureWatcher.setFuture(future); m_futureWatcher.setFuture(future);
Core::ProgressManager::addTask(future, tr("Running Tests"), Autotest::Constants::TASK_INDEX); Core::ProgressManager::addTask(future, tr("Running Tests"), Autotest::Constants::TASK_INDEX);
} }

View File

@@ -71,6 +71,8 @@ private:
void buildFinished(bool success); void buildFinished(bool success);
void onFinished(); void onFinished();
int precheckTestConfigurations();
void runTests(); void runTests();
void debugTests(); void debugTests();
void runOrDebugTests(); void runOrDebugTests();