diff options
author | Tim Jenssen <tim.jenssen@theqtcompany.com> | 2015-01-16 11:53:33 +0100 |
---|---|---|
committer | Tim Jenssen <tim.jenssen@theqtcompany.com> | 2015-01-21 09:24:22 +0200 |
commit | 33ce9f9e0da3282ebd33655a8aa8b7752c7485b0 (patch) | |
tree | b3a05741f6399aee8bf4f1630b5fbe106787728d | |
parent | 003f81245650a0549487744eda5dba065c68969f (diff) | |
download | qt-creator-33ce9f9e0da3282ebd33655a8aa8b7752c7485b0.tar.gz |
refactor performTestRun
On windows we are only interested in .exe files. For example
QProcess("test.cmd") does not work.
renamed which to executableFilePath
Change-Id: Ib9aa2d011c3d0525b618a1b0a6bd32b556c02010
Reviewed-by: Christian Stenger <christian.stenger@theqtcompany.com>
-rw-r--r-- | plugins/autotest/testrunner.cpp | 94 |
1 files changed, 39 insertions, 55 deletions
diff --git a/plugins/autotest/testrunner.cpp b/plugins/autotest/testrunner.cpp index 824d17f6d2..ec142c9ec0 100644 --- a/plugins/autotest/testrunner.cpp +++ b/plugins/autotest/testrunner.cpp @@ -302,34 +302,31 @@ void processOutput(QProcess *testRunner) } } -static QString which(const QString &pathValue, const QString &command) +static QString executableFilePath(const QString &command, const QProcessEnvironment &environment) { - if (pathValue.isEmpty() || command.isEmpty()) + if (command.isEmpty()) return QString(); - QStringList pathList; -#ifdef Q_OS_WIN - pathList = pathValue.split(QLatin1Char(';')); -#else - pathList = pathValue.split(QLatin1Char(':')); -#endif - - foreach (const QString &path, pathList) { - const QString filePath = path + QDir::separator() + command; - QFileInfo commandFileInfo(filePath); - if (commandFileInfo.exists() && commandFileInfo.isExecutable()) - return filePath; -#ifdef Q_OS_WIN - commandFileInfo = QFileInfo(filePath + QLatin1String(".exe")); - if (commandFileInfo.exists()) - return commandFileInfo.absoluteFilePath(); - commandFileInfo = QFileInfo(filePath + QLatin1String(".bat")); - if (commandFileInfo.exists()) - return commandFileInfo.absoluteFilePath(); - commandFileInfo = QFileInfo(filePath + QLatin1String(".cmd")); - if (commandFileInfo.exists()) - return commandFileInfo.absoluteFilePath(); -#endif + QFileInfo commandFileInfo(command); + if (commandFileInfo.isExecutable() && commandFileInfo.path() != QLatin1String(".")) { + return commandFileInfo.absoluteFilePath(); + } else if (commandFileInfo.path() == QLatin1String(".")){ + QString fullCommandFileName = command; + #ifdef Q_OS_WIN + if (!command.endsWith(QLatin1String(".exe"))) + fullCommandFileName = command + QLatin1String(".exe"); + + static const QString pathSeparator(QLatin1Char(';')); + #else + static const QString pathSeparator(QLatin1Char(':')); + #endif + QStringList pathList = environment.value(QLatin1String("PATH")).split(pathSeparator); + + foreach (const QString &path, pathList) { + QString filePath(path + QDir::separator() + fullCommandFileName); + if (QFileInfo(filePath).isExecutable()) + return commandFileInfo.absoluteFilePath(); + } } return QString(); } @@ -344,9 +341,8 @@ void performTestRun(QFutureInterface<void> &future, const QList<TestConfiguratio QProcess testProcess; testProcess.setReadChannelMode(QProcess::MergedChannels); testProcess.setReadChannel(QProcess::StandardOutput); - QObject::connect(testRunner, &TestRunner::requestStopTestRun, [&] () { - if (testProcess.state() != QProcess::NotRunning && m_currentFuture) - m_currentFuture->cancel(); + QObject::connect(testRunner, &TestRunner::requestStopTestRun, &testProcess, [&] () { + future.cancel(); // this kills the process if that is still in the running loop }); QObject::connect(&testProcess, &QProcess::readyReadStandardOutput, [&] () { @@ -359,41 +355,29 @@ void performTestRun(QFutureInterface<void> &future, const QList<TestConfiguratio foreach (const TestConfiguration *testConfiguration, selectedTests) { if (m_currentFuture->isCanceled()) break; - QString command = testConfiguration->targetFile(); - QString workingDirectory = testConfiguration->workingDirectory(); - QStringList argumentList; - Utils::Environment environment = testConfiguration->environment(); - - argumentList << QLatin1String("-xml"); - if (!metricsOption.isEmpty()) - argumentList << metricsOption; - if (testConfiguration->testCases().count()) - argumentList << testConfiguration->testCases(); - QString runCommand; - if (!QDir::toNativeSeparators(command).contains(QDir::separator())) { - if (environment.hasKey(QLatin1String("PATH"))) - runCommand = which(environment.value(QLatin1String("PATH")), command); - } else if (QFileInfo(command).exists()) { - runCommand = command; - } - if (runCommand.isEmpty()) { + QProcessEnvironment environment = testConfiguration->environment().toProcessEnvironment(); + QString commandFilePath = executableFilePath(testConfiguration->targetFile(), environment); + if (commandFilePath.isEmpty()) { emitTestResultCreated(FaultyTestResult(Result::MESSAGE_FATAL, - QObject::tr("*** Could not find command '%1' ***").arg(command))); + QObject::tr("*** Could not find command '%1' ***").arg(testConfiguration->targetFile()))); continue; } - testProcess.setWorkingDirectory(workingDirectory); - testProcess.setProcessEnvironment(environment.toProcessEnvironment()); - QTime executionTimer; + QStringList argumentList(QLatin1String("-xml")); + if (!metricsOption.isEmpty()) + argumentList << metricsOption; + if (testConfiguration->testCases().count()) + argumentList << testConfiguration->testCases(); + testProcess.setArguments(argumentList); - if (argumentList.count()) { - testProcess.start(runCommand, argumentList); - } else { - testProcess.start(runCommand); - } + testProcess.setWorkingDirectory(testConfiguration->workingDirectory()); + testProcess.setProcessEnvironment(environment); + testProcess.setProgram(commandFilePath); + testProcess.start(); bool ok = testProcess.waitForStarted(); + QTime executionTimer; executionTimer.start(); if (ok) { while (testProcess.state() == QProcess::Running && executionTimer.elapsed() < timeout) { |