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
|
||||
|
||||
Reference in New Issue
Block a user