@@ -14,8 +14,10 @@ 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-
1817declare variable $TEST-SUITES-ROOT := "/test/suites/" ;
18+ declare variable $db-id as xs:unsignedLong := xdmp:modules-database ();
19+ declare variable $root as xs:string := xdmp:modules-root ();
20+
1921
2022(:
2123 : Returns a list of the available tests. This list is magically computed based on the modules
@@ -29,45 +31,89 @@ declare function list()
2931 )
3032 return
3133 element t:tests {
32- let $db-id as xs:unsignedLong := xdmp:modules-database ()
33- let $root as xs:string := xdmp:modules-root ()
3434 let $suites as xs:string* :=
3535 if ($db-id = 0 ) then
3636 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
3737 else
38- let $uris := helper:list-from-database ($db-id, $root, ())
38+ let $uris := helper:list-from-database ($db-id, $root, (), 'suites' )
3939 return
4040 fn:distinct-values (
4141 for $uri in $uris
4242 let $path := fn:replace (cvt:basepath ($uri), fn:concat ($root, "test/suites/?" ), "" )
4343 where $path ne "" and fn:not (fn:contains ($path, "/" )) and fn:not ($path = $suite-ignore-list)
4444 return
4545 $path)
46- for $suite as xs:string in $suites
47- let $tests as xs:string* :=
46+ let $main-formats as xs:string* :=
4847 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 " )]
48+ 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:ends-with (., ".xsl " )]
5049 else
51- let $uris := helper:list-from-database ($db-id, $root, fn:concat ($suite , '/' ) )
50+ let $uris := helper:list-from-database ($db-id, $root, () , 'formats' )
5251 return
5352 fn:distinct-values (
5453 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 " ))
54+ let $path := fn:replace ($uri, fn:concat ($root, "test/formats /" ), "" )
55+ where $path ne "" and fn:not (fn:contains ($path, "/" )) and fn:not ($path = $test-ignore-list) and (fn:ends-with ($path, ".xsl " ))
5756 return
5857 $path)
59- where $tests
60- return
61- element t:suite {
62- attribute path {$suite},
63- element t:tests {
64- for $test in $tests
58+ return (
59+ for $suite as xs:string in $suites
60+ let $tests as xs:string* :=
61+ if ($db-id = 0 ) then
62+ 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" )]
63+ else
64+ let $uris := helper:list-from-database (
65+ $db-id, $root, fn:concat ($suite, '/' ), 'suites' )
66+ return
67+ fn:distinct-values (
68+ for $uri in $uris
69+ let $path := fn:replace ($uri, fn:concat ($root, "test/suites/" , $suite, "/" ), "" )
70+ 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" ))
71+ return
72+ $path)
73+ let $formats as xs:string* :=
74+ if ($db-id = 0 ) then
75+ xdmp:filesystem-directory (fn:concat ($root, $FS-PATH, "test/suites/" , $suite, "/formats" ))/dir:entry[dir:type = "file" and fn:not (dir:filename = $test-ignore-list)]/dir:filename[fn:ends-with (., ".xsl" )]
76+ else
77+ let $uris := helper:list-from-database (
78+ $db-id, $root, fn:concat ($suite, '/formats/' ), 'suites' )
79+ return
80+ fn:distinct-values (
81+ for $uri in $uris
82+ let $path := fn:replace ($uri, fn:concat ($root, "test/suites/" , $suite, "/formats/" ), "" )
83+ where $path ne "" and fn:not (fn:contains ($path, "/" )) and fn:not ($path = $test-ignore-list) and (fn:ends-with ($path, ".xsl" ))
84+ return
85+ $path)
86+ where $tests
87+ return
88+ element t:suite {
89+ attribute path {$suite},
90+ element t:tests {
91+ for $test in $tests
92+ return
93+ element t:test {
94+ attribute path {$test}
95+ }
96+ },
97+ if ($formats) then
98+ element t:formats {
99+ for $format in $formats
100+ return
101+ element t:format {
102+ attribute path {$format}
103+ }
104+ }
105+ else ()
106+ },
107+ if ($main-formats) then
108+ element t:formats {
109+ for $main-format in $main-formats
65110 return
66- element t:test {
67- attribute path {$test }
111+ element t:format {
112+ attribute path {$main-format }
68113 }
69114 }
70- }
115+ else ()
116+ )
71117 }
72118};
73119
@@ -98,7 +144,7 @@ declare function run-suite(
98144 $run-suite-teardown as xs:boolean,
99145 $run-teardown as xs:boolean)
100146{
101- run-suite ($suite, $tests, $run-suite-teardown, $run-teardown, fn:false ())
147+ run-suite ($suite, $tests, $run-suite-teardown, $run-teardown, fn:false ())
102148};
103149
104150(:~
@@ -205,6 +251,29 @@ declare function run(
205251};
206252
207253
254+ declare function format ($result as element (), $format as xs:string, $suite as xs:string)
255+ {
256+ if ($format eq "junit" ) then
257+ format-junit ($suite)
258+ else
259+ let $format-uris := helper:list-from-database ($db-id, $root, (), 'formats' )
260+ let $suite-format-uris := helper:list-from-database ($db-id, $root, $suite || '/formats/' , 'suites' )
261+ let $xsl-match :=
262+ for $uri in ($format-uris, $suite-format-uris)
263+ return
264+ if (fn:matches (fn:tokenize ($uri, '/' )[fn:last ()], '^' || $format || '(\.xsl)?$' )) then $uri
265+ else ()
266+ return
267+ if ($xsl-match) then
268+ let $xsl := $xsl-match[1 ]
269+ let $params := map:map ()
270+ let $_ := map:put ($params, "hostname" , fn:tokenize (xdmp:get-request-header ("Host" ), ":" )[1 ])
271+ let $_ := map:put ($params, "timestamp" , fn:current-dateTime ())
272+ return xdmp:xslt-invoke ($xsl, $result, $params)/element ()
273+ else $result
274+ };
275+
276+
208277declare function format-junit ($suite as element ())
209278{
210279 element testsuite {
0 commit comments