add qmake evaluator test

Change-Id: I31b95daede5edef245dd1ba447f2937a0db34232
Reviewed-by: Joerg Bornemann <joerg.bornemann@theqtcompany.com>
This commit is contained in:
Oswald Buddenhagen 2015-05-15 20:58:50 +02:00
parent ef50e244cd
commit 5ddc16b5df
22 changed files with 2604 additions and 14 deletions

View File

@ -135,6 +135,7 @@ public:
bool initProperties();
# else
void setProperties(const QHash<QString, QString> &props);
void setProperties(const QHash<ProKey, ProString> &props) { properties = props; }
# endif
ProString propertyValue(const ProKey &name) const { return properties.value(name); }
#endif

File diff suppressed because it is too large Load Diff

View File

@ -1956,7 +1956,7 @@ void tst_qmakelib::proParser()
QFETCH(bool, ok);
bool verified = true;
QMakeHandler handler;
QMakeTestHandler handler;
handler.setExpectedMessages(msgs.split('\n', QString::SkipEmptyParts));
QMakeVfs vfs;
QMakeParser parser(0, &vfs, &handler);

View File

@ -12,9 +12,13 @@ HEADERS += \
SOURCES += \
tst_qmakelib.cpp \
parsertest.cpp \
evaltest.cpp \
ioutils.cpp \
proitems.cpp \
qmakevfs.cpp \
qmakeparser.cpp
qmakeparser.cpp \
qmakeglobals.cpp \
qmakebuiltins.cpp \
qmakeevaluator.cpp
DEFINES += PROPARSER_DEBUG
DEFINES += PROPARSER_DEBUG PROEVALUATOR_FULL PROEVALUATOR_SETENV

View File

@ -0,0 +1,2 @@
"Hello, world."
foo bar baz

View File

@ -0,0 +1,5 @@
foo bar baz
"Hello, ' world." post
'Hello, " world.' post
\" \' \\ \a \ nix
" "

View File

View File

View File

View File

View File

View File

@ -0,0 +1 @@
error("fail!")

View File

@ -0,0 +1 @@
DEFINES = QT_DLL

View File

@ -0,0 +1,8 @@
VAR = val
.VAR = nope
fake-*: MATCH = 1
defineTest(func) {
message("say hi!")
}

View File

@ -0,0 +1 @@
# Nothing here

View File

@ -0,0 +1 @@
# Nothing here

View File

@ -0,0 +1 @@
# Nothing here

View File

@ -0,0 +1 @@
# Nothing here

View File

@ -0,0 +1 @@
# Nothing here

View File

@ -0,0 +1 @@
VAR = foo bar

View File

@ -37,6 +37,27 @@
using namespace QMakeInternal;
void tst_qmakelib::initTestCase()
{
m_indir = QFINDTESTDATA("testdata");
m_outdir = m_indir + QLatin1String("_build");
m_env.insert(QStringLiteral("E1"), QStringLiteral("env var"));
#ifdef Q_OS_WIN
m_env.insert(QStringLiteral("COMSPEC"), qgetenv("COMSPEC"));
#endif
m_prop.insert(ProKey("P1"), ProString("prop val"));
m_prop.insert(ProKey("QT_HOST_DATA/get"), ProString(m_indir));
QVERIFY(!m_indir.isEmpty());
QVERIFY(QDir(m_outdir).removeRecursively());
QVERIFY(QDir().mkpath(m_outdir));
}
void tst_qmakelib::cleanupTestCase()
{
QVERIFY(QDir(m_outdir).removeRecursively());
}
void tst_qmakelib::proString()
{
QString qs1(QStringLiteral("this is a string"));
@ -225,21 +246,24 @@ void tst_qmakelib::pathUtils()
QCOMPARE(IoUtils::resolvePath(fnbase, fn1), QStringLiteral("/a/unix/file/path"));
}
void QMakeHandler::print(const QString &fileName, int lineNo, int type, const QString &msg)
void QMakeTestHandler::print(const QString &fileName, int lineNo, int type, const QString &msg)
{
QString pfx = ((type & QMakeParserHandler::CategoryMask) == QMakeParserHandler::WarningMessage)
? QString::fromLatin1("WARNING: ") : QString();
QString out;
if (lineNo)
out = QStringLiteral("%1%2:%3: %4").arg(pfx, fileName, QString::number(lineNo), msg);
doPrint(QStringLiteral("%1%2:%3: %4").arg(pfx, fileName, QString::number(lineNo), msg));
else
out = QStringLiteral("%1%2").arg(pfx, msg);
if (!expected.isEmpty() && expected.first() == out) {
doPrint(QStringLiteral("%1%2").arg(pfx, msg));
}
void QMakeTestHandler::doPrint(const QString &msg)
{
if (!expected.isEmpty() && expected.first() == msg) {
expected.removeAt(0);
return;
} else {
qWarning("%s", qPrintable(msg));
printed = true;
}
qWarning("%s", qPrintable(out));
printed = true;
}
QTEST_MAIN(tst_qmakelib)

View File

@ -31,9 +31,10 @@
**
****************************************************************************/
#include <qmakeparser.h>
#include <qmakeevaluator.h>
#include <QObject>
#include <QProcessEnvironment>
#include <QtTest/QtTest>
class tst_qmakelib : public QObject
@ -45,6 +46,9 @@ public:
virtual ~tst_qmakelib() {}
private slots:
void initTestCase();
void cleanupTestCase();
void quoteArgUnix_data();
void quoteArgUnix();
void quoteArgWin_data();
@ -57,6 +61,9 @@ private slots:
void proParser_data();
void proParser();
void proEval_data();
void proEval();
private:
void addParseOperators();
void addParseValues();
@ -65,14 +72,30 @@ private:
void addParseBraces();
void addParseCustomFunctions();
void addParseAbuse();
void addAssignments();
void addExpansions();
void addControlStructs();
void addReplaceFunctions(const QString &qindir);
void addTestFunctions(const QString &qindir);
QProcessEnvironment m_env;
QHash<ProKey, ProString> m_prop;
QString m_indir, m_outdir;
};
class QMakeHandler : public QMakeParserHandler {
class QMakeTestHandler : public QMakeHandler {
public:
QMakeHandler() : QMakeParserHandler(), printed(false) {}
QMakeTestHandler() : QMakeHandler(), printed(false) {}
virtual void message(int type, const QString &msg, const QString &fileName, int lineNo)
{ print(fileName, lineNo, type, msg); }
virtual void fileMessage(const QString &msg)
{ doPrint(msg); }
virtual void aboutToEval(ProFile *, ProFile *, EvalFileType) {}
virtual void doneWithEval(ProFile *) {}
void setExpectedMessages(const QStringList &msgs) { expected = msgs; }
QStringList expectedMessages() const { return expected; }
@ -80,7 +103,9 @@ public:
private:
void print(const QString &fileName, int lineNo, int type, const QString &msg);
void doPrint(const QString &msg);
QStringList expected;
bool printed;
};