diff --git a/src/utils.xqy b/src/utils.xqy
index 5a1f356..e8e5260 100644
--- a/src/utils.xqy
+++ b/src/utils.xqy
@@ -6,7 +6,25 @@ declare namespace test = "http://github.com/robwhitby/xray/test";
import module namespace parser = "XQueryML10" at "parsers/XQueryML10.xq";
declare private variable $test-ns-uri := fn:namespace-uri-for-prefix("test", );
+
+declare function utils:get-modules(
+ $test-dir as xs:string,
+ $pattern as xs:string?
+) as xs:string*
+{
+ let $test-dir :=
+ if (xdmp:platform() eq "winnt")
+ then fn:replace($test-dir, "/", "\\")
+ else fn:replace($test-dir, "\\", "/")
+ let $fs-dir := fn:concat(xdmp:modules-root(), fn:replace($test-dir, "^[/\\]+", ""))
+ where utils:filesystem-directory-exists($fs-dir)
+ return
+ for $filepath in utils:get-filelist($fs-dir)
+ where fn:matches(utils:relative-path($filepath), fn:string($pattern))
+ return $filepath
+};
+
declare function utils:get-filelist(
$dir as xs:string
@@ -16,8 +34,8 @@ declare function utils:get-filelist(
order by $entry/dir:type descending, $entry/dir:filename ascending
return
if ($entry/dir:type = "file")
- then
- if (fn:matches($entry/dir:pathname, "\.xqy?$"))
+ then
+ if (fn:matches($entry/dir:pathname, "\.xqy?$"))
then $entry/dir:pathname/fn:string()
else ()
else utils:get-filelist($entry/dir:pathname/fn:string())
@@ -30,7 +48,7 @@ declare function utils:get-functions(
{
for $fn in utils:parse-xquery($module-path)//FunctionDecl
let $qname := xs:QName($fn/FunctionName/QName)
- let $qname :=
+ let $qname :=
if (fn:namespace-uri-from-QName($qname) eq "")
then fn:QName($test-ns-uri, fn:local-name-from-QName($qname))
else $qname
@@ -39,25 +57,11 @@ declare function utils:get-functions(
};
-declare function utils:get-modules(
- $test-dir as xs:string,
- $pattern as xs:string?
-) as xs:string*
-{
- let $fs-dir := fn:concat(xdmp:modules-root(), fn:replace($test-dir, "^/+", ""))
- where utils:filesystem-directory-exists($fs-dir)
- return
- for $filepath in utils:get-filelist($fs-dir)
- where fn:matches(utils:relative-path($filepath), $pattern)
- return $filepath
-};
-
-
declare function utils:relative-path(
$path as xs:string
) as xs:string
{
- fn:replace($path, xdmp:modules-root(), "/")
+ fn:substring($path, fn:string-length(xdmp:modules-root()))
};
@@ -90,7 +94,7 @@ declare function utils:transform(
};
-declare function utils:parse-xquery(
+declare private function utils:parse-xquery(
$module-path as xs:string
) as element(XQuery)?
{
diff --git a/src/xray.xqy b/src/xray.xqy
index 371f3fc..9df24b0 100644
--- a/src/xray.xqy
+++ b/src/xray.xqy
@@ -11,7 +11,7 @@ declare function xray:run-tests(
$module-pattern as xs:string?,
$test-pattern as xs:string?,
$format as xs:string?
-)
+) as item()*
{
let $modules := utils:get-modules($test-dir, fn:string($module-pattern))
let $tests :=
@@ -44,11 +44,7 @@ declare function xray:run-test(
) as element(test)
{
let $ignore := fn:starts-with(utils:get-local-name($fn), "IGNORE")
- let $test :=
- if ($ignore) then ()
- else
- try { xray:apply($fn) }
- catch($ex) { element exception { xray:error($ex)} }
+ let $test := if ($ignore) then () else xray:apply($fn)
return element test {
attribute name { utils:get-local-name($fn) },
attribute result {
@@ -71,26 +67,32 @@ declare function xray:test-response(
element assert {
attribute test { $assertion },
attribute result { if ($passed) then "passed" else "failed" },
- element xray:actual { $actual },
- element xray:expected { $expected }
+ element actual { $actual },
+ element expected { $expected }
}
};
-declare function xray:apply($function as xdmp:function)
+declare private function xray:apply(
+ $function as xdmp:function
+) as item()*
{
- xdmp:eval("
- declare variable $fn as xdmp:function external;
- declare option xdmp:update 'true';
- xdmp:apply($fn)",
- (fn:QName("","fn"), $function),
- different-transaction
- )
+ try {
+ xdmp:eval("
+ declare variable $fn as xdmp:function external;
+ declare option xdmp:update 'true';
+ xdmp:apply($fn)",
+ (fn:QName("","fn"), $function),
+ different-transaction
+ )
+ }
+ catch($ex) { element exception { xray:error($ex)} }
};
-declare function xray:error($ex as element(error:error))
-as element(error:error)
+declare private function xray:error(
+ $ex as element(error:error)
+) as element(error:error)
{
$ex
};