diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2015-07-16 17:41:15 -0700 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2015-07-20 16:07:46 +0000 |
commit | db2fc7843c031c450799269ad82f379d358f29a5 (patch) | |
tree | 229337d65ced61eb927d8ec14adcfae254f8e360 /tests/auto/corelib | |
parent | ee0fd8700724848e73c228d973bf72e246077d07 (diff) |
QProcess: make setWorkingDirectory stop launch if the dir doesn't exist
[ChangeLog][QtCore][QProcess] Fixed a bug that caused QProcess to launch
a child process on Unix even if the directory specified with
setWorkingDirectory did not exist.
Task-number: QTBUG-47271
Change-Id: Ib306f8f647014b399b87ffff13f195158b0e52f5
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
Diffstat (limited to 'tests/auto/corelib')
-rw-r--r-- | tests/auto/corelib/io/qprocess/tst_qprocess.cpp | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp index 4a166c540e..02501ca9d9 100644 --- a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp +++ b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp @@ -122,9 +122,8 @@ private slots: void removeFileWhileProcessIsRunning(); void fileWriterProcess(); void switchReadChannels(); -#ifdef Q_OS_WIN void setWorkingDirectory(); -#endif // Q_OS_WIN + void setNonExistentWorkingDirectory(); #endif // not Q_OS_WINCE void exitStatus_data(); @@ -2192,15 +2191,19 @@ void tst_QProcess::switchReadChannels() #endif //----------------------------------------------------------------------------- -#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) +#ifndef Q_OS_WINCE // Q_OS_WIN - setWorkingDirectory will chdir before starting the process on unices // Windows CE does not support working directory logic void tst_QProcess::setWorkingDirectory() { process = new QProcess; process->setWorkingDirectory("test"); - process->start("testSetWorkingDirectory/testSetWorkingDirectory"); - QVERIFY(process->waitForFinished()); + + // use absolute path because on Windows, the executable is relative to the parent's CWD + // while on Unix with fork it's relative to the child's (with posix_spawn, it could be either). + process->start(QFileInfo("testSetWorkingDirectory/testSetWorkingDirectory").absoluteFilePath()); + + QVERIFY2(process->waitForFinished(), process->errorString().toLocal8Bit()); QByteArray workingDir = process->readAllStandardOutput(); QCOMPARE(QDir("test").canonicalPath(), QDir(workingDir.constData()).canonicalPath()); @@ -2208,6 +2211,25 @@ void tst_QProcess::setWorkingDirectory() delete process; process = 0; } + +//----------------------------------------------------------------------------- +void tst_QProcess::setNonExistentWorkingDirectory() +{ + process = new QProcess; + process->setWorkingDirectory("this/directory/should/not/exist/for/sure"); + + // use absolute path because on Windows, the executable is relative to the parent's CWD + // while on Unix with fork it's relative to the child's (with posix_spawn, it could be either). + process->start(QFileInfo("testSetWorkingDirectory/testSetWorkingDirectory").absoluteFilePath()); + QVERIFY(!process->waitForFinished()); +#ifdef QPROCESS_USE_SPAWN + QEXPECT_FAIL("", "QProcess cannot detect failure to start when using posix_spawn()", Continue); +#endif + QCOMPARE(int(process->error()), int(QProcess::FailedToStart)); + + delete process; + process = 0; +} #endif //----------------------------------------------------------------------------- |