Skip to content

Commit ab27751

Browse files
committed
[enhancement] export error QName to allow fallback
Allow backwards compatible implementations of custom assertions for packages that target multiple version of eXist-db, including ones that do not yet have `test:fail`.
1 parent 7dd80c8 commit ab27751

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

exist-core/src/main/resources/org/exist/xquery/lib/xqsuite/xqsuite.xql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ declare variable $test:UNKNOWN_ASSERTION := QName($test:TEST_NAMESPACE, "no-such
5858
declare variable $test:WRONG_ARG_COUNT := QName($test:TEST_NAMESPACE, "wrong-number-of-arguments");
5959
declare variable $test:TYPE_ERROR := QName($test:TEST_NAMESPACE, "type-error");
6060
declare variable $test:UNKNOWN_ANNOTATION_VALUE_TYPE := QName($test:TEST_NAMESPACE, "unknown-annotation-value-type");
61+
declare variable $test:FAILURE := QName($test:TEST_NAMESPACE, "failure");
6162
declare variable $test:CUSTOM_ASSERTION_FAILURE_TYPE := "custom-assertion-failure";
6263

6364
(:~
@@ -150,7 +151,7 @@ declare function test:fail (
150151
$actual as item()*,
151152
$type as xs:string
152153
) as empty-sequence() {
153-
error(xs:QName("test:failure"), $message, map {
154+
error($test:FAILURE, $message, map {
154155
"expected": $expected,
155156
"actual": $actual,
156157
"type": $type

exist-core/src/test/xquery/xqsuite/custom-assertion.xqm

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,21 @@ function ca:test-fail-4() as item()* {
5353
}
5454
};
5555

56+
declare
57+
%test:assertEquals("Custom message", "expected", "actual", "custom-assertion-failure")
58+
function ca:test-fail-fallback() as item()* {
59+
try {
60+
error($test:FAILURE, "Custom message", map {
61+
"expected": "expected",
62+
"actual": "actual",
63+
"type": $test:CUSTOM_ASSERTION_FAILURE_TYPE
64+
})
65+
}
66+
catch test:failure {
67+
$err:description, $err:value?expected, $err:value?actual, $err:value?type
68+
}
69+
};
70+
5671
declare
5772
%test:assertTrue
5873
function ca:map-assertion-pass() as item()* {

0 commit comments

Comments
 (0)