Skip to content

Commit

Permalink
Fix for paths on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
robwhitby committed Feb 18, 2012
1 parent 63d1ffd commit da77128
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 37 deletions.
42 changes: 23 additions & 19 deletions src/utils.xqy
Expand Up @@ -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", <test:x/>);


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
Expand All @@ -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())
Expand All @@ -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
Expand All @@ -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()))
};


Expand Down Expand Up @@ -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)?
{
Expand Down
38 changes: 20 additions & 18 deletions src/xray.xqy
Expand Up @@ -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 :=
Expand Down Expand Up @@ -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 {
Expand All @@ -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),
<options xmlns="xdmp:eval"><isolation>different-transaction</isolation></options>
)
try {
xdmp:eval("
declare variable $fn as xdmp:function external;
declare option xdmp:update 'true';
xdmp:apply($fn)",
(fn:QName("","fn"), $function),
<options xmlns="xdmp:eval"><isolation>different-transaction</isolation></options>
)
}
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
};

0 comments on commit da77128

Please sign in to comment.