summaryrefslogtreecommitdiff
path: root/test cases/common
diff options
context:
space:
mode:
authorXavier Claessens <xavier.claessens@collabora.com>2023-02-14 10:12:38 -0500
committerXavier Claessens <xclaesse@gmail.com>2023-03-01 20:13:34 -0500
commitf0dc61a76403d3ad26cbfa8e3922fa84343ba7d4 (patch)
tree7479c1af389b43a785c90a3a43e1574ff75d1205 /test cases/common
parenta952b01a0885da9cc89b637d78ee649aea437a95 (diff)
downloadmeson-f0dc61a76403d3ad26cbfa8e3922fa84343ba7d4.tar.gz
interpreter: Add testcase..endtestcase clause support
This is currently only enabled when running unit tests to facilitate writing failing unit tests. Fixes: #11394
Diffstat (limited to 'test cases/common')
-rw-r--r--test cases/common/261 testcase clause/meson.build37
-rw-r--r--test cases/common/261 testcase clause/test.json9
2 files changed, 46 insertions, 0 deletions
diff --git a/test cases/common/261 testcase clause/meson.build b/test cases/common/261 testcase clause/meson.build
new file mode 100644
index 000000000..834865f2c
--- /dev/null
+++ b/test cases/common/261 testcase clause/meson.build
@@ -0,0 +1,37 @@
+project('testcase clause')
+
+# To make sure unreachable code is not executed.
+unreachable = true
+
+# Verify assertion exception gets catched and dropped.
+testcase expect_error('Assert failed: false')
+ assert(false)
+ unreachable = false
+endtestcase
+assert(unreachable)
+
+# The inner testcase raises an exception because it did not receive the expected
+# error message. The outer testcase catches the inner testcase exception and
+# drop it.
+testcase expect_error('Expecting error \'something\' but got \'Assert failed: false\'')
+ testcase expect_error('something')
+ assert(false)
+ unreachable = false
+ endtestcase
+ unreachable = false
+endtestcase
+assert(unreachable)
+
+# The inner testcase raises an exception because it did not receive an
+# exception. The outer testcase catches the inner testcase exception and
+# drop it.
+testcase expect_error('Expecting an error but code block succeeded')
+ testcase expect_error('something')
+ reached = true
+ endtestcase
+ unreachable = false
+endtestcase
+assert(reached)
+assert(unreachable)
+
+message('all good')
diff --git a/test cases/common/261 testcase clause/test.json b/test cases/common/261 testcase clause/test.json
new file mode 100644
index 000000000..650ae9f00
--- /dev/null
+++ b/test cases/common/261 testcase clause/test.json
@@ -0,0 +1,9 @@
+{
+ "stdout": [
+ {
+ "line": ".*all good",
+ "match": "re",
+ "count": 1
+ }
+ ]
+}