diff --git a/context.xqm b/context.xqm index 108f836..dcd1f3c 100644 --- a/context.xqm +++ b/context.xqm @@ -48,17 +48,19 @@ as map(*) return map:merge( - ($options, - map{ - 'phase' : $active-phase, - 'patterns' : $active-patterns, - 'ns-decls' : $namespaces, - 'globals' : $globals, - 'instance' : $instance, - 'diagnostics' : $schema/sch:diagnostics/sch:diagnostic, - 'properties' : $schema/sch:properties/sch:property, - 'functions' : $schema/xqy:function - }) + ( + $options, + map{ + 'phase' : $active-phase, + 'patterns' : $active-patterns, + 'ns-decls' : $namespaces, + 'globals' : $globals, + 'instance' : $instance, + 'diagnostics' : $schema/sch:diagnostics/sch:diagnostic, + 'properties' : $schema/sch:properties/sch:property, + 'functions' : $schema/xqy:function + } + ) ) }; @@ -251,6 +253,7 @@ as map(*) : @param query the query to evaluate : @param ns-elems namespace declarations : @param bindings map of global variable bindings + : @param options map of options :) declare function c:evaluate-global-variable( $variable as element(sch:let), @@ -267,7 +270,8 @@ as map(*) then utils:eval( $query => utils:escape(), map:merge(($bindings, map{'':$instance})), - map:merge($options, map{'pass':'true'}) + map:merge($options, map{'pass':'true'}), + $variable/@value ) else $variable/* let $bindings := map:merge( @@ -302,7 +306,8 @@ as map(*) let $uris := utils:eval( utils:make-query-prolog($context) || $documents => utils:escape(), map:merge(($context?globals, map{'':$context?instance})), - map{'pass':'true'} (:report exception details:) + map{'pass':'true'}, (:report exception details:) + $documents ) return map:put( $context, diff --git a/evaluate.xqm b/evaluate.xqm index 888b548..4362234 100644 --- a/evaluate.xqm +++ b/evaluate.xqm @@ -35,7 +35,9 @@ declare function eval:schema( {output:namespace-decls-as-svrl($schema/sch:ns)} {for $phase in ($schema/sch:phase/@id/data(), '') let $context as map(*) := context:get-context($instance, $schema, $phase, $options) - return eval:phase($context)} + return + ($context?globals?*[self::svrl:*[@err:*]], + eval:phase($context))} else eval:schema($instance, $schema, $phase) @@ -153,7 +155,8 @@ as element()* let $rule-context := utils:eval( $query => utils:escape(), map:merge((map{'':$context?instance}, $context?globals)), - map{'pass':'true', 'dry-run':$context?dry-run} + map{'pass':'true', 'dry-run':$context?dry-run}, + $rule/@context ) return if($rule-context) @@ -212,7 +215,8 @@ declare function eval:assertion( let $result := utils:eval( $prolog || $assertion/@test => utils:escape(), map:merge((map{'':$rule-context}, $context?globals)), - map{'pass':'true', 'dry-run':$context?dry-run} + map{'pass':'true', 'dry-run':$context?dry-run}, + $assertion/@test ) return typeswitch($assertion) diff --git a/svrl.xqm b/svrl.xqm index 335960f..7cb089c 100644 --- a/svrl.xqm +++ b/svrl.xqm @@ -119,14 +119,16 @@ declare function output:assertion-message-content( then utils:eval( $prolog || $node/@path, map:merge((map{'':$rule-context}, $context?globals)), - map{'pass':'true'} + map{'pass':'true'}, + $node/@path ) else name($rule-context) case element(sch:value-of) return utils:eval( $prolog || $node/@select, map:merge((map{'':$rule-context}, $context?globals)), - map{'pass':'true'} + map{'pass':'true'}, + $node/@select ) => string() case element(sch:emph) diff --git a/test/test-compile.xqm b/test/test-compile.xqm index af513b5..bf5e8b4 100644 --- a/test/test-compile.xqm +++ b/test/test-compile.xqm @@ -1328,6 +1328,7 @@ declare %unit:test function _:global-variable-bindings() document{}, '', (), + map{}, map{} ) return ( diff --git a/test/test-context.xqm b/test/test-context.xqm index 3f204d4..5a5c094 100644 --- a/test/test-context.xqm +++ b/test/test-context.xqm @@ -271,7 +271,8 @@ declare %unit:test function _:get-context-patterns() let $patterns := c:get-context( , $schema, - 'phase1' + 'phase1', + map{} )?patterns return unit:assert-equals( @@ -296,7 +297,8 @@ declare %unit:test function _:get-context-active-phase() let $phase := c:get-context( , $schema, - 'phase1' + 'phase1', + map{} )?phase return unit:assert-equals( @@ -322,7 +324,8 @@ declare %unit:test function _:get-context-namespaces() let $ns-decls := c:get-context( , $schema, - '' + '', + map{} )?ns-decls return unit:assert-equals( @@ -350,7 +353,8 @@ declare %unit:test function _:get-context-globals() let $globals := c:get-context( , $schema, - 'phase1' + 'phase1', + map{} )?globals return unit:assert-equals( diff --git a/test/test-evaluate.xqm b/test/test-evaluate.xqm index 631111d..e944aa3 100644 --- a/test/test-evaluate.xqm +++ b/test/test-evaluate.xqm @@ -1299,4 +1299,28 @@ declare %unit:test function _:map-rule-variable() unit:assert(empty($result/svrl:failed-assert)), unit:assert(empty($result/svrl:successful-report)) ) +}; + +declare %unit:test function _:global-variable-syntax-error() +{ + let $result := eval:schema( + document{}, + doc('global-variable-syntax-error.sch')/*, + '', + map{'dry-run':'true'} + ) + return ( + unit:assert-equals( + $result/svrl:failed-assert/@location/data(), + "/Q{http://purl.oclc.org/dsdl/schematron}schema[1]/Q{http://purl.oclc.org/dsdl/schematron}let[1]/@value" + ), + unit:assert-equals( + $result/svrl:failed-assert/@err:code/data(), + "err:XPST0003" + ), + unit:assert-equals( + $result/svrl:failed-assert/svrl:text, + No specifier after lookup operator: ';'. + ) + ) }; \ No newline at end of file diff --git a/utils.xqm b/utils.xqm index e17486a..3884637 100644 --- a/utils.xqm +++ b/utils.xqm @@ -125,14 +125,28 @@ declare function utils:check-duplicate-variable-names($decls as element(sch:let) ) else() }; -(:~ Wrapper around xquery:eval() :) +(:~ Wrapper around xquery:eval() + : @param $query string of the query to evaluate + : @param bindings map of bindings + : @param options map of options + : @param node the schema node being evaluated + :) declare function utils:eval( $query as xs:string, $bindings as map(*), - $options as map(*) + $options as map(*), + $node as node() ) as item()* { if($options?dry-run eq 'true') - then () + then + try{ + xquery:parse($query, map{'pass':'true'}) + } + catch * { + + {$err:description} + } else xquery:eval($query, $bindings, map{'pass':'true'}) }; \ No newline at end of file