summaryrefslogtreecommitdiffstats
path: root/tests/auto/tools/qmakelib/evaltest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/tools/qmakelib/evaltest.cpp')
-rw-r--r--tests/auto/tools/qmakelib/evaltest.cpp198
1 files changed, 191 insertions, 7 deletions
diff --git a/tests/auto/tools/qmakelib/evaltest.cpp b/tests/auto/tools/qmakelib/evaltest.cpp
index df8736a1b1..e3be294e5f 100644
--- a/tests/auto/tools/qmakelib/evaltest.cpp
+++ b/tests/auto/tools/qmakelib/evaltest.cpp
@@ -815,6 +815,49 @@ void tst_qmakelib::addReplaceFunctions(const QString &qindir)
<< "##:2: member() argument 2 (start) '4..foo' invalid."
<< true;
+ // The argument processing is shared with $$member(), so some tests are skipped.
+ QTest::newRow("$$str_member(): empty")
+ << "VAR = $$str_member()"
+ << "VAR ="
+ << ""
+ << true;
+
+ QTest::newRow("$$str_member(): too short")
+ << "VAR = $$str_member(string_value, 7, 12)"
+ << "VAR =" // this is actually kinda stupid
+ << ""
+ << true;
+
+ QTest::newRow("$$str_member(): ok")
+ << "VAR = $$str_member(string_value, 7, 11)"
+ << "VAR = value"
+ << ""
+ << true;
+
+ QTest::newRow("$$str_member(): ok (default start)")
+ << "VAR = $$str_member(string_value)"
+ << "VAR = s"
+ << ""
+ << true;
+
+ QTest::newRow("$$str_member(): ok (default end)")
+ << "VAR = $$str_member(string_value, 7)"
+ << "VAR = v"
+ << ""
+ << true;
+
+ QTest::newRow("$$str_member(): negative")
+ << "VAR = $$str_member(string_value, -5, -3)"
+ << "VAR = val"
+ << ""
+ << true;
+
+ QTest::newRow("$$str_member(): inverse")
+ << "VAR = $$str_member(string_value, -2, 1)"
+ << "VAR = ulav_gnirt"
+ << ""
+ << true;
+
QTest::newRow("$$first(): empty")
<< "IN = \nVAR = $$first(IN)"
<< "VAR ="
@@ -839,6 +882,30 @@ void tst_qmakelib::addReplaceFunctions(const QString &qindir)
<< "##:1: first(var) requires one argument."
<< true;
+ QTest::newRow("$$take_first(): empty")
+ << "IN = \nVAR = $$take_first(IN)"
+ << "VAR =\nIN ="
+ << ""
+ << true;
+
+ QTest::newRow("$$take_first(): one")
+ << "IN = one\nVAR = $$take_first(IN)"
+ << "VAR = one\nIN ="
+ << ""
+ << true;
+
+ QTest::newRow("$$take_first(): multiple")
+ << "IN = one two three\nVAR = $$take_first(IN)"
+ << "VAR = one\nIN = two three"
+ << ""
+ << true;
+
+ QTest::newRow("$$take_first(): bad number of arguments")
+ << "VAR = $$take_first(1, 2)"
+ << "VAR ="
+ << "##:1: take_first(var) requires one argument."
+ << true;
+
QTest::newRow("$$last(): empty")
<< "IN = \nVAR = $$last(IN)"
<< "VAR ="
@@ -863,6 +930,30 @@ void tst_qmakelib::addReplaceFunctions(const QString &qindir)
<< "##:1: last(var) requires one argument."
<< true;
+ QTest::newRow("$$take_last(): empty")
+ << "IN = \nVAR = $$take_last(IN)"
+ << "VAR =\nIN ="
+ << ""
+ << true;
+
+ QTest::newRow("$$take_last(): one")
+ << "IN = one\nVAR = $$take_last(IN)"
+ << "VAR = one\nIN ="
+ << ""
+ << true;
+
+ QTest::newRow("$$take_last(): multiple")
+ << "IN = one two three\nVAR = $$take_last(IN)"
+ << "VAR = three\nIN = one two"
+ << ""
+ << true;
+
+ QTest::newRow("$$take_last(): bad number of arguments")
+ << "VAR = $$take_last(1, 2)"
+ << "VAR ="
+ << "##:1: take_last(var) requires one argument."
+ << true;
+
QTest::newRow("$$size()")
<< "IN = one two three\nVAR = $$size(IN)"
<< "VAR = 3"
@@ -875,6 +966,18 @@ void tst_qmakelib::addReplaceFunctions(const QString &qindir)
<< "##:1: size(var) requires one argument."
<< true;
+ QTest::newRow("$$str_size()")
+ << "VAR = $$str_size(one two three)"
+ << "VAR = 13"
+ << ""
+ << true;
+
+ QTest::newRow("$$str_size(): bad number of arguments")
+ << "VAR = $$str_size(1, 2)"
+ << "VAR ="
+ << "##:1: str_size(str) requires one argument."
+ << true;
+
QTest::newRow("$$fromfile(): right var")
<< "VAR = $$fromfile(" + qindir + "/fromfile/infile.prx, DEFINES)"
<< "VAR = QT_DLL"
@@ -1003,6 +1106,48 @@ void tst_qmakelib::addReplaceFunctions(const QString &qindir)
<< "##:1: format_number(): invalid format option foo=bar."
<< true;
+ QTest::newRow("$$num_add(): one")
+ << "VAR = $$num_add(10)"
+ << "VAR = 10"
+ << ""
+ << true;
+
+ QTest::newRow("$$num_add(): two")
+ << "VAR = $$num_add(1, 2)"
+ << "VAR = 3"
+ << ""
+ << true;
+
+ QTest::newRow("$$num_add(): three")
+ << "VAR = $$num_add(1, 3, 5)"
+ << "VAR = 9"
+ << ""
+ << true;
+
+ QTest::newRow("$$num_add(): negative")
+ << "VAR = $$num_add(7, -13)"
+ << "VAR = -6"
+ << ""
+ << true;
+
+ QTest::newRow("$$num_add(): bad number of arguments")
+ << "VAR = $$num_add()"
+ << "VAR = "
+ << "##:1: num_add(num, ...) requires at least one argument."
+ << true;
+
+ QTest::newRow("$$num_add(): bad number: float")
+ << "VAR = $$num_add(1.1)"
+ << "VAR ="
+ << "##:1: num_add(): floats are currently not supported."
+ << true;
+
+ QTest::newRow("$$num_add(): bad number: malformed")
+ << "VAR = $$num_add(fail)"
+ << "VAR ="
+ << "##:1: num_add(): malformed number fail."
+ << true;
+
QTest::newRow("$$join(): empty")
<< "IN = \nVAR = $$join(IN, //)"
<< "VAR ="
@@ -1181,9 +1326,9 @@ void tst_qmakelib::addReplaceFunctions(const QString &qindir)
<< true;
QTest::newRow("$$system(): bad number of arguments")
- << "VAR = $$system(1, 2, 3)"
+ << "VAR = $$system(1, 2, 3, 4)"
<< "VAR ="
- << "##:1: system(execute) requires one or two arguments."
+ << "##:1: system(command, [mode], [stsvar]) requires one to three arguments."
<< true;
QTest::newRow("$$unique()")
@@ -1198,6 +1343,18 @@ void tst_qmakelib::addReplaceFunctions(const QString &qindir)
<< "##:1: unique(var) requires one argument."
<< true;
+ QTest::newRow("$$sorted()")
+ << "IN = one two three\nVAR = $$sorted(IN)"
+ << "VAR = one three two"
+ << ""
+ << true;
+
+ QTest::newRow("$$sorted(): bad number of arguments")
+ << "VAR = $$sorted(1, 2)"
+ << "VAR ="
+ << "##:1: sorted(var) requires one argument."
+ << true;
+
QTest::newRow("$$reverse()")
<< "IN = one two three\nVAR = $$reverse(IN)"
<< "VAR = three two one"
@@ -2102,7 +2259,7 @@ void tst_qmakelib::addTestFunctions(const QString &qindir)
<< "jsontext = not good\n"
"parseJson(jsontext, json): OK = 1"
<< "OK = UNDEF"
- << ""
+ << "##:2: Error parsing JSON at 1:1: illegal value"
<< true;
QTest::newRow("parseJson(): bad number of arguments")
@@ -2168,6 +2325,26 @@ void tst_qmakelib::addTestFunctions(const QString &qindir)
<< "##:1: load(feature) requires one or two arguments."
<< true;
+ QTest::newRow("discard_from()")
+ << "HERE = 1\nPLUS = one\n"
+ "defineTest(tfunc) {}\ndefineReplace(rfunc) {}\n"
+ "include(include/inc.pri)\n"
+ "contains(QMAKE_INTERNAL_INCLUDED_FILES, .*/include/inc\\\\.pri): PRE = 1\n"
+ "discard_from(include/inc.pri): OK = 1\n"
+ "!contains(QMAKE_INTERNAL_INCLUDED_FILES, .*/include/inc\\\\.pri): POST = 1\n"
+ "defined(tfunc, test): TDEF = 1\ndefined(rfunc, replace): RDEF = 1\n"
+ "defined(func, test): DTDEF = 1\ndefined(func, replace): DRDEF = 1\n"
+ << "PRE = 1\nPOST = 1\nOK = 1\nHERE = 1\nPLUS = one\nVAR = UNDEF\n"
+ "TDEF = 1\nRDEF = 1\nDTDEF = UNDEF\nDRDEF = UNDEF"
+ << ""
+ << true;
+
+ QTest::newRow("discard_from(): bad number of arguments")
+ << "discard_from(1, 2): OK = 1"
+ << "OK = UNDEF"
+ << "##:1: discard_from(file) requires one argument."
+ << true;
+
// We don't test debug() and log(), because they print directly to stderr.
QTest::newRow("message()")
@@ -2189,12 +2366,18 @@ void tst_qmakelib::addTestFunctions(const QString &qindir)
<< "Project WARNING: World, be warned!"
<< true;
- QTest::newRow("error()")
+ QTest::newRow("error(message)")
<< "error('World, you FAIL!'): OK = 1\nOKE = 1"
<< "OK = UNDEF\nOKE = UNDEF"
<< "Project ERROR: World, you FAIL!"
<< false;
+ QTest::newRow("error(empty)")
+ << "error(): OK = 1\nOKE = 1"
+ << "OK = UNDEF\nOKE = UNDEF"
+ << ""
+ << false;
+
QTest::newRow("if(error())")
<< "if(error(\\'World, you FAIL!\\')): OK = 1\nOKE = 1"
<< "OK = UNDEF\nOKE = UNDEF"
@@ -2581,19 +2764,20 @@ void tst_qmakelib::proEval()
QMakeTestHandler handler;
handler.setExpectedMessages(msgs.replace("##:", infile + ':').split('\n', QString::SkipEmptyParts));
QMakeVfs vfs;
- QMakeParser parser(0, &vfs, &handler);
+ ProFileCache cache;
+ QMakeParser parser(&cache, &vfs, &handler);
QMakeGlobals globals;
globals.do_cache = false;
globals.xqmakespec = "fake-g++";
globals.environment = m_env;
globals.setProperties(m_prop);
globals.setDirectories(m_indir, m_outdir);
- ProFile *outPro = parser.parsedProBlock(out, "out", 1, QMakeParser::FullGrammar);
+ ProFile *outPro = parser.parsedProBlock(QStringRef(&out), "out", 1, QMakeParser::FullGrammar);
if (!outPro->isOk()) {
qWarning("Expected output is malformed");
verified = false;
}
- ProFile *pro = parser.parsedProBlock(in, infile, 1, QMakeParser::FullGrammar);
+ ProFile *pro = parser.parsedProBlock(QStringRef(&in), infile, 1, QMakeParser::FullGrammar);
QMakeEvaluator visitor(&globals, &parser, &vfs, &handler);
visitor.setOutputDir(m_outdir);
#ifdef Q_OS_WIN