Skip to content

Commit

Permalink
[enhancement] export error QName to allow fallback
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
line-o committed Jun 21, 2023
1 parent 7dd80c8 commit ab27751
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ declare variable $test:UNKNOWN_ASSERTION := QName($test:TEST_NAMESPACE, "no-such
declare variable $test:WRONG_ARG_COUNT := QName($test:TEST_NAMESPACE, "wrong-number-of-arguments");
declare variable $test:TYPE_ERROR := QName($test:TEST_NAMESPACE, "type-error");
declare variable $test:UNKNOWN_ANNOTATION_VALUE_TYPE := QName($test:TEST_NAMESPACE, "unknown-annotation-value-type");
declare variable $test:FAILURE := QName($test:TEST_NAMESPACE, "failure");
declare variable $test:CUSTOM_ASSERTION_FAILURE_TYPE := "custom-assertion-failure";

(:~
Expand Down Expand Up @@ -150,7 +151,7 @@ declare function test:fail (
$actual as item()*,
$type as xs:string
) as empty-sequence() {
error(xs:QName("test:failure"), $message, map {
error($test:FAILURE, $message, map {
"expected": $expected,
"actual": $actual,
"type": $type
Expand Down
15 changes: 15 additions & 0 deletions exist-core/src/test/xquery/xqsuite/custom-assertion.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,21 @@ function ca:test-fail-4() as item()* {
}
};

declare
%test:assertEquals("Custom message", "expected", "actual", "custom-assertion-failure")
function ca:test-fail-fallback() as item()* {
try {
error($test:FAILURE, "Custom message", map {
"expected": "expected",
"actual": "actual",
"type": $test:CUSTOM_ASSERTION_FAILURE_TYPE
})
}
catch test:failure {
$err:description, $err:value?expected, $err:value?actual, $err:value?type
}
};

declare
%test:assertTrue
function ca:map-assertion-pass() as item()* {
Expand Down

0 comments on commit ab27751

Please sign in to comment.