From ed3aca119fc23844e6d00c95f444d0ee3f71ad1e Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Thu, 27 Nov 2014 14:12:52 +0100 Subject: make test support qmake path with spaces Change-Id: I66d8b3cc742c44d02c224bbfc4086500af0d5f4a Reviewed-by: Joerg Bornemann --- tests/auto/tools/qmake/testcompiler.cpp | 36 ++++++++++++++++++++------------- tests/auto/tools/qmake/testcompiler.h | 10 +++++---- tests/auto/tools/qmake/tst_qmake.cpp | 3 ++- 3 files changed, 30 insertions(+), 19 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/tools/qmake/testcompiler.cpp b/tests/auto/tools/qmake/testcompiler.cpp index 7551f5bfbf..61970d0e17 100644 --- a/tests/auto/tools/qmake/testcompiler.cpp +++ b/tests/auto/tools/qmake/testcompiler.cpp @@ -146,14 +146,22 @@ static inline QStringList systemEnvironment() return result; } -bool TestCompiler::runCommand( QString cmdline, bool expectFail ) +bool TestCompiler::runCommand(const QString &cmd, const QStringList &args, bool expectFail) { - testOutput_.append("Running command: " + cmdline); + QString dbg = cmd; + if (dbg.contains(' ')) + dbg.prepend('"').append('"'); + foreach (QString arg, args) { + if (arg.contains(' ')) + arg.prepend('"').append('"'); + dbg.append(' ').append(arg); + } + testOutput_.append("Running command: " + dbg); QProcess child; child.setEnvironment(systemEnvironment() + environment_); - child.start(cmdline); + child.start(cmd, args); if (!child.waitForStarted(-1)) { testOutput_.append( "Unable to start child process." ); return errorOut(); @@ -185,7 +193,7 @@ void TestCompiler::resetArguments() qmakeArgs_.clear(); } -void TestCompiler::setArguments( QString makeArgs, QString qmakeArgs ) +void TestCompiler::setArguments(const QStringList &makeArgs, const QStringList &qmakeArgs) { makeArgs_ = makeArgs; qmakeArgs_ = qmakeArgs; @@ -213,7 +221,7 @@ bool TestCompiler::makeClean( const QString &workPath ) QFileInfo Fi( workPath + "/Makefile"); if (Fi.exists()) // Run make clean - return runCommand( makeCmd_ + " clean" ); + return runCommand(makeCmd_, QStringList() << "clean"); return true; } @@ -230,7 +238,7 @@ bool TestCompiler::makeDistClean( const QString &workPath ) QFileInfo Fi( workPath + "/Makefile"); if (Fi.exists()) // Run make distclean - return runCommand( makeCmd_ + " distclean" ); + return runCommand(makeCmd_, QStringList() << "distclean"); return true; @@ -249,7 +257,7 @@ bool TestCompiler::qmakeProject( const QString &workDir, const QString &proName if (!projectFile.endsWith(".pro")) projectFile += ".pro"; - return runCommand(qmakeCmd_ + " -project -o " + projectFile + " DESTDIR=./"); + return runCommand(qmakeCmd_, QStringList() << "-project" << "-o" << projectFile << "DESTDIR=./"); } bool TestCompiler::qmake( const QString &workDir, const QString &proName, const QString &buildDir ) @@ -269,7 +277,7 @@ bool TestCompiler::qmake( const QString &workDir, const QString &proName, const makeFile += "Makefile"; // Now start qmake and generate the makefile - return runCommand( qmakeCmd_ + " " + qmakeArgs_ + " " + projectFile + " -o " + makeFile ); + return runCommand(qmakeCmd_, QStringList(qmakeArgs_) << projectFile << "-o" << makeFile); } bool TestCompiler::make( const QString &workPath, const QString &target, bool expectFail ) @@ -277,13 +285,13 @@ bool TestCompiler::make( const QString &workPath, const QString &target, bool ex QDir D; D.setCurrent( workPath ); - QString cmdline = makeCmd_ + " " + makeArgs_; - if ( cmdline.contains("nmake", Qt::CaseInsensitive) ) - cmdline.append(" /NOLOGO"); - if ( !target.isEmpty() ) - cmdline += " " + target; + QStringList args = makeArgs_; + if (makeCmd_.contains("nmake", Qt::CaseInsensitive)) + args << "/NOLOGO"; + if (!target.isEmpty()) + args << target; - return runCommand( cmdline, expectFail ); + return runCommand(makeCmd_, args, expectFail); } bool TestCompiler::exists( const QString &destDir, const QString &exeName, BuildType buildType, const QString &version ) diff --git a/tests/auto/tools/qmake/testcompiler.h b/tests/auto/tools/qmake/testcompiler.h index 5e0d706c68..ee73b6cbb3 100644 --- a/tests/auto/tools/qmake/testcompiler.h +++ b/tests/auto/tools/qmake/testcompiler.h @@ -49,7 +49,7 @@ public: void setBaseCommands( QString makeCmd, QString qmakeCmd ); void resetArguments(); - void setArguments( QString makeArgs, QString qmakeArgs ); + void setArguments(const QStringList &makeArgs, const QStringList &qmakeArgs); void resetEnvironment(); void addToEnvironment( QString varAssignment ); @@ -78,11 +78,13 @@ public: void clearCommandOutput(); private: - bool runCommand( QString cmdLine, bool expectFail = false ); + bool runCommand(const QString &cmd, const QStringList &args, bool expectFail = false); bool errorOut(); - QString makeCmd_, makeArgs_; - QString qmakeCmd_, qmakeArgs_; + QString makeCmd_; + QStringList makeArgs_; + QString qmakeCmd_; + QStringList qmakeArgs_; QStringList environment_; QStringList testOutput_; diff --git a/tests/auto/tools/qmake/tst_qmake.cpp b/tests/auto/tools/qmake/tst_qmake.cpp index 53d90aa5ce..cc69b78a52 100644 --- a/tests/auto/tools/qmake/tst_qmake.cpp +++ b/tests/auto/tools/qmake/tst_qmake.cpp @@ -461,7 +461,8 @@ void tst_qmake::bundle_spaces() // Bundles and since this might be the wrong output we rely on dry-running // make (-n). - test_compiler.setArguments("-n", "-spec macx-clang"); + test_compiler.setArguments(QStringList() << "-n", + QStringList() << "-spec" << "macx-clang"); QVERIFY( test_compiler.qmake(workDir, "bundle-spaces") ); -- cgit v1.2.3