From 4bdc3a24df2c371ff2f3e7bc0486a004bb4f7575 Mon Sep 17 00:00:00 2001 From: Fred Atherden <43879983+fred-atherden@users.noreply.github.com> Date: Wed, 22 Nov 2023 16:45:56 +0000 Subject: [PATCH] better xspec failure messaging --- xquery/get-xspec-failures.xq | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/xquery/get-xspec-failures.xq b/xquery/get-xspec-failures.xq index 65566586d7..942de8eb97 100644 --- a/xquery/get-xspec-failures.xq +++ b/xquery/get-xspec-failures.xq @@ -1,11 +1,24 @@ declare namespace x="http://www.jenitennison.com/xslt/xspec"; +import module namespace schematron = "http://github.com/Schematron/schematron-basex"; +declare variable $sch := doc('../src/schematron.sch'); +declare variable $base := substring-before(base-uri($sch),'src'); -let $result := doc('../test/xspec/xspec/schematron-result.xml') +let $xspec-result := doc('../test/xspec/xspec/schematron-result.xml') -return distinct-values( - for $x in ( - $result//x:test[@successful="false"]/parent::x:scenario//x:context/substring-after(@href,'/tests/') - ) - order by lower-case($x) - return $x -) \ No newline at end of file +let $failures := distinct-values(for $x in $xspec-result//x:test[@successful="false"]/parent::x:scenario//x:context/substring-after(@href,'/tests/') + order by lower-case($x) + return $x) + +for $failure in $failures +let $filename := tokenize($failure,'/')[last()] +let $folder := $base||'/test/tests/'||substring-before($failure,$filename) +let $id := tokenize(replace($folder,'/$',''),'/')[last()] +let $xml := doc($folder||$filename) +let $sch := schematron:compile(doc($folder||$id||'.sch')) +let $svrl := schematron:validate($xml, $sch) +let $messages := schematron:messages($svrl) +return ($failure, + schematron:is-valid($svrl), + for $message in $messages + return concat(schematron:message-level($message), ': ', schematron:message-description($message)) + ) \ No newline at end of file