forked from qt-creator/qt-creator
Utils: Fix splitting in ChannelBuffer::takeFirstLine()
Escape the '\r' Change-Id: I8cee40dc4a65f893f1a11c7cf066777498c37339 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -875,7 +875,7 @@ QString ChannelBuffer::linesRead()
|
|||||||
// Check for first complete line inside the rawData and return it, removing the line from the buffer
|
// Check for first complete line inside the rawData and return it, removing the line from the buffer
|
||||||
Utils::optional<QString> ChannelBuffer::takeFirstLine()
|
Utils::optional<QString> ChannelBuffer::takeFirstLine()
|
||||||
{
|
{
|
||||||
const int firstLineEnd = qMax(rawData.indexOf('\n'), rawData.indexOf('r'));
|
const int firstLineEnd = qMax(rawData.indexOf('\n'), rawData.indexOf('\r'));
|
||||||
if (firstLineEnd == -1)
|
if (firstLineEnd == -1)
|
||||||
return Utils::nullopt;
|
return Utils::nullopt;
|
||||||
|
|
||||||
|
@@ -37,6 +37,15 @@ using namespace Utils;
|
|||||||
const char kExitCodeSubProcessCode[] = "QTC_TST_QTCPROCESS_EXITCODE_CODE";
|
const char kExitCodeSubProcessCode[] = "QTC_TST_QTCPROCESS_EXITCODE_CODE";
|
||||||
const char kRunBlockingStdOutSubProcessMagicWord[] = "42";
|
const char kRunBlockingStdOutSubProcessMagicWord[] = "42";
|
||||||
const char kRunBlockingStdOutSubProcessWithEndl[] = "QTC_TST_QTCPROCESS_RUNBLOCKINGSTDOUT_WITHENDL";
|
const char kRunBlockingStdOutSubProcessWithEndl[] = "QTC_TST_QTCPROCESS_RUNBLOCKINGSTDOUT_WITHENDL";
|
||||||
|
const char kLineCallback[] = "QTC_TST_QTCPROCESS_LINECALLBACK";
|
||||||
|
|
||||||
|
Q_GLOBAL_STATIC_WITH_ARGS(const QStringList, lineCallbackData,
|
||||||
|
({
|
||||||
|
"This is the first line\r",
|
||||||
|
"Here comes the second one\r",
|
||||||
|
"Let's also have a third one\r",
|
||||||
|
"Actually four are better\r",
|
||||||
|
}))
|
||||||
|
|
||||||
static void exitCodeSubProcessMain()
|
static void exitCodeSubProcessMain()
|
||||||
{
|
{
|
||||||
@@ -57,6 +66,13 @@ static void blockingStdOutSubProcessMain()
|
|||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void lineCallbackMain()
|
||||||
|
{
|
||||||
|
for (const QString &line : *lineCallbackData())
|
||||||
|
std::cerr << qPrintable(line);
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
class MacroMapExpander : public AbstractMacroExpander {
|
class MacroMapExpander : public AbstractMacroExpander {
|
||||||
public:
|
public:
|
||||||
virtual bool resolveMacro(const QString &name, QString *ret, QSet<AbstractMacroExpander*> &seen)
|
virtual bool resolveMacro(const QString &name, QString *ret, QSet<AbstractMacroExpander*> &seen)
|
||||||
@@ -102,6 +118,7 @@ private slots:
|
|||||||
void exitCode();
|
void exitCode();
|
||||||
void runBlockingStdOut_data();
|
void runBlockingStdOut_data();
|
||||||
void runBlockingStdOut();
|
void runBlockingStdOut();
|
||||||
|
void lineCallback();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void iteratorEditsHelper(OsType osType);
|
void iteratorEditsHelper(OsType osType);
|
||||||
@@ -121,6 +138,8 @@ void tst_QtcProcess::initTestCase()
|
|||||||
exitCodeSubProcessMain();
|
exitCodeSubProcessMain();
|
||||||
if (qEnvironmentVariableIsSet(kRunBlockingStdOutSubProcessWithEndl))
|
if (qEnvironmentVariableIsSet(kRunBlockingStdOutSubProcessWithEndl))
|
||||||
blockingStdOutSubProcessMain();
|
blockingStdOutSubProcessMain();
|
||||||
|
if (qEnvironmentVariableIsSet(kLineCallback))
|
||||||
|
lineCallbackMain();
|
||||||
|
|
||||||
homeStr = QLatin1String("@HOME@");
|
homeStr = QLatin1String("@HOME@");
|
||||||
home = QDir::homePath();
|
home = QDir::homePath();
|
||||||
@@ -871,6 +890,23 @@ void tst_QtcProcess::runBlockingStdOut()
|
|||||||
QVERIFY2(readLastLine, "Last line was read.");
|
QVERIFY2(readLastLine, "Last line was read.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst_QtcProcess::lineCallback()
|
||||||
|
{
|
||||||
|
QtcProcess process;
|
||||||
|
QStringList args = QCoreApplication::arguments();
|
||||||
|
const QString binary = args.takeFirst();
|
||||||
|
process.setCommand(CommandLine(binary, args));
|
||||||
|
Environment env = Environment::systemEnvironment();
|
||||||
|
env.set(kLineCallback, "Yes");
|
||||||
|
process.setEnvironment(env);
|
||||||
|
int lineNumber = 0;
|
||||||
|
process.setStdErrLineCallback([&lineNumber](const QString &actual) {
|
||||||
|
const QString expected = lineCallbackData()->at(lineNumber++).trimmed();
|
||||||
|
QCOMPARE(actual, expected);
|
||||||
|
});
|
||||||
|
process.start();
|
||||||
|
process.waitForFinished();
|
||||||
|
}
|
||||||
QTEST_MAIN(tst_QtcProcess)
|
QTEST_MAIN(tst_QtcProcess)
|
||||||
|
|
||||||
#include "tst_qtcprocess.moc"
|
#include "tst_qtcprocess.moc"
|
||||||
|
Reference in New Issue
Block a user