forked from qt-creator/qt-creator
Process: Make multiRead test platform independent
Change-Id: Ife58e7b2a41ac35f8137acfc66ff827672f75de9 Reviewed-by: hjk <hjk@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
@@ -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());
|
||||
|
@@ -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);
|
||||
|
@@ -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()
|
||||
|
Reference in New Issue
Block a user