forked from qt-creator/qt-creator
AutoTest: Fix setting working directory
If there is no working directory explicitly set inside the run configuration we end up using the current working directory of Qt Creator. We normally get an empty string if not having modified the respective target ourselves although you can see a default working directory when opening the respective target for the first time. Task-number: QTCREATORBUG-16715 Change-Id: I6e16fd4f9b15759793653a6c229c44a1be2b7739 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -263,5 +263,48 @@ void TestConfiguration::setGuessedConfiguration(bool guessed)
|
||||
m_guessedConfiguration = guessed;
|
||||
}
|
||||
|
||||
QString TestConfiguration::executableFilePath() const
|
||||
{
|
||||
if (m_targetFile.isEmpty())
|
||||
return QString();
|
||||
|
||||
QFileInfo commandFileInfo(m_targetFile);
|
||||
if (commandFileInfo.isExecutable() && commandFileInfo.path() != ".") {
|
||||
return commandFileInfo.absoluteFilePath();
|
||||
} else if (commandFileInfo.path() == "."){
|
||||
QString fullCommandFileName = m_targetFile;
|
||||
#ifdef Q_OS_WIN
|
||||
if (!m_targetFile.endsWith(".exe"))
|
||||
fullCommandFileName = m_targetFile + QLatin1String(".exe");
|
||||
|
||||
static const QString separator(";");
|
||||
#else
|
||||
static const QString separator(":");
|
||||
#endif
|
||||
// TODO: check if we can use searchInPath() from Utils::Environment
|
||||
const QStringList &pathList
|
||||
= m_environment.toProcessEnvironment().value("PATH").split(separator);
|
||||
|
||||
foreach (const QString &path, pathList) {
|
||||
QString filePath(path + QDir::separator() + fullCommandFileName);
|
||||
if (QFileInfo(filePath).isExecutable())
|
||||
return commandFileInfo.absoluteFilePath();
|
||||
}
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
|
||||
QString TestConfiguration::workingDirectory() const
|
||||
{
|
||||
if (!m_workingDir.isEmpty()) {
|
||||
const QFileInfo info(m_workingDir);
|
||||
if (info.isDir()) // ensure wanted working dir does exist
|
||||
return info.absoluteFilePath();
|
||||
}
|
||||
|
||||
const QString executable = executableFilePath();
|
||||
return executable.isEmpty() ? executable : QFileInfo(executable).absolutePath();
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace Autotest
|
||||
|
@@ -74,8 +74,9 @@ public:
|
||||
int testCaseCount() const { return m_testCaseCount; }
|
||||
QString proFile() const { return m_proFile; }
|
||||
QString targetFile() const { return m_targetFile; }
|
||||
QString executableFilePath() const;
|
||||
QString targetName() const { return m_targetName; }
|
||||
QString workingDirectory() const { return m_workingDir; }
|
||||
QString workingDirectory() const;
|
||||
QString buildDirectory() const { return m_buildDir; }
|
||||
QString displayName() const { return m_displayName; }
|
||||
Utils::Environment environment() const { return m_environment; }
|
||||
|
@@ -55,35 +55,6 @@ namespace Internal {
|
||||
|
||||
static TestRunner *m_instance = 0;
|
||||
|
||||
static QString executableFilePath(const QString &command, const QProcessEnvironment &environment)
|
||||
{
|
||||
if (command.isEmpty())
|
||||
return QString();
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
TestRunner *TestRunner::instance()
|
||||
{
|
||||
if (!m_instance)
|
||||
@@ -157,7 +128,7 @@ static void performTestRun(QFutureInterface<TestResultPtr> &futureInterface,
|
||||
continue;
|
||||
|
||||
QProcessEnvironment environment = testConfiguration->environment().toProcessEnvironment();
|
||||
QString commandFilePath = executableFilePath(testConfiguration->targetFile(), environment);
|
||||
QString commandFilePath = testConfiguration->executableFilePath();
|
||||
if (commandFilePath.isEmpty()) {
|
||||
futureInterface.reportResult(TestResultPtr(new FaultyTestResult(Result::MessageFatal,
|
||||
TestRunner::tr("Could not find command \"%1\". (%2)")
|
||||
@@ -293,8 +264,7 @@ void TestRunner::debugTests()
|
||||
return;
|
||||
}
|
||||
|
||||
const QString &commandFilePath = executableFilePath(config->targetFile(),
|
||||
config->environment().toProcessEnvironment());
|
||||
const QString &commandFilePath = config->executableFilePath();
|
||||
if (commandFilePath.isEmpty()) {
|
||||
emit testResultReady(TestResultPtr(new FaultyTestResult(Result::MessageFatal,
|
||||
TestRunner::tr("Could not find command \"%1\". (%2)")
|
||||
|
Reference in New Issue
Block a user