@@ -14,8 +14,11 @@ import module namespace helper = "http://marklogic.com/roxy/test-helper" at "/te
1414declare namespace t="http://marklogic.com/roxy/test" ;
1515
1616declare variable $FS-PATH as xs:string := if (xdmp:platform () eq "winnt" ) then "\" else "/" ;
17-
17+ declare variable $XSL-PATTERN as xs:string := "\.xslt?$" ;
1818declare variable $TEST-SUITES-ROOT := "/test/suites/" ;
19+ declare variable $db-id as xs:unsignedLong := xdmp:modules-database ();
20+ declare variable $root as xs:string := xdmp:modules-root ();
21+
1922
2023(:
2124 : Returns a list of the available tests. This list is magically computed based on the modules
@@ -29,45 +32,67 @@ declare function list()
2932 )
3033 return
3134 element t:tests {
32- let $db-id as xs:unsignedLong := xdmp:modules-database ()
33- let $root as xs:string := xdmp:modules-root ()
3435 let $suites as xs:string* :=
3536 if ($db-id = 0 ) then
3637 xdmp:filesystem-directory (fn:concat ($root, $FS-PATH, "test/suites" ))/dir:entry[dir:type = "directory" and fn:not (dir:filename = $suite-ignore-list)]/dir:filename
3738 else
38- let $uris := helper:list-from-database ($db-id, $root, ())
39+ let $uris := helper:list-from-database ($db-id, $root, (), 'suites' )
3940 return
4041 fn:distinct-values (
4142 for $uri in $uris
4243 let $path := fn:replace (cvt:basepath ($uri), fn:concat ($root, "test/suites/?" ), "" )
4344 where $path ne "" and fn:not (fn:contains ($path, "/" )) and fn:not ($path = $suite-ignore-list)
4445 return
4546 $path)
46- for $suite as xs:string in $suites
47- let $tests as xs:string* :=
47+ let $main-formats as xs:string* :=
4848 if ($db-id = 0 ) then
49- xdmp:filesystem-directory (fn:concat ($root, $FS-PATH, "test/suites/" , $suite ))/dir:entry[dir:type = "file" and fn:not (dir:filename = $test-ignore-list)]/dir:filename[fn:ends-with (., ".xqy" ) or fn:ends-with (., ".sjs" )]
49+ xdmp:filesystem-directory (fn:concat ($root, $FS-PATH, "test/formats" ))/dir:entry[dir:type = "file" and fn:not (dir:filename = $test-ignore-list)]/dir:filename[fn:matches (., $XSL-PATTERN )]
5050 else
51- let $uris := helper:list-from-database ($db-id, $root, fn:concat ($suite , '/' ) )
51+ let $uris := helper:list-from-database ($db-id, $root, () , 'formats' )
5252 return
5353 fn:distinct-values (
5454 for $uri in $uris
55- let $path := fn:replace ($uri, fn:concat ($root, "test/suites/" , $suite, " /" ), "" )
56- where $path ne "" and fn:not (fn:contains ($path, "/" )) and fn:not ($path = $test-ignore-list) and (fn:ends-with ($path, ".xqy" ) or fn:ends-with ($path, ".sjs" ))
55+ let $path := fn:replace ($uri, fn:concat ($root, "test/formats /" ), "" )
56+ where $path ne "" and fn:not (fn:contains ($path, "/" )) and fn:not ($path = $test-ignore-list) and (fn:matches ($path, $XSL-PATTERN ))
5757 return
5858 $path)
59- where $tests
60- return
61- element t:suite {
62- attribute path {$suite},
63- element t:tests {
64- for $test in $tests
59+ return (
60+ for $suite as xs:string in $suites
61+ let $tests as xs:string* :=
62+ if ($db-id = 0 ) then
63+ xdmp:filesystem-directory (fn:concat ($root, $FS-PATH, "test/suites/" , $suite))/dir:entry[dir:type = "file" and fn:not (dir:filename = $test-ignore-list)]/dir:filename[fn:ends-with (., ".xqy" ) or fn:ends-with (., ".sjs" )]
64+ else
65+ let $uris := helper:list-from-database (
66+ $db-id, $root, fn:concat ($suite, '/' ), 'suites' )
67+ return
68+ fn:distinct-values (
69+ for $uri in $uris
70+ let $path := fn:replace ($uri, fn:concat ($root, "test/suites/" , $suite, "/" ), "" )
71+ where $path ne "" and fn:not (fn:contains ($path, "/" )) and fn:not ($path = $test-ignore-list) and (fn:ends-with ($path, ".xqy" ) or fn:ends-with ($path, ".sjs" ))
72+ return
73+ $path)
74+ where $tests
75+ return
76+ element t:suite {
77+ attribute path {$suite},
78+ element t:tests {
79+ for $test in $tests
80+ return
81+ element t:test {
82+ attribute path {$test}
83+ }
84+ }
85+ },
86+ if ($main-formats) then
87+ element t:formats {
88+ for $main-format in $main-formats
6589 return
66- element t:test {
67- attribute path {$test }
90+ element t:format {
91+ attribute path {$main-format }
6892 }
6993 }
70- }
94+ else ()
95+ )
7196 }
7297};
7398
@@ -98,7 +123,7 @@ declare function run-suite(
98123 $run-suite-teardown as xs:boolean,
99124 $run-teardown as xs:boolean)
100125{
101- run-suite ($suite, $tests, $run-suite-teardown, $run-teardown, fn:false ())
126+ run-suite ($suite, $tests, $run-suite-teardown, $run-teardown, fn:false ())
102127};
103128
104129(:~
@@ -205,6 +230,32 @@ declare function run(
205230};
206231
207232
233+ declare function format ($result as element (), $format as xs:string, $suite as xs:string)
234+ {
235+ if ($format eq "junit" ) then
236+ format-junit ($suite)
237+ else
238+ let $format-uris :=
239+ if ($db-id = 0 ) then
240+ xdmp:filesystem-directory (fn:concat ($root, $FS-PATH, "test/formats" ))/dir:entry[dir:type = "file" ]/dir:filename[fn:matches (., $XSL-PATTERN)]
241+ else
242+ helper:list-from-database ($db-id, $root, (), 'formats' )
243+ let $xsl-match :=
244+ for $uri in $format-uris
245+ return
246+ if (fn:matches (fn:tokenize ($uri, '/' )[fn:last ()], '^' || $format || $XSL-PATTERN)) then $uri
247+ else ()
248+ return
249+ if ($xsl-match) then
250+ let $xsl := $xsl-match[1 ]
251+ let $params := map:map ()
252+ let $_ := map:put ($params, "hostname" , fn:tokenize (xdmp:get-request-header ("Host" ), ":" )[1 ])
253+ let $_ := map:put ($params, "timestamp" , fn:current-dateTime ())
254+ return xdmp:xslt-invoke ($xsl, $result, $params)/element ()
255+ else $result
256+ };
257+
258+
208259declare function format-junit ($suite as element ())
209260{
210261 element testsuite {
0 commit comments