From 694ba19499e584b659971618098754eeae19d42a Mon Sep 17 00:00:00 2001 From: Juri Leino Date: Mon, 26 Sep 2022 21:15:32 +0200 Subject: [PATCH] [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`. --- .../org/exist/xquery/lib/xqsuite/xqsuite.xql | 3 ++- .../src/test/xquery/xqsuite/custom-assertion.xqm | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/exist-core/src/main/resources/org/exist/xquery/lib/xqsuite/xqsuite.xql b/exist-core/src/main/resources/org/exist/xquery/lib/xqsuite/xqsuite.xql index 9dd1fe7bcb0..9d0d2716670 100755 --- a/exist-core/src/main/resources/org/exist/xquery/lib/xqsuite/xqsuite.xql +++ b/exist-core/src/main/resources/org/exist/xquery/lib/xqsuite/xqsuite.xql @@ -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"; (:~ @@ -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 diff --git a/exist-core/src/test/xquery/xqsuite/custom-assertion.xqm b/exist-core/src/test/xquery/xqsuite/custom-assertion.xqm index 3d5d2812417..990a574950c 100644 --- a/exist-core/src/test/xquery/xqsuite/custom-assertion.xqm +++ b/exist-core/src/test/xquery/xqsuite/custom-assertion.xqm @@ -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()* {