aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@qt.io>2023-05-16 17:14:03 +0200
committerChristian Kandeler <christian.kandeler@qt.io>2023-05-17 08:49:05 +0000
commit610508fcbf95b16567a17f53fd370f9b0ae3505b (patch)
tree5812c8e4c691e808cb340cc55a92038abda35142 /tests
parent36887c42052e92eb8d0576e6d25699e0a49bc1f9 (diff)
Properly handle non-string exceptions
Fixes: QBS-1734 Change-Id: If7901dc698fdd5ee44021a3b92cf28295123eccc Reviewed-by: Ivan Komissarov <ABBAPOH@gmail.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/language/testdata/throw.qbs16
-rw-r--r--tests/auto/language/tst_language.cpp35
-rw-r--r--tests/auto/language/tst_language.h2
3 files changed, 53 insertions, 0 deletions
diff --git a/tests/auto/language/testdata/throw.qbs b/tests/auto/language/testdata/throw.qbs
new file mode 100644
index 000000000..e9a97efb5
--- /dev/null
+++ b/tests/auto/language/testdata/throw.qbs
@@ -0,0 +1,16 @@
+Project {
+ property string throwType
+ property bool dummy: {
+ if (throwType === "bool")
+ throw true;
+ if (throwType === "int")
+ throw 43;
+ if (throwType === "string")
+ throw "an error";
+ if (throwType === "list")
+ throw ["an", "error"];
+ if (throwType === "object")
+ throw { result: "crash", reason: "overheating" };
+ throw "type missing";
+ }
+}
diff --git a/tests/auto/language/tst_language.cpp b/tests/auto/language/tst_language.cpp
index 50269a7d7..9045442c9 100644
--- a/tests/auto/language/tst_language.cpp
+++ b/tests/auto/language/tst_language.cpp
@@ -65,6 +65,7 @@
#include <tools/settings.h>
#include <tools/stlutils.h>
+#include <QtCore/qjsonobject.h>
#include <QtCore/qprocess.h>
#include <algorithm>
@@ -371,6 +372,40 @@ void TestLanguage::rfc1034Identifier()
QCOMPARE(exceptionCaught, false);
}
+void TestLanguage::throwThings_data()
+{
+ QTest::addColumn<QString>("type");
+ QTest::addColumn<QString>("result");
+ QTest::addRow("bool") << "bool" << "true";
+ QTest::addRow("int") << "int" << "43";
+ QTest::addRow("string") << "string" << "an error";
+ QTest::addRow("list") << "list" << R"([
+ "an",
+ "error"
+])";
+ QTest::addRow("object") << "object" << R"({
+ "reason": "overheating",
+ "result": "crash"
+})";
+}
+
+void TestLanguage::throwThings()
+{
+ QFETCH(QString, type);
+ QFETCH(QString, result);
+ bool exceptionCaught = false;
+ try {
+ SetupProjectParameters params = defaultParameters;
+ params.setProjectFilePath(testProject("throw.qbs"));
+ params.setOverriddenValues({{"project.throwType", type}});
+ loader->loadProject(params);
+ } catch (const ErrorInfo &e) {
+ exceptionCaught = true;
+ QVERIFY2(e.toString().contains(result), qPrintable(e.toString()));
+ }
+ QVERIFY(exceptionCaught);
+}
+
void TestLanguage::conditionalDepends()
{
bool exceptionCaught = false;
diff --git a/tests/auto/language/tst_language.h b/tests/auto/language/tst_language.h
index 4fe2752e4..e72259a0f 100644
--- a/tests/auto/language/tst_language.h
+++ b/tests/auto/language/tst_language.h
@@ -177,6 +177,8 @@ private slots:
void qualifiedId();
void recursiveProductDependencies();
void rfc1034Identifier();
+ void throwThings_data();
+ void throwThings();
void useInternalProfile();
void versionCompare();
void wildcards_data();