summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJoerg Bornemann <joerg.bornemann@qt.io>2019-03-20 16:42:54 +0100
committerJoerg Bornemann <joerg.bornemann@qt.io>2019-03-25 08:51:35 +0000
commit307d95735ff48e3734bbae2037dafc2ea6404889 (patch)
tree65e62d0801a3771828f3d6ffbcf1164341435abe /tests
parent01815fce03c9ce5eb7dfdf2527250a34cb3eb525 (diff)
Fix handling of macro definitions on command line
Setting a variable FooBar=2 on the command line explicitly defines the macro FooBar, but also implicitly defines the macro FOOBAR. Explicitly set macros are not overridden. The first definition wins. Implicitly set macros are overridden. The last definition wins. Fixes: QTCREATORBUG-22176 Change-Id: I5324ba20295a1fade5e98302d698a826400fa80c Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/makefiles/blackbox/macrosOnCommandLine/test.mk3
-rw-r--r--tests/tests.cpp77
-rw-r--r--tests/tests.h2
3 files changed, 80 insertions, 2 deletions
diff --git a/tests/makefiles/blackbox/macrosOnCommandLine/test.mk b/tests/makefiles/blackbox/macrosOnCommandLine/test.mk
new file mode 100644
index 0000000..efd7090
--- /dev/null
+++ b/tests/makefiles/blackbox/macrosOnCommandLine/test.mk
@@ -0,0 +1,3 @@
+FooBar = 1
+!message FooBar:$(FooBar)
+!message FOOBAR:$(FOOBAR)
diff --git a/tests/tests.cpp b/tests/tests.cpp
index d939cb0..21184de 100644
--- a/tests/tests.cpp
+++ b/tests/tests.cpp
@@ -25,11 +25,12 @@
#include "tests.h"
-#include <QTest>
+#include <QDebug>
#include <QDir>
+#include <QHash>
#include <QScopedPointer>
-#include <QDebug>
#include <QStringBuilder>
+#include <QTest>
#include <ppexprparser.h>
#include <makefilefactory.h>
@@ -39,6 +40,7 @@
#include <exception.h>
#include <algorithm>
+#include <functional>
#include <limits>
using namespace NMakeFile;
@@ -1208,6 +1210,77 @@ void Tests::suffixes()
QCOMPARE(output.takeFirst(), QByteArray("c -> x"));
}
+using ByteArrayDict = QHash<QByteArray, QByteArray>;
+
+void Tests::macrosOnCommandLine_data()
+{
+ QTest::addColumn<QStringList>("arguments");
+ QTest::addColumn<ByteArrayDict>("expectedMacros");
+ QTest::newRow("no_arguments")
+ << QStringList()
+ << ByteArrayDict{ { "FooBar", "1" }, { "FOOBAR", "" } };
+ QTest::newRow("FooBar")
+ << QStringList{ "FooBar=2" }
+ << ByteArrayDict{ { "FooBar", "2" }, { "FOOBAR", "2" } };
+ QTest::newRow("FOOBAR")
+ << QStringList{ "FOOBAR=2" }
+ << ByteArrayDict{ { "FooBar", "1" }, { "FOOBAR", "2" } };
+ QTest::newRow("foobar")
+ << QStringList{ "foobar=2" }
+ << ByteArrayDict{ { "FooBar", "1" }, { "FOOBAR", "2" } };
+ QTest::newRow("FooBar_FOOBAR")
+ << QStringList{ "FooBar=2", "FOOBAR=3" }
+ << ByteArrayDict{ { "FooBar", "2" }, { "FOOBAR", "3" } };
+ QTest::newRow("FOOBAR_FooBar")
+ << QStringList{ "FOOBAR=2", "FooBar=3" }
+ << ByteArrayDict{ { "FooBar", "3" }, { "FOOBAR", "2" } };
+ QTest::newRow("FooBar_FOOBAR_foobar")
+ << QStringList{ "FooBar=2", "FOOBAR=3", "foobar=4" }
+ << ByteArrayDict{ { "FooBar", "2" }, { "FOOBAR", "3" } };
+ QTest::newRow("foobar_FooBar_FOOBAR")
+ << QStringList{ "foobar=2", "FooBar=3", "FOOBAR=4" }
+ << ByteArrayDict{ { "FooBar", "3" }, { "FOOBAR", "4" } };
+ QTest::newRow("FooBar_FooBar")
+ << QStringList{ "FooBar=2", "FooBar=3" }
+ << ByteArrayDict{ { "FooBar", "2" }, { "FOOBAR", "3" } };
+ QTest::newRow("FooBar_FooBar_FooBar")
+ << QStringList{ "FooBar=2", "FooBar=3", "FooBar=4" }
+ << ByteArrayDict{ { "FooBar", "2" }, { "FOOBAR", "4" } };
+ QTest::newRow("FOOBAR_FOOBAR")
+ << QStringList{ "FOOBAR=2", "FOOBAR=3" }
+ << ByteArrayDict{ { "FooBar", "1" }, { "FOOBAR", "2" } };
+ QTest::newRow("FOOBAR_FOOBAR_FOOBAR")
+ << QStringList{ "FOOBAR=2", "FOOBAR=3", "FOOBAR=4" }
+ << ByteArrayDict{ { "FooBar", "1" }, { "FOOBAR", "2" } };
+ QTest::newRow("FooBar_FooBar_FOOBAR_FOOBAR")
+ << QStringList{ "FooBar=2", "FooBar=3", "FOOBAR=4", "FOOBAR=5" }
+ << ByteArrayDict{ { "FooBar", "2" }, { "FOOBAR", "4" } };
+}
+
+void Tests::macrosOnCommandLine()
+{
+ QFETCH(QStringList, arguments);
+ QFETCH(ByteArrayDict, expectedMacros);
+ QVERIFY(runJom(arguments << "/nologo" << "/f" << "test.mk", "blackbox/macrosOnCommandLine"));
+ QCOMPARE(m_jomProcess->exitCode(), 0);
+ QList<QByteArray> output = m_jomProcess->readAllStandardOutput().split('\n');
+ std::transform(output.cbegin(), output.cend(), output.begin(),
+ [](const QByteArray &line) { return line.trimmed(); });
+ auto it = std::remove_if(output.begin(), output.end(), std::mem_fn(&QByteArray::isEmpty));
+ if (it != output.end())
+ output.erase(it, output.end());
+ ByteArrayDict macros;
+ for (const QByteArray &line : qAsConst(output)) {
+ auto x = line.split(':');
+ macros[x.at(0)] = x.at(1);
+ }
+ if (macros != expectedMacros) {
+ qDebug() << " actual:" << macros;
+ qDebug() << "expected:" << expectedMacros;
+ QFAIL("Unexpected macro values");
+ }
+}
+
void Tests::nonexistentDependent()
{
QVERIFY(runJom(QStringList() << "/nologo" << "/f" << "test.mk", "blackbox/nonexistentdependent"));
diff --git a/tests/tests.h b/tests/tests.h
index b98758c..820a078 100644
--- a/tests/tests.h
+++ b/tests/tests.h
@@ -80,6 +80,8 @@ private slots:
void builtin_cd_data();
void builtin_cd();
void suffixes();
+ void macrosOnCommandLine_data();
+ void macrosOnCommandLine();
void nonexistentDependent();
void noTargets();
void outOfDateCheck();