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