diff --git a/tests/auto/utils/process/processtestapp/processtestapp.cpp b/tests/auto/utils/process/processtestapp/processtestapp.cpp index d9a10f31faa..efdb4b6a407 100644 --- a/tests/auto/utils/process/processtestapp/processtestapp.cpp +++ b/tests/auto/utils/process/processtestapp/processtestapp.cpp @@ -115,6 +115,23 @@ int ProcessTestApp::SimpleTest::main() return 0; } +int ProcessTestApp::ChannelEchoer::main() +{ + const QProcess::ProcessChannel processChannel + = QProcess::ProcessChannel(envVarIntWithDefault(envVar(), 0)); + while (true) { + std::string input; + std::cin >> input; + if (input == "exit") + return 0; + if (processChannel == QProcess::StandardOutput) + std::cout << input << std::endl; + else + std::cerr << input << std::endl; + } + return 0; +} + int ProcessTestApp::ExitCode::main() { const int exitCode = qEnvironmentVariableIntValue(envVar()); diff --git a/tests/auto/utils/process/processtestapp/processtestapp.h b/tests/auto/utils/process/processtestapp/processtestapp.h index 4c7e84e3028..6237e4df383 100644 --- a/tests/auto/utils/process/processtestapp/processtestapp.h +++ b/tests/auto/utils/process/processtestapp/processtestapp.h @@ -44,6 +44,7 @@ public: // of the subprocess. The following subprocess classes are defined: SUB_PROCESS(SimpleTest); + SUB_PROCESS(ChannelEchoer); SUB_PROCESS(ExitCode); SUB_PROCESS(RunBlockingStdOut); SUB_PROCESS(LineCallback); diff --git a/tests/auto/utils/process/tst_process.cpp b/tests/auto/utils/process/tst_process.cpp index c8b1345b3a5..b8e83b3362f 100644 --- a/tests/auto/utils/process/tst_process.cpp +++ b/tests/auto/utils/process/tst_process.cpp @@ -121,7 +121,6 @@ private slots: } void multiRead(); - void splitArgs_data(); void splitArgs(); void prepareArgs_data(); @@ -247,30 +246,31 @@ Q_DECLARE_METATYPE(Utils::ProcessResult) void tst_Process::multiRead() { - if (HostOsInfo::isWindowsHost()) - QSKIP("This test uses /bin/sh."); + SubProcessConfig subConfig(ProcessTestApp::ChannelEchoer::envVar(), {}); QByteArray buffer; Process process; + subConfig.setupSubProcess(&process); - process.setCommand({"/bin/sh", {}}); - process.setProcessChannelMode(QProcess::SeparateChannels); process.setProcessMode(Utils::ProcessMode::Writer); - process.start(); + QVERIFY(process.waitForStarted()); - process.writeRaw("echo hi\n"); - + process.writeRaw("hi\n"); QVERIFY(process.waitForReadyRead(1000)); buffer = process.readAllRawStandardOutput(); + buffer.replace("\r\n", "\n"); // Needed for Windows only QCOMPARE(buffer, QByteArray("hi\n")); - process.writeRaw("echo you\n"); - + process.writeRaw("you\n"); QVERIFY(process.waitForReadyRead(1000)); buffer = process.readAllRawStandardOutput(); + buffer.replace("\r\n", "\n"); // Needed for Windows only QCOMPARE(buffer, QByteArray("you\n")); + + process.writeRaw("exit\n"); + QVERIFY(process.waitForFinished(1000)); } void tst_Process::splitArgs_data()