forked from qt-creator/qt-creator
support tilde expansion under unix
Task-number: QTCREATORBUG-4239
This commit is contained in:
@@ -34,10 +34,7 @@
|
||||
#include "qtcprocess.h"
|
||||
#include "stringutils.h"
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
#include <QtCore/QDir>
|
||||
#endif
|
||||
|
||||
#include <QtCore/QDebug>
|
||||
|
||||
using namespace Utils;
|
||||
@@ -311,6 +308,16 @@ QStringList QtcProcess::splitArgs(const QString &args, bool abortOnMeta, SplitEr
|
||||
} while (c.isSpace());
|
||||
QString cret;
|
||||
bool hadWord = false;
|
||||
if (c == QLatin1Char('~')) {
|
||||
if (pos >= args.length()
|
||||
|| args.unicode()[pos].isSpace() || args.unicode()[pos] == QLatin1Char('/')) {
|
||||
cret = QDir::homePath();
|
||||
hadWord = true;
|
||||
goto getc;
|
||||
} else if (abortOnMeta) {
|
||||
goto metaerr;
|
||||
}
|
||||
}
|
||||
do {
|
||||
if (c == QLatin1Char('\'')) {
|
||||
int spos = pos;
|
||||
@@ -449,6 +456,7 @@ QStringList QtcProcess::splitArgs(const QString &args, bool abortOnMeta, SplitEr
|
||||
cret += c;
|
||||
hadWord = true;
|
||||
}
|
||||
getc:
|
||||
if (pos >= args.length())
|
||||
break;
|
||||
c = args.unicode()[pos++];
|
||||
|
||||
@@ -76,10 +76,19 @@ private slots:
|
||||
private:
|
||||
Environment env;
|
||||
MacroMapExpander mx;
|
||||
#ifdef Q_OS_UNIX
|
||||
QString homeStr;
|
||||
QString home;
|
||||
#endif
|
||||
};
|
||||
|
||||
void tst_QtcProcess::initTestCase()
|
||||
{
|
||||
#ifdef Q_OS_UNIX
|
||||
homeStr = QLatin1String("@HOME@");
|
||||
home = QDir::homePath();
|
||||
#endif
|
||||
|
||||
env.set("empty", "");
|
||||
env.set("word", "hi");
|
||||
env.set("words", "hi ho");
|
||||
@@ -161,12 +170,20 @@ void tst_QtcProcess::splitArgs_data()
|
||||
{ "hi'", "", QtcProcess::BadQuoting },
|
||||
{ "hi\"dood", "", QtcProcess::BadQuoting },
|
||||
{ "$var", "'$var'", QtcProcess::SplitOk },
|
||||
{ "~", "@HOME@", QtcProcess::SplitOk },
|
||||
{ "~ foo", "@HOME@ foo", QtcProcess::SplitOk },
|
||||
{ "foo ~", "foo @HOME@", QtcProcess::SplitOk },
|
||||
{ "~/foo", "@HOME@/foo", QtcProcess::SplitOk },
|
||||
{ "~foo", "'~foo'", QtcProcess::SplitOk },
|
||||
#endif
|
||||
};
|
||||
|
||||
for (unsigned i = 0; i < sizeof(vals)/sizeof(vals[0]); i++)
|
||||
QTest::newRow(vals[i].in) << QString::fromLatin1(vals[i].in)
|
||||
<< QString::fromLatin1(vals[i].out)
|
||||
#ifdef Q_OS_UNIX
|
||||
.replace(homeStr, home)
|
||||
#endif
|
||||
<< vals[i].err;
|
||||
}
|
||||
|
||||
@@ -221,12 +238,19 @@ void tst_QtcProcess::prepareArgs_data()
|
||||
{ "hi'", "", QtcProcess::BadQuoting },
|
||||
{ "hi\"dood", "", QtcProcess::BadQuoting },
|
||||
{ "$var", "", QtcProcess::FoundMeta },
|
||||
{ "~", "@HOME@", QtcProcess::SplitOk },
|
||||
{ "~ foo", "@HOME@ foo", QtcProcess::SplitOk },
|
||||
{ "~/foo", "@HOME@/foo", QtcProcess::SplitOk },
|
||||
{ "~foo", "", QtcProcess::FoundMeta },
|
||||
#endif
|
||||
};
|
||||
|
||||
for (unsigned i = 0; i < sizeof(vals)/sizeof(vals[0]); i++)
|
||||
QTest::newRow(vals[i].in) << QString::fromLatin1(vals[i].in)
|
||||
<< QString::fromLatin1(vals[i].out)
|
||||
#ifdef Q_OS_UNIX
|
||||
.replace(homeStr, home)
|
||||
#endif
|
||||
<< vals[i].err;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user