From 472420216ea3cb10c7042c46a77b082fb904c91c Mon Sep 17 00:00:00 2001 From: James Gardner Date: Thu, 3 Jan 2019 16:11:25 -0500 Subject: [PATCH 01/22] Consolidating filesystem reads Removing lots of code that sat alongside list-from-database() calls that was doing filesystem reads. Updated list-from-database() so that it detects and reads from the filesystem whenever the database-id is 0. This removed the duplication of logic used to detect tests, suites, and custom formats. --- .../ml-modules/root/test/test-controller.xqy | 66 ++++++++----------- .../main/ml-modules/root/test/test-helper.xqy | 39 ++++++++--- 2 files changed, 55 insertions(+), 50 deletions(-) diff --git a/marklogic-unit-test-modules/src/main/ml-modules/root/test/test-controller.xqy b/marklogic-unit-test-modules/src/main/ml-modules/root/test/test-controller.xqy index c35d90d..021ed4e 100644 --- a/marklogic-unit-test-modules/src/main/ml-modules/root/test/test-controller.xqy +++ b/marklogic-unit-test-modules/src/main/ml-modules/root/test/test-controller.xqy @@ -13,7 +13,6 @@ import module namespace helper = "http://marklogic.com/roxy/test-helper" at "/te declare namespace t="http://marklogic.com/roxy/test"; -declare variable $FS-PATH as xs:string := if (xdmp:platform() eq "winnt") then "\" else "/"; declare variable $XSL-PATTERN as xs:string := "\.xslt?$"; declare variable $TEST-SUITES-ROOT := "/test/suites/"; declare variable $db-id as xs:unsignedLong := xdmp:modules-database(); @@ -33,44 +32,35 @@ declare function list() return element t:tests { let $suites as xs:string* := - if ($db-id = 0) then - 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 - else - let $uris := helper:list-from-database($db-id, $root, (), 'suites') - return - fn:distinct-values( - for $uri in $uris - let $path := fn:replace(cvt:basepath($uri), fn:concat($root, "test/suites/?"), "") - where $path ne "" and fn:not(fn:contains($path, "/")) and fn:not($path = $suite-ignore-list) - return - $path) + let $uris := helper:list-from-database($db-id, $root, (), 'suites') + return + fn:distinct-values( + for $uri in $uris + let $path := fn:replace(cvt:basepath($uri), fn:concat($root, "test/suites/?"), "") + where $path ne "" and fn:not(fn:contains($path, "/")) and fn:not($path = $suite-ignore-list) + return + $path) let $main-formats as xs:string* := - if ($db-id = 0) then - 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)] - else - let $uris := helper:list-from-database($db-id, $root, (), 'formats') - return - fn:distinct-values( - for $uri in $uris - let $path := fn:replace($uri, fn:concat($root, "test/formats/"), "") - where $path ne "" and fn:not(fn:contains($path, "/")) and fn:not($path = $test-ignore-list) and (fn:matches($path, $XSL-PATTERN)) - return - $path) + let $uris := helper:list-from-database($db-id, $root, (), 'formats') + return + fn:distinct-values( + for $uri in $uris + let $path := fn:replace($uri, fn:concat($root, "test/formats/"), "") + where $path ne "" and fn:not(fn:contains($path, "/")) and fn:not($path = $test-ignore-list) and (fn:matches($path, $XSL-PATTERN)) + return + $path) return ( for $suite as xs:string in $suites let $tests as xs:string* := - if ($db-id = 0) then - 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")] - else - let $uris := helper:list-from-database( - $db-id, $root, fn:concat($suite, '/'), 'suites') - return - fn:distinct-values( - for $uri in $uris - let $path := fn:replace($uri, fn:concat($root, "test/suites/", $suite, "/"), "") - 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")) - return - $path) + let $uris := helper:list-from-database( + $db-id, $root, fn:concat($suite, '/'), 'suites') + return + fn:distinct-values( + for $uri in $uris + let $path := fn:replace($uri, fn:concat($root, "test/suites/", $suite, "/"), "") + 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")) + return + $path) where $tests return element t:suite { @@ -240,11 +230,7 @@ declare function format($result as element(), $format as xs:string, $suite-name if ($format eq "junit") then format-junit($result) else - let $format-uris := - if ($db-id = 0) then - xdmp:filesystem-directory(fn:concat($root, $FS-PATH, "test/formats"))/dir:entry[dir:type = "file"]/dir:filename[fn:matches(., $XSL-PATTERN)] - else - helper:list-from-database($db-id, $root, (), 'formats') + let $format-uris := helper:list-from-database($db-id, $root, (), 'formats') let $xsl-match := for $uri in $format-uris return diff --git a/marklogic-unit-test-modules/src/main/ml-modules/root/test/test-helper.xqy b/marklogic-unit-test-modules/src/main/ml-modules/root/test/test-helper.xqy index a04aed3..e0e8270 100644 --- a/marklogic-unit-test-modules/src/main/ml-modules/root/test/test-helper.xqy +++ b/marklogic-unit-test-modules/src/main/ml-modules/root/test/test-helper.xqy @@ -26,6 +26,8 @@ declare namespace xdmp-http="xdmp:http"; declare option xdmp:mapping "false"; +declare variable $helper:DIRECTORY-SEPARATOR as xs:string := if (xdmp:platform() eq "winnt") then "\" else "/"; + declare variable $helper:PREVIOUS_LINE_FILE as xs:string := try { fn:error(xs:QName("boom"), "") @@ -668,16 +670,33 @@ declare function helper:list-from-database( $file-type as xs:string) as xs:string* { - xdmp:eval( - 'xquery version "1.0-ml"; - declare variable $PATH as xs:string external; - try { cts:uris((), (), cts:directory-query($PATH, "infinity")) } - catch ($ex) { - if ($ex/error:code ne "XDMP-URILXCNNOTFOUND") then xdmp:rethrow() - else xdmp:directory($PATH, "infinity")/xdmp:node-uri(.) }', - (xs:QName('PATH'), - fn:concat($root, 'test/', $file-type, '/', ($suite, '')[1])), - {$database}) + if ($database = 0) then + helper:list-from-filesystem(fn:string-join(($root, "test", $file-type, $suite), $helper:DIRECTORY-SEPARATOR)) + else + xdmp:eval( + 'xquery version "1.0-ml"; + declare variable $PATH as xs:string external; + try { cts:uris((), (), cts:directory-query($PATH, "infinity")) } + catch ($ex) { + if ($ex/error:code ne "XDMP-URILXCNNOTFOUND") then xdmp:rethrow() + else xdmp:directory($PATH, "infinity")/xdmp:node-uri(.) }', + (xs:QName('PATH'), + fn:concat($root, 'test/', $file-type, '/', ($suite, '')[1])), + {$database}) +}; + +declare function helper:list-from-filesystem($path as xs:string) +as xs:string* +{ + let $path := fn:replace($path, "(/|\\)", $helper:DIRECTORY-SEPARATOR) + for $entry in xdmp:filesystem-directory($path)/dir:entry + return + if ($entry/dir:type = "directory") then + helper:list-from-filesystem($entry/dir:pathname) + else if ($entry/dir:type = "file") then + $entry/dir:pathname + else + () }; (: From 0213af9d2ebb96626d38e9537c36f5f6ed1aaa13 Mon Sep 17 00:00:00 2001 From: James Gardner Date: Thu, 3 Jan 2019 16:57:24 -0500 Subject: [PATCH 02/22] Simplify list-from-database function and reducing arguments Removed arguments that were ultimately combined together to form a complete path. Ultimately this moves the logic out of this helper method and into the parent method where the logic belongs. Also added a few niceties: 1) Now replace the directory separator based on file system in one place instead of having to do it multiple times 2) Now add trailing '/' when the path didn't have one. --- .../ml-modules/root/test/test-controller.xqy | 9 +++-- .../main/ml-modules/root/test/test-helper.xqy | 36 +++++++++---------- 2 files changed, 21 insertions(+), 24 deletions(-) diff --git a/marklogic-unit-test-modules/src/main/ml-modules/root/test/test-controller.xqy b/marklogic-unit-test-modules/src/main/ml-modules/root/test/test-controller.xqy index 021ed4e..e4b86cc 100644 --- a/marklogic-unit-test-modules/src/main/ml-modules/root/test/test-controller.xqy +++ b/marklogic-unit-test-modules/src/main/ml-modules/root/test/test-controller.xqy @@ -32,7 +32,7 @@ declare function list() return element t:tests { let $suites as xs:string* := - let $uris := helper:list-from-database($db-id, $root, (), 'suites') + let $uris := helper:list-from-database($db-id, $root || "test/suites/") return fn:distinct-values( for $uri in $uris @@ -41,7 +41,7 @@ declare function list() return $path) let $main-formats as xs:string* := - let $uris := helper:list-from-database($db-id, $root, (), 'formats') + let $uris := helper:list-from-database($db-id, $root || "test/formats/") return fn:distinct-values( for $uri in $uris @@ -52,8 +52,7 @@ declare function list() return ( for $suite as xs:string in $suites let $tests as xs:string* := - let $uris := helper:list-from-database( - $db-id, $root, fn:concat($suite, '/'), 'suites') + let $uris := helper:list-from-database($db-id, $root || "test/suites/" || $suite) return fn:distinct-values( for $uri in $uris @@ -230,7 +229,7 @@ declare function format($result as element(), $format as xs:string, $suite-name if ($format eq "junit") then format-junit($result) else - let $format-uris := helper:list-from-database($db-id, $root, (), 'formats') + let $format-uris := helper:list-from-database($db-id, $root || "test/formats/") let $xsl-match := for $uri in $format-uris return diff --git a/marklogic-unit-test-modules/src/main/ml-modules/root/test/test-helper.xqy b/marklogic-unit-test-modules/src/main/ml-modules/root/test/test-helper.xqy index e0e8270..ec6effb 100644 --- a/marklogic-unit-test-modules/src/main/ml-modules/root/test/test-helper.xqy +++ b/marklogic-unit-test-modules/src/main/ml-modules/root/test/test-helper.xqy @@ -26,8 +26,6 @@ declare namespace xdmp-http="xdmp:http"; declare option xdmp:mapping "false"; -declare variable $helper:DIRECTORY-SEPARATOR as xs:string := if (xdmp:platform() eq "winnt") then "\" else "/"; - declare variable $helper:PREVIOUS_LINE_FILE as xs:string := try { fn:error(xs:QName("boom"), "") @@ -665,30 +663,30 @@ declare function helper:log($items as item()*) declare function helper:list-from-database( $database as xs:unsignedLong, - $root as xs:string, - $suite as xs:string?, - $file-type as xs:string) + $path as xs:string) as xs:string* { - if ($database = 0) then - helper:list-from-filesystem(fn:string-join(($root, "test", $file-type, $suite), $helper:DIRECTORY-SEPARATOR)) - else - xdmp:eval( - 'xquery version "1.0-ml"; - declare variable $PATH as xs:string external; - try { cts:uris((), (), cts:directory-query($PATH, "infinity")) } - catch ($ex) { - if ($ex/error:code ne "XDMP-URILXCNNOTFOUND") then xdmp:rethrow() - else xdmp:directory($PATH, "infinity")/xdmp:node-uri(.) }', - (xs:QName('PATH'), - fn:concat($root, 'test/', $file-type, '/', ($suite, '')[1])), - {$database}) + (: Add trailing '/' if missing :) + let $path := fn:replace($path, "([^/])$", "$1/") + return + if ($database = 0) then + let $directory-separator := if (xdmp:platform() eq "winnt") then "\\" else "/" + return helper:list-from-filesystem(fn:replace($path, "(/|\\)", $directory-separator)) + else + xdmp:eval( + 'xquery version "1.0-ml"; + declare variable $PATH as xs:string external; + try { cts:uris((), (), cts:directory-query($PATH, "infinity")) } + catch ($ex) { + if ($ex/error:code ne "XDMP-URILXCNNOTFOUND") then xdmp:rethrow() + else xdmp:directory($PATH, "infinity")/xdmp:node-uri(.) }', + (xs:QName('PATH'), $path), + {$database}) }; declare function helper:list-from-filesystem($path as xs:string) as xs:string* { - let $path := fn:replace($path, "(/|\\)", $helper:DIRECTORY-SEPARATOR) for $entry in xdmp:filesystem-directory($path)/dir:entry return if ($entry/dir:type = "directory") then From 2b6b46ccbe7209f2f57e67f00f86bc98453ac821 Mon Sep 17 00:00:00 2001 From: James Gardner Date: Fri, 4 Jan 2019 11:13:00 -0500 Subject: [PATCH 03/22] list() to uses a map instead of string comparison Now filtering out ignored directories and files by using a map instead of string comparison. This should scale much better. Also re-organized the code so it's a bit easier to read and follow. --- .../ml-modules/root/test/test-controller.xqy | 60 +++++++++---------- 1 file changed, 29 insertions(+), 31 deletions(-) diff --git a/marklogic-unit-test-modules/src/main/ml-modules/root/test/test-controller.xqy b/marklogic-unit-test-modules/src/main/ml-modules/root/test/test-controller.xqy index e4b86cc..a9f64e9 100644 --- a/marklogic-unit-test-modules/src/main/ml-modules/root/test/test-controller.xqy +++ b/marklogic-unit-test-modules/src/main/ml-modules/root/test/test-controller.xqy @@ -24,42 +24,41 @@ declare variable $root as xs:string := xdmp:modules-root(); :) declare function list() { - let $suite-ignore-list := (".svn", "CVS", ".DS_Store", "Thumbs.db", "thumbs.db", "test-data") - let $test-ignore-list := ( + let $suite-ignore-list := map:new(( + ".svn", "CVS", ".DS_Store", "Thumbs.db", "thumbs.db", "test-data" + ) ! map:entry(., .)) + + let $test-ignore-list := map:new(( "setup.xqy", "teardown.xqy", "setup.sjs", "teardown.sjs", "suite-setup.xqy", "suite-teardown.xqy", "suiteSetup.sjs", "suiteTeardown.sjs" - ) + ) ! map:entry(., .)) + + let $suites as xs:string* := fn:distinct-values( + let $uris := helper:list-from-database($db-id, $root || "test/suites/") + for $uri in $uris + let $path := fn:replace(cvt:basepath($uri), fn:concat($root, "test/suites/?"), "") + where $path ne "" and fn:not(fn:contains($path, "/")) and fn:empty(map:get($suite-ignore-list, $path)) + return $path + ) + + let $main-formats as xs:string* := fn:distinct-values( + let $uris := helper:list-from-database($db-id, $root || "test/formats/") + for $uri in $uris + let $path := fn:replace($uri, fn:concat($root, "test/formats/"), "") + where $path ne "" and fn:not(fn:contains($path, "/")) and fn:empty(map:get($test-ignore-list, $path)) and (fn:matches($path, $XSL-PATTERN)) + return $path + ) + return element t:tests { - let $suites as xs:string* := - let $uris := helper:list-from-database($db-id, $root || "test/suites/") - return - fn:distinct-values( - for $uri in $uris - let $path := fn:replace(cvt:basepath($uri), fn:concat($root, "test/suites/?"), "") - where $path ne "" and fn:not(fn:contains($path, "/")) and fn:not($path = $suite-ignore-list) - return - $path) - let $main-formats as xs:string* := - let $uris := helper:list-from-database($db-id, $root || "test/formats/") - return - fn:distinct-values( - for $uri in $uris - let $path := fn:replace($uri, fn:concat($root, "test/formats/"), "") - where $path ne "" and fn:not(fn:contains($path, "/")) and fn:not($path = $test-ignore-list) and (fn:matches($path, $XSL-PATTERN)) - return - $path) - return ( for $suite as xs:string in $suites - let $tests as xs:string* := + let $tests as xs:string* := fn:distinct-values( let $uris := helper:list-from-database($db-id, $root || "test/suites/" || $suite) - return - fn:distinct-values( - for $uri in $uris - let $path := fn:replace($uri, fn:concat($root, "test/suites/", $suite, "/"), "") - 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")) - return - $path) + for $uri in $uris + let $path := fn:replace($uri, fn:concat($root, "test/suites/", $suite, "/"), "") + where $path ne "" and fn:not(fn:contains($path, "/")) and fn:empty(map:get($test-ignore-list, $path)) and (fn:ends-with($path, ".xqy") or fn:ends-with($path, ".sjs")) + return $path + ) where $tests return element t:suite { @@ -81,7 +80,6 @@ declare function list() } } else () - ) } }; From d99cc129b4f840b7f11e065dc80ee4b001053224 Mon Sep 17 00:00:00 2001 From: James Gardner Date: Fri, 4 Jan 2019 12:29:49 -0500 Subject: [PATCH 04/22] list() iterates over tests once instead of twice Now populating a map of suites and tests. No longer asking for all of the tests in the module database two different times. Removed a few extra string operators in the process. --- .../ml-modules/root/test/test-controller.xqy | 67 ++++++++++--------- 1 file changed, 37 insertions(+), 30 deletions(-) diff --git a/marklogic-unit-test-modules/src/main/ml-modules/root/test/test-controller.xqy b/marklogic-unit-test-modules/src/main/ml-modules/root/test/test-controller.xqy index a9f64e9..cf6c647 100644 --- a/marklogic-unit-test-modules/src/main/ml-modules/root/test/test-controller.xqy +++ b/marklogic-unit-test-modules/src/main/ml-modules/root/test/test-controller.xqy @@ -33,44 +33,51 @@ declare function list() "suite-setup.xqy", "suite-teardown.xqy", "suiteSetup.sjs", "suiteTeardown.sjs" ) ! map:entry(., .)) - let $suites as xs:string* := fn:distinct-values( - let $uris := helper:list-from-database($db-id, $root || "test/suites/") - for $uri in $uris - let $path := fn:replace(cvt:basepath($uri), fn:concat($root, "test/suites/?"), "") - where $path ne "" and fn:not(fn:contains($path, "/")) and fn:empty(map:get($suite-ignore-list, $path)) - return $path - ) + let $suites := map:map() + + let $_ := + for $uri in helper:list-from-database($db-id, $root || "test/suites/") + let $test-path := fn:replace($uri, fn:concat($root, "test/suites/?"), "") + let $suite-path := cvt:basepath($test-path) + let $test-name := fn:replace($test-path, $suite-path || "(\\|/)?", "") + let $suite-is-valid := + $suite-path ne "" + and fn:not(fn:contains($suite-path, "/")) + and fn:empty(map:get($suite-ignore-list, $suite-path)) + let $test-is-valid := + $test-name ne "" + and fn:not(fn:contains($test-name, "/")) + and fn:empty(map:get($test-ignore-list, $test-name)) + and fn:matches($test-name, "(\.sjs|\.xqy)$") + where $suite-is-valid and $test-is-valid + return map:put($suites, $suite-path, (map:get($suites, $suite-path), $test-name)) let $main-formats as xs:string* := fn:distinct-values( - let $uris := helper:list-from-database($db-id, $root || "test/formats/") - for $uri in $uris + for $uri in helper:list-from-database($db-id, $root || "test/formats/") let $path := fn:replace($uri, fn:concat($root, "test/formats/"), "") where $path ne "" and fn:not(fn:contains($path, "/")) and fn:empty(map:get($test-ignore-list, $path)) and (fn:matches($path, $XSL-PATTERN)) return $path ) - return element t:tests { - for $suite as xs:string in $suites - let $tests as xs:string* := fn:distinct-values( - let $uris := helper:list-from-database($db-id, $root || "test/suites/" || $suite) - for $uri in $uris - let $path := fn:replace($uri, fn:concat($root, "test/suites/", $suite, "/"), "") - where $path ne "" and fn:not(fn:contains($path, "/")) and fn:empty(map:get($test-ignore-list, $path)) and (fn:ends-with($path, ".xqy") or fn:ends-with($path, ".sjs")) - return $path - ) - where $tests - return - element t:suite { - attribute path {$suite}, - element t:tests { - for $test in $tests - return - element t:test { - attribute path {$test} - } - } - }, + for $suite as xs:string in map:keys($suites) + let $tests as xs:string* := + for $test-name in map:get($suites, $suite) + order by $test-name + return $test-name + where $tests + order by $suite + return + element t:suite { + attribute path {$suite}, + element t:tests { + for $test in $tests + return + element t:test { + attribute path {$test} + } + } + }, if ($main-formats) then element t:formats { for $main-format in $main-formats From 24c3e2f0b800f47b4a8fffbd8386fc18d2898da4 Mon Sep 17 00:00:00 2001 From: James Gardner Date: Fri, 4 Jan 2019 12:56:21 -0500 Subject: [PATCH 05/22] Adding tests for suite structure and test detection Most files added have comments explaining why they exist, and how files either named in such a way or living in such a directory should be used out in the wild. --- .../suites/More Unit Tests/suite-teardown.xqy | 1 - .../test/suites/More Unit Tests/teardown.xqy | 1 - .../test/suites/Setup and Teardown/setup.sjs | 1 + .../test/suites/Setup and Teardown/setup.xqy | 6 ++++++ .../suites/Setup and Teardown/suite-setup.sjs | 1 + .../suites/Setup and Teardown/suite-setup.xqy | 6 ++++++ .../Setup and Teardown/suite-teardown.xqy | 6 ++++++ .../Setup and Teardown/suiteTeardown.sjs | 1 + .../suites/Setup and Teardown/teardown.sjs | 1 + .../suites/Setup and Teardown/teardown.xqy | 6 ++++++ .../Test Suites/ignored-directories.xqy | 11 ++++++++++ .../test/suites/Test Suites/ignored-files.xqy | 20 +++++++++++++++++++ .../suites/Test Suites/non-nested-suite.xqy | 11 ++++++++++ .../non-xquery-or-serverside-javascript.xqy | 11 ++++++++++ .../Test Suites/test-data/test-data.xml | 6 ++++++ .../suites/Test Suites/test-lib/library.xqy | 9 +++++++++ .../root/test/suites/Test Suites/test.xml | 3 +++ .../ml-modules/root/test/test-controller.xqy | 2 +- 18 files changed, 100 insertions(+), 3 deletions(-) delete mode 100644 marklogic-unit-test-client/src/test/ml-modules/root/test/suites/More Unit Tests/suite-teardown.xqy delete mode 100644 marklogic-unit-test-client/src/test/ml-modules/root/test/suites/More Unit Tests/teardown.xqy create mode 100644 marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Setup and Teardown/setup.sjs create mode 100644 marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Setup and Teardown/setup.xqy create mode 100644 marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Setup and Teardown/suite-setup.sjs create mode 100644 marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Setup and Teardown/suite-setup.xqy create mode 100644 marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Setup and Teardown/suite-teardown.xqy create mode 100644 marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Setup and Teardown/suiteTeardown.sjs create mode 100644 marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Setup and Teardown/teardown.sjs create mode 100644 marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Setup and Teardown/teardown.xqy create mode 100644 marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Test Suites/ignored-directories.xqy create mode 100644 marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Test Suites/ignored-files.xqy create mode 100644 marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Test Suites/non-nested-suite.xqy create mode 100644 marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Test Suites/non-xquery-or-serverside-javascript.xqy create mode 100644 marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Test Suites/test-data/test-data.xml create mode 100644 marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Test Suites/test-lib/library.xqy create mode 100644 marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Test Suites/test.xml diff --git a/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/More Unit Tests/suite-teardown.xqy b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/More Unit Tests/suite-teardown.xqy deleted file mode 100644 index 47f9ff5..0000000 --- a/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/More Unit Tests/suite-teardown.xqy +++ /dev/null @@ -1 +0,0 @@ -xdmp:log("Suite teardown") \ No newline at end of file diff --git a/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/More Unit Tests/teardown.xqy b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/More Unit Tests/teardown.xqy deleted file mode 100644 index e6f7a87..0000000 --- a/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/More Unit Tests/teardown.xqy +++ /dev/null @@ -1 +0,0 @@ -xdmp:log("Test teardown") \ No newline at end of file diff --git a/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Setup and Teardown/setup.sjs b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Setup and Teardown/setup.sjs new file mode 100644 index 0000000..319ecdf --- /dev/null +++ b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Setup and Teardown/setup.sjs @@ -0,0 +1 @@ +// This file would be ran multiple times, once before each test is ran diff --git a/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Setup and Teardown/setup.xqy b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Setup and Teardown/setup.xqy new file mode 100644 index 0000000..2200773 --- /dev/null +++ b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Setup and Teardown/setup.xqy @@ -0,0 +1,6 @@ +xquery version "1.0-ml"; + +(: + Code inserted here will be ran multiple times. It will run before each test in the suite runs. +:) +() diff --git a/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Setup and Teardown/suite-setup.sjs b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Setup and Teardown/suite-setup.sjs new file mode 100644 index 0000000..c0836aa --- /dev/null +++ b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Setup and Teardown/suite-setup.sjs @@ -0,0 +1 @@ +// This test would be ran once, before any tests in the suite has been ran diff --git a/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Setup and Teardown/suite-setup.xqy b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Setup and Teardown/suite-setup.xqy new file mode 100644 index 0000000..6ec0231 --- /dev/null +++ b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Setup and Teardown/suite-setup.xqy @@ -0,0 +1,6 @@ +xquery version "1.0-ml"; + +(: + Code inserted here will be ran one time. It will run before any test in the suite is ran. +:) +() diff --git a/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Setup and Teardown/suite-teardown.xqy b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Setup and Teardown/suite-teardown.xqy new file mode 100644 index 0000000..820b19b --- /dev/null +++ b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Setup and Teardown/suite-teardown.xqy @@ -0,0 +1,6 @@ +xquery version "1.0-ml"; + +(: + Code inserted here will be ran once, after all tests inside the suite have finished running. +:) +() diff --git a/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Setup and Teardown/suiteTeardown.sjs b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Setup and Teardown/suiteTeardown.sjs new file mode 100644 index 0000000..9806f4e --- /dev/null +++ b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Setup and Teardown/suiteTeardown.sjs @@ -0,0 +1 @@ +// This file would be ran once, after all tests in the suite have ran diff --git a/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Setup and Teardown/teardown.sjs b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Setup and Teardown/teardown.sjs new file mode 100644 index 0000000..1cdb728 --- /dev/null +++ b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Setup and Teardown/teardown.sjs @@ -0,0 +1 @@ +// This file would be called multiple times, once after each test in the suite is ran. diff --git a/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Setup and Teardown/teardown.xqy b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Setup and Teardown/teardown.xqy new file mode 100644 index 0000000..c051b1b --- /dev/null +++ b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Setup and Teardown/teardown.xqy @@ -0,0 +1,6 @@ +xquery version "1.0-ml"; + +(: + Code inserted here will be ran multiple times. It will run after each test in the suite has finished. +:) +() diff --git a/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Test Suites/ignored-directories.xqy b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Test Suites/ignored-directories.xqy new file mode 100644 index 0000000..94bea5b --- /dev/null +++ b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Test Suites/ignored-directories.xqy @@ -0,0 +1,11 @@ +xquery version "1.0-ml"; + +import module namespace test = "http://marklogic.com/roxy/test-helper" at "/test/test-helper.xqy", +"/test/test-controller.xqy"; + +let $list := test:list() + +return ( + test:assert-not-exists($list//element()[fn:contains(@path, "test-data")]), + test:assert-not-exists($list//element()[fn:contains(@path, "test-lib")]) +) diff --git a/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Test Suites/ignored-files.xqy b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Test Suites/ignored-files.xqy new file mode 100644 index 0000000..32d7377 --- /dev/null +++ b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Test Suites/ignored-files.xqy @@ -0,0 +1,20 @@ +xquery version "1.0-ml"; + +import module namespace test = "http://marklogic.com/roxy/test-helper" at "/test/test-helper.xqy", +"/test/test-controller.xqy"; + +declare namespace t = "http://marklogic.com/roxy/test"; + + +let $list := test:list() + +return ( + test:assert-not-exists($list/t:suite[@path="Setup and Teardown"]/t:tests/t:test[@path="setup.xqy"]), + test:assert-not-exists($list/t:suite[@path="Setup and Teardown"]/t:tests/t:test[@path="teardown.xqy"]), + test:assert-not-exists($list/t:suite[@path="Setup and Teardown"]/t:tests/t:test[@path="setup.sjs"]), + test:assert-not-exists($list/t:suite[@path="Setup and Teardown"]/t:tests/t:test[@path="teardown.sjs"]), + test:assert-not-exists($list/t:suite[@path="Setup and Teardown"]/t:tests/t:test[@path="suite-setup.xqy"]), + test:assert-not-exists($list/t:suite[@path="Setup and Teardown"]/t:tests/t:test[@path="suite-teardown.xqy"]), + test:assert-not-exists($list/t:suite[@path="Setup and Teardown"]/t:tests/t:test[@path="suiteSetup.sjs"]), + test:assert-not-exists($list/t:suite[@path="Setup and Teardown"]/t:tests/t:test[@path="suiteTeardown.sjs"]) +) diff --git a/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Test Suites/non-nested-suite.xqy b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Test Suites/non-nested-suite.xqy new file mode 100644 index 0000000..139ddac --- /dev/null +++ b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Test Suites/non-nested-suite.xqy @@ -0,0 +1,11 @@ +xquery version "1.0-ml"; + +import module namespace test = "http://marklogic.com/roxy/test-helper" at "/test/test-helper.xqy", +"/test/test-controller.xqy"; + +declare namespace t = "http://marklogic.com/roxy/test"; + + +let $list := test:list() + +return test:assert-exists($list/t:suite[@path="Unit Test Tests"]/t:tests/t:test[@path="assert-all-exist.xqy"]) diff --git a/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Test Suites/non-xquery-or-serverside-javascript.xqy b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Test Suites/non-xquery-or-serverside-javascript.xqy new file mode 100644 index 0000000..b5e0950 --- /dev/null +++ b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Test Suites/non-xquery-or-serverside-javascript.xqy @@ -0,0 +1,11 @@ +xquery version "1.0-ml"; + +import module namespace test = "http://marklogic.com/roxy/test-helper" at "/test/test-helper.xqy", +"/test/test-controller.xqy"; + +declare namespace t = "http://marklogic.com/roxy/test"; + + +let $list := test:list() +(: should only find tests that end with .sjs or .xqy :) +return test:assert-not-exists($list//t:test[fn:matches(@path, "([^.xqy|.sjs])$")]) diff --git a/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Test Suites/test-data/test-data.xml b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Test Suites/test-data/test-data.xml new file mode 100644 index 0000000..8c9cb4c --- /dev/null +++ b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Test Suites/test-data/test-data.xml @@ -0,0 +1,6 @@ + + + diff --git a/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Test Suites/test-lib/library.xqy b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Test Suites/test-lib/library.xqy new file mode 100644 index 0000000..4bb3688 --- /dev/null +++ b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Test Suites/test-lib/library.xqy @@ -0,0 +1,9 @@ +xquery version "1.0-ml"; +(: + This file is not used at all. It's here to ensure we don't accidentally read files in the lib directory and attempt + to run them as a test. + + All files in a test-lib directory will be ignored by the test scanner. This is a good place to add libraries that + will be used by multiple tests, but don't belong as a main part of the application. +:) +() diff --git a/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Test Suites/test.xml b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Test Suites/test.xml new file mode 100644 index 0000000..d3e4f6e --- /dev/null +++ b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Test Suites/test.xml @@ -0,0 +1,3 @@ + + + diff --git a/marklogic-unit-test-modules/src/main/ml-modules/root/test/test-controller.xqy b/marklogic-unit-test-modules/src/main/ml-modules/root/test/test-controller.xqy index cf6c647..71eb53a 100644 --- a/marklogic-unit-test-modules/src/main/ml-modules/root/test/test-controller.xqy +++ b/marklogic-unit-test-modules/src/main/ml-modules/root/test/test-controller.xqy @@ -25,7 +25,7 @@ declare variable $root as xs:string := xdmp:modules-root(); declare function list() { let $suite-ignore-list := map:new(( - ".svn", "CVS", ".DS_Store", "Thumbs.db", "thumbs.db", "test-data" + ".svn", "CVS", ".DS_Store", "Thumbs.db", "thumbs.db", "test-data", "test-lib" ) ! map:entry(., .)) let $test-ignore-list := map:new(( From 402759e1f02c6ca2feae88c595cd376dab86d26f Mon Sep 17 00:00:00 2001 From: James Gardner Date: Fri, 4 Jan 2019 13:11:36 -0500 Subject: [PATCH 06/22] #45 Support for nested test suites The system will recursive descend through the test suites directory and run any tests that are not part of an ignored directory nor an ignored file. Updating the list of ignored directories and ignored files is as simple as adding it to the map. --- .../double-nested-test.xqy | 6 ++++++ .../Another Nested Directory/nested-test.xqy | 6 ++++++ .../test/suites/Test Suites/nested-suite.xqy | 17 +++++++++++++++ .../ml-modules/root/test/test-controller.xqy | 21 +++++++++++-------- 4 files changed, 41 insertions(+), 9 deletions(-) create mode 100644 marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Nested Directory/Another Nested Directory/Double Nested Test Suite/double-nested-test.xqy create mode 100644 marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Nested Directory/Another Nested Directory/nested-test.xqy create mode 100644 marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Test Suites/nested-suite.xqy diff --git a/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Nested Directory/Another Nested Directory/Double Nested Test Suite/double-nested-test.xqy b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Nested Directory/Another Nested Directory/Double Nested Test Suite/double-nested-test.xqy new file mode 100644 index 0000000..73e376c --- /dev/null +++ b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Nested Directory/Another Nested Directory/Double Nested Test Suite/double-nested-test.xqy @@ -0,0 +1,6 @@ +import module namespace test="http://marklogic.com/roxy/test-helper" at "/test/test-helper.xqy"; +(: + This file is used to ensure we detect double nested tests when returning a list of tests and suites. The below + assertion is not meaningful. +:) +test:assert-true(fn:true()) diff --git a/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Nested Directory/Another Nested Directory/nested-test.xqy b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Nested Directory/Another Nested Directory/nested-test.xqy new file mode 100644 index 0000000..346139c --- /dev/null +++ b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Nested Directory/Another Nested Directory/nested-test.xqy @@ -0,0 +1,6 @@ +import module namespace test="http://marklogic.com/roxy/test-helper" at "/test/test-helper.xqy"; +(: + This file is used to ensure we detect nested tests when returning a list of tests and suites. The below assertion is + not meaningful. +:) +test:assert-true(fn:true()) diff --git a/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Test Suites/nested-suite.xqy b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Test Suites/nested-suite.xqy new file mode 100644 index 0000000..f69fd5f --- /dev/null +++ b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Test Suites/nested-suite.xqy @@ -0,0 +1,17 @@ +import module namespace test = "http://marklogic.com/roxy/test-helper" at "/test/test-helper.xqy", +"/test/test-controller.xqy"; + +declare namespace t = "http://marklogic.com/roxy/test"; + + +let $list := test:list() +let $_ := xdmp:log($list, "info") +return ( + test:assert-exists($list/t:suite[@path="Nested Directory/Another Nested Directory"] + /t:tests/t:test[@path="nested-test.xqy"]), + + test:assert-exists($list/t:suite[@path="Nested Directory/Another Nested Directory/Double Nested Test Suite"] + /t:tests/t:test[@path="double-nested-test.xqy"]) +) + + diff --git a/marklogic-unit-test-modules/src/main/ml-modules/root/test/test-controller.xqy b/marklogic-unit-test-modules/src/main/ml-modules/root/test/test-controller.xqy index 71eb53a..06f4242 100644 --- a/marklogic-unit-test-modules/src/main/ml-modules/root/test/test-controller.xqy +++ b/marklogic-unit-test-modules/src/main/ml-modules/root/test/test-controller.xqy @@ -24,11 +24,11 @@ declare variable $root as xs:string := xdmp:modules-root(); :) declare function list() { - let $suite-ignore-list := map:new(( + let $directories-to-ignore := map:new(( ".svn", "CVS", ".DS_Store", "Thumbs.db", "thumbs.db", "test-data", "test-lib" ) ! map:entry(., .)) - let $test-ignore-list := map:new(( + let $files-to-ignore := map:new(( "setup.xqy", "teardown.xqy", "setup.sjs", "teardown.sjs", "suite-setup.xqy", "suite-teardown.xqy", "suiteSetup.sjs", "suiteTeardown.sjs" ) ! map:entry(., .)) @@ -40,22 +40,25 @@ declare function list() let $test-path := fn:replace($uri, fn:concat($root, "test/suites/?"), "") let $suite-path := cvt:basepath($test-path) let $test-name := fn:replace($test-path, $suite-path || "(\\|/)?", "") + let $suite-is-valid := - $suite-path ne "" - and fn:not(fn:contains($suite-path, "/")) - and fn:empty(map:get($suite-ignore-list, $suite-path)) + let $path-not-in-ignored-directory := + fn:empty(fn:tokenize($suite-path, "(\\|/)") ! map:get($directories-to-ignore, .)) + return $suite-path and $path-not-in-ignored-directory + let $test-is-valid := - $test-name ne "" - and fn:not(fn:contains($test-name, "/")) - and fn:empty(map:get($test-ignore-list, $test-name)) + $test-name + and fn:not(fn:contains($test-name, "(\\|/)")) + and fn:empty(map:get($files-to-ignore, $test-name)) and fn:matches($test-name, "(\.sjs|\.xqy)$") + where $suite-is-valid and $test-is-valid return map:put($suites, $suite-path, (map:get($suites, $suite-path), $test-name)) let $main-formats as xs:string* := fn:distinct-values( for $uri in helper:list-from-database($db-id, $root || "test/formats/") let $path := fn:replace($uri, fn:concat($root, "test/formats/"), "") - where $path ne "" and fn:not(fn:contains($path, "/")) and fn:empty(map:get($test-ignore-list, $path)) and (fn:matches($path, $XSL-PATTERN)) + where $path ne "" and fn:not(fn:contains($path, "/")) and fn:empty(map:get($files-to-ignore, $path)) and (fn:matches($path, $XSL-PATTERN)) return $path ) return From 167862d851f6cd2c0bd22fe3c312bca12298cc94 Mon Sep 17 00:00:00 2001 From: James Gardner Date: Fri, 4 Jan 2019 16:57:44 -0500 Subject: [PATCH 07/22] #52 Remove Roxy from all namespaces This is still a bit of a work in progress. Everything seems to work when testing and building using gradle from the command line. However, the ParameterizedTest class isn't detecting test classes from inside IDEA. While updating the namespaces, I moved the assertion functions out into a separate assert library. Since everyone's imports are already going to break with the namespace change, I felt this was a good time to re- organize the code so that we have better separation of internal and external libraries. --- .../unit/JaxpServiceResponseUnmarshaller.java | 4 +- .../assert-all-exist.xqy | 4 +- .../assert-at-least-one-equal.xqy | 2 +- .../assert-equal-json.sjs | 18 +- .../assert-equal-json.xqy | 4 +- .../assert-equal.xqy | 4 +- .../assert-exists.xqy | 4 +- .../assert-false.xqy | 2 +- .../assert-meets-maximum-threshold.xqy | 4 +- .../assert-meets-minimum-threshold.xqy | 4 +- .../assert-not-equal.xqy | 4 +- .../assert-not-exists.xqy | 4 +- .../assert-throws-error.xqy | 4 +- .../assert-true.xqy | 4 +- .../assertEqual.sjs | 0 .../{Unit Test Tests => Assertions}/fail.xqy | 4 +- .../root/test/suites/Assertions/success.xqy | 5 + .../http-helpers.xqy | 2 +- .../double-nested-test.xqy | 2 +- .../Another Nested Directory/nested-test.xqy | 2 +- .../Test Suites/ignored-directories.xqy | 2 +- .../test/suites/Test Suites/ignored-files.xqy | 23 +- .../test/suites/Test Suites/nested-suite.xqy | 16 +- .../suites/Test Suites/non-nested-suite.xqy | 9 +- .../non-xquery-or-serverside-javascript.xqy | 9 +- .../test/suites/Unit Test Tests/success.xqy | 5 - .../src/main/ml-modules/root/test/assert.xqy | 393 ++++++++++++++ .../src/main/ml-modules/root/test/default.xqy | 20 +- .../ml-modules/root/test/formats/j-unit.xsl | 10 +- .../src/main/ml-modules/root/test/js/tests.js | 4 +- .../ml-modules/root/test/test-controller.xqy | 89 ++- .../ml-modules/root/test/test-coverage.xqy | 32 +- .../main/ml-modules/root/test/test-helper.xqy | 505 ++---------------- .../root/test/xslt/coverage/common.xsl | 2 +- .../root/test/xslt/coverage/module/html.xsl | 2 +- .../root/test/xslt/coverage/report/html.xsl | 2 +- .../root/test/xslt/coverage/report/xml.xsl | 4 +- .../services/marklogic-unit-test.xqy | 9 +- .../ml-modules/root/test/formats/j-unit.xsl | 10 +- .../ml-modules/root/test/test-coverage.xqy | 20 +- .../root/test/xslt/coverage/common.xsl | 2 +- .../root/test/xslt/coverage/module/html.xsl | 2 +- .../root/test/xslt/coverage/report/html.xsl | 2 +- .../root/test/xslt/coverage/report/xml.xsl | 4 +- 44 files changed, 625 insertions(+), 632 deletions(-) rename marklogic-unit-test-client/src/test/ml-modules/root/test/suites/{Unit Test Tests => Assertions}/assert-all-exist.xqy (77%) rename marklogic-unit-test-client/src/test/ml-modules/root/test/suites/{Unit Test Tests => Assertions}/assert-at-least-one-equal.xqy (90%) rename marklogic-unit-test-client/src/test/ml-modules/root/test/suites/{Unit Test Tests => Assertions}/assert-equal-json.sjs (87%) rename marklogic-unit-test-client/src/test/ml-modules/root/test/suites/{Unit Test Tests => Assertions}/assert-equal-json.xqy (95%) rename marklogic-unit-test-client/src/test/ml-modules/root/test/suites/{Unit Test Tests => Assertions}/assert-equal.xqy (91%) rename marklogic-unit-test-client/src/test/ml-modules/root/test/suites/{Unit Test Tests => Assertions}/assert-exists.xqy (63%) rename marklogic-unit-test-client/src/test/ml-modules/root/test/suites/{Unit Test Tests => Assertions}/assert-false.xqy (78%) rename marklogic-unit-test-client/src/test/ml-modules/root/test/suites/{Unit Test Tests => Assertions}/assert-meets-maximum-threshold.xqy (76%) rename marklogic-unit-test-client/src/test/ml-modules/root/test/suites/{Unit Test Tests => Assertions}/assert-meets-minimum-threshold.xqy (76%) rename marklogic-unit-test-client/src/test/ml-modules/root/test/suites/{More Unit Tests => Assertions}/assert-not-equal.xqy (79%) rename marklogic-unit-test-client/src/test/ml-modules/root/test/suites/{More Unit Tests => Assertions}/assert-not-exists.xqy (56%) rename marklogic-unit-test-client/src/test/ml-modules/root/test/suites/{More Unit Tests => Assertions}/assert-throws-error.xqy (89%) rename marklogic-unit-test-client/src/test/ml-modules/root/test/suites/{More Unit Tests => Assertions}/assert-true.xqy (86%) rename marklogic-unit-test-client/src/test/ml-modules/root/test/suites/{Unit Test Tests => Assertions}/assertEqual.sjs (100%) rename marklogic-unit-test-client/src/test/ml-modules/root/test/suites/{Unit Test Tests => Assertions}/fail.xqy (53%) create mode 100644 marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Assertions/success.xqy rename marklogic-unit-test-client/src/test/ml-modules/root/test/suites/{More Unit Tests => Helpers}/http-helpers.xqy (61%) delete mode 100644 marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Unit Test Tests/success.xqy create mode 100644 marklogic-unit-test-modules/src/main/ml-modules/root/test/assert.xqy diff --git a/marklogic-unit-test-client/src/main/java/com/marklogic/test/unit/JaxpServiceResponseUnmarshaller.java b/marklogic-unit-test-client/src/main/java/com/marklogic/test/unit/JaxpServiceResponseUnmarshaller.java index d9eb78b..76a48a1 100644 --- a/marklogic-unit-test-client/src/main/java/com/marklogic/test/unit/JaxpServiceResponseUnmarshaller.java +++ b/marklogic-unit-test-client/src/main/java/com/marklogic/test/unit/JaxpServiceResponseUnmarshaller.java @@ -31,8 +31,10 @@ public List parseTestList(String xml) { List testModules = new ArrayList<>(); for (int i = 0; i < kids.getLength(); i++) { Node suiteNode = kids.item(i); + String namespaceUri = suiteNode.getNamespaceURI(); + String localname = suiteNode.getLocalName(); // getLocalName returns null, have to compare against getNodeName to ensure we have a suite - if ("t:suite".equals(suiteNode.getNodeName())) { + if ("test:suite".equals(suiteNode.getNodeName())) { String suite = suiteNode.getAttributes().getNamedItem("path").getTextContent(); NodeList testsNodes = suiteNode.getChildNodes(); for (int j = 0; j < testsNodes.getLength(); j++) { diff --git a/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Unit Test Tests/assert-all-exist.xqy b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Assertions/assert-all-exist.xqy similarity index 77% rename from marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Unit Test Tests/assert-all-exist.xqy rename to marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Assertions/assert-all-exist.xqy index dbc12a1..179cf2a 100644 --- a/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Unit Test Tests/assert-all-exist.xqy +++ b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Assertions/assert-all-exist.xqy @@ -1,4 +1,4 @@ -import module namespace test="http://marklogic.com/roxy/test-helper" at "/test/test-helper.xqy"; +import module namespace test="http://marklogic.com/test/unit" at "/test/assert.xqy"; declare function local:case1() { @@ -14,4 +14,4 @@ test:assert-all-exist(0, ()), test:assert-all-exist(1, "1"), test:assert-all-exist(2, ("1", "2")), test:assert-throws-error(xdmp:function(xs:QName("local:case1")), "ASSERT-ALL-EXIST-FAILED"), -test:assert-throws-error(xdmp:function(xs:QName("local:case2")), "ASSERT-ALL-EXIST-FAILED") \ No newline at end of file +test:assert-throws-error(xdmp:function(xs:QName("local:case2")), "ASSERT-ALL-EXIST-FAILED") diff --git a/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Unit Test Tests/assert-at-least-one-equal.xqy b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Assertions/assert-at-least-one-equal.xqy similarity index 90% rename from marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Unit Test Tests/assert-at-least-one-equal.xqy rename to marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Assertions/assert-at-least-one-equal.xqy index a1892b9..f62a315 100644 --- a/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Unit Test Tests/assert-at-least-one-equal.xqy +++ b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Assertions/assert-at-least-one-equal.xqy @@ -1,4 +1,4 @@ -import module namespace test="http://marklogic.com/roxy/test-helper" at "/test/test-helper.xqy"; +import module namespace test="http://marklogic.com/test/unit" at "/test/assert.xqy"; declare function local:case1() { diff --git a/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Unit Test Tests/assert-equal-json.sjs b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Assertions/assert-equal-json.sjs similarity index 87% rename from marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Unit Test Tests/assert-equal-json.sjs rename to marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Assertions/assert-equal-json.sjs index f3b5ae6..ef88c24 100644 --- a/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Unit Test Tests/assert-equal-json.sjs +++ b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Assertions/assert-equal-json.sjs @@ -1,9 +1,9 @@ // Given two JSON objects or arrays, determine whether they are the same. -const test = require("/test/test-helper.xqy"); +const test = require("/test/assert.xqy"); -let j0 = +let j0 = { "PersonNameType":{ "PersonSurName":"SMITH", @@ -11,13 +11,13 @@ let j0 = } }; -let j1 = +let j1 = { "PersonNameType":{ "PersonSurName":"JONES", "PersonGivenName":"LINDSEY" }, - "charges": [1,true,"a",null] + "charges": [1,true,"a",null] }; let j2 = @@ -32,7 +32,7 @@ let j2 = let j3 = { "PersonNameType":{ - "PersonGivenName":"LINDSEY", + "PersonGivenName":"LINDSEY", "PersonSurName":"JONES" }, "charges": [1,true,"a",null] @@ -57,9 +57,9 @@ let j5 = }; /** - * test.assertEqualJson expects an xdmp:function, but a JS function is not one of those. - * @param f - * @param msg + * test.assertEqualJson expects an xdmp:function, but a JS function is not one of those. + * @param f + * @param msg */ function assertThrowsError(f, msg) { @@ -86,7 +86,7 @@ function assertThrowsError(f, msg) assertThrowsError( function() { test.assertEqualJson(j0, j5) - }, + }, "ASSERT-EQUAL-JSON-FAILED" ) ] diff --git a/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Unit Test Tests/assert-equal-json.xqy b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Assertions/assert-equal-json.xqy similarity index 95% rename from marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Unit Test Tests/assert-equal-json.xqy rename to marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Assertions/assert-equal-json.xqy index 1c677e9..6ef356f 100644 --- a/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Unit Test Tests/assert-equal-json.xqy +++ b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Assertions/assert-equal-json.xqy @@ -1,4 +1,4 @@ -import module namespace test="http://marklogic.com/roxy/test-helper" at "/test/test-helper.xqy"; +import module namespace test="http://marklogic.com/test/unit" at "/test/assert.xqy"; declare option xdmp:mapping "false"; @@ -61,4 +61,4 @@ return xdmp:eager(( test:assert-equal-json($j0, $j5) }, "ASSERT-EQUAL-JSON-FAILED") -)) \ No newline at end of file +)) diff --git a/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Unit Test Tests/assert-equal.xqy b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Assertions/assert-equal.xqy similarity index 91% rename from marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Unit Test Tests/assert-equal.xqy rename to marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Assertions/assert-equal.xqy index ed68975..3c3d38a 100644 --- a/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Unit Test Tests/assert-equal.xqy +++ b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Assertions/assert-equal.xqy @@ -1,4 +1,4 @@ -import module namespace test="http://marklogic.com/roxy/test-helper" at "/test/test-helper.xqy"; +import module namespace test="http://marklogic.com/test/unit" at "/test/assert.xqy"; declare function local:case1() { @@ -47,4 +47,4 @@ test:assert-equal("a", "a"), test:assert-equal((), ()), -test:assert-throws-error(xdmp:function(xs:QName("local:case5")), "ASSERT-EQUAL-FAILED") \ No newline at end of file +test:assert-throws-error(xdmp:function(xs:QName("local:case5")), "ASSERT-EQUAL-FAILED") diff --git a/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Unit Test Tests/assert-exists.xqy b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Assertions/assert-exists.xqy similarity index 63% rename from marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Unit Test Tests/assert-exists.xqy rename to marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Assertions/assert-exists.xqy index 31398d9..a16801d 100644 --- a/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Unit Test Tests/assert-exists.xqy +++ b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Assertions/assert-exists.xqy @@ -1,4 +1,4 @@ -import module namespace test="http://marklogic.com/roxy/test-helper" at "/test/test-helper.xqy"; +import module namespace test="http://marklogic.com/test/unit" at "/test/assert.xqy"; declare function local:case1() { @@ -8,4 +8,4 @@ declare function local:case1() test:assert-exists("1"), test:assert-exists(("1", "2")), test:assert-exists(), -test:assert-throws-error(xdmp:function(xs:QName("local:case1")), "ASSERT-EXISTS-FAILED") \ No newline at end of file +test:assert-throws-error(xdmp:function(xs:QName("local:case1")), "ASSERT-EXISTS-FAILED") diff --git a/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Unit Test Tests/assert-false.xqy b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Assertions/assert-false.xqy similarity index 78% rename from marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Unit Test Tests/assert-false.xqy rename to marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Assertions/assert-false.xqy index b6e9691..884c6d3 100644 --- a/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Unit Test Tests/assert-false.xqy +++ b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Assertions/assert-false.xqy @@ -1,4 +1,4 @@ -import module namespace test="http://marklogic.com/roxy/test-helper" at "/test/test-helper.xqy"; +import module namespace test="http://marklogic.com/test/unit" at "/test/assert.xqy"; declare function local:case1() { diff --git a/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Unit Test Tests/assert-meets-maximum-threshold.xqy b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Assertions/assert-meets-maximum-threshold.xqy similarity index 76% rename from marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Unit Test Tests/assert-meets-maximum-threshold.xqy rename to marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Assertions/assert-meets-maximum-threshold.xqy index c957b5d..c850525 100644 --- a/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Unit Test Tests/assert-meets-maximum-threshold.xqy +++ b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Assertions/assert-meets-maximum-threshold.xqy @@ -1,4 +1,4 @@ -import module namespace test="http://marklogic.com/roxy/test-helper" at "/test/test-helper.xqy"; +import module namespace test="http://marklogic.com/test/unit" at "/test/assert.xqy"; declare function local:case1() { @@ -13,4 +13,4 @@ declare function local:case2() test:assert-meets-maximum-threshold(6, 6), test:assert-meets-maximum-threshold(6, (3, 4, 5, 6)), test:assert-throws-error(xdmp:function(xs:QName("local:case1")), "ASSERT-MEETS-MAXIMUM-THRESHOLD-FAILED"), -test:assert-throws-error(xdmp:function(xs:QName("local:case2")), "ASSERT-MEETS-MAXIMUM-THRESHOLD-FAILED") \ No newline at end of file +test:assert-throws-error(xdmp:function(xs:QName("local:case2")), "ASSERT-MEETS-MAXIMUM-THRESHOLD-FAILED") diff --git a/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Unit Test Tests/assert-meets-minimum-threshold.xqy b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Assertions/assert-meets-minimum-threshold.xqy similarity index 76% rename from marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Unit Test Tests/assert-meets-minimum-threshold.xqy rename to marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Assertions/assert-meets-minimum-threshold.xqy index 948aa85..1521bca 100644 --- a/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Unit Test Tests/assert-meets-minimum-threshold.xqy +++ b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Assertions/assert-meets-minimum-threshold.xqy @@ -1,4 +1,4 @@ -import module namespace test="http://marklogic.com/roxy/test-helper" at "/test/test-helper.xqy"; +import module namespace test="http://marklogic.com/test/unit" at "/test/assert.xqy"; declare function local:case1() { @@ -13,4 +13,4 @@ declare function local:case2() test:assert-meets-minimum-threshold(2, 2), test:assert-meets-minimum-threshold(2, (3, 4, 5, 6)), test:assert-throws-error(xdmp:function(xs:QName("local:case1")), "ASSERT-MEETS-MINIMUM-THRESHOLD-FAILED"), -test:assert-throws-error(xdmp:function(xs:QName("local:case2")), "ASSERT-MEETS-MINIMUM-THRESHOLD-FAILED") \ No newline at end of file +test:assert-throws-error(xdmp:function(xs:QName("local:case2")), "ASSERT-MEETS-MINIMUM-THRESHOLD-FAILED") diff --git a/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/More Unit Tests/assert-not-equal.xqy b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Assertions/assert-not-equal.xqy similarity index 79% rename from marklogic-unit-test-client/src/test/ml-modules/root/test/suites/More Unit Tests/assert-not-equal.xqy rename to marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Assertions/assert-not-equal.xqy index 7c19a29..99618de 100644 --- a/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/More Unit Tests/assert-not-equal.xqy +++ b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Assertions/assert-not-equal.xqy @@ -1,4 +1,4 @@ -import module namespace test="http://marklogic.com/roxy/test-helper" at "/test/test-helper.xqy"; +import module namespace test="http://marklogic.com/test/unit" at "/test/assert.xqy"; declare function local:case1() { @@ -16,4 +16,4 @@ test:assert-not-equal((0, 1, 2), ()), test:assert-not-equal(, ), test:assert-not-equal(, ), test:assert-throws-error(xdmp:function(xs:QName("local:case1")), "ASSERT-NOT-EQUAL-FAILED"), -test:assert-throws-error(xdmp:function(xs:QName("local:case2")), "ASSERT-NOT-EQUAL-FAILED") \ No newline at end of file +test:assert-throws-error(xdmp:function(xs:QName("local:case2")), "ASSERT-NOT-EQUAL-FAILED") diff --git a/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/More Unit Tests/assert-not-exists.xqy b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Assertions/assert-not-exists.xqy similarity index 56% rename from marklogic-unit-test-client/src/test/ml-modules/root/test/suites/More Unit Tests/assert-not-exists.xqy rename to marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Assertions/assert-not-exists.xqy index 76b8021..9c1c8f1 100644 --- a/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/More Unit Tests/assert-not-exists.xqy +++ b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Assertions/assert-not-exists.xqy @@ -1,4 +1,4 @@ -import module namespace test="http://marklogic.com/roxy/test-helper" at "/test/test-helper.xqy"; +import module namespace test="http://marklogic.com/test/unit" at "/test/assert.xqy"; declare function local:case1() { @@ -6,4 +6,4 @@ declare function local:case1() }; test:assert-not-exists(()), -test:assert-throws-error(xdmp:function(xs:QName("local:case1")), "ASSERT-NOT-EXISTS-FAILED") \ No newline at end of file +test:assert-throws-error(xdmp:function(xs:QName("local:case1")), "ASSERT-NOT-EXISTS-FAILED") diff --git a/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/More Unit Tests/assert-throws-error.xqy b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Assertions/assert-throws-error.xqy similarity index 89% rename from marklogic-unit-test-client/src/test/ml-modules/root/test/suites/More Unit Tests/assert-throws-error.xqy rename to marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Assertions/assert-throws-error.xqy index 738f661..ed18165 100644 --- a/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/More Unit Tests/assert-throws-error.xqy +++ b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Assertions/assert-throws-error.xqy @@ -1,4 +1,4 @@ -import module namespace test="http://marklogic.com/roxy/test-helper" at "/test/test-helper.xqy"; +import module namespace test="http://marklogic.com/test/unit" at "/test/assert.xqy"; declare function local:case1() { @@ -53,4 +53,4 @@ catch($ex) { test:assert-throws-error(xdmp:function(xs:QName("local:case5")), 5, ()), -test:assert-throws-error(xdmp:function(xs:QName("local:case5")), 5, "XDMP-DIVBYZERO") \ No newline at end of file +test:assert-throws-error(xdmp:function(xs:QName("local:case5")), 5, "XDMP-DIVBYZERO") diff --git a/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/More Unit Tests/assert-true.xqy b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Assertions/assert-true.xqy similarity index 86% rename from marklogic-unit-test-client/src/test/ml-modules/root/test/suites/More Unit Tests/assert-true.xqy rename to marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Assertions/assert-true.xqy index a4e6641..73bf31d 100644 --- a/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/More Unit Tests/assert-true.xqy +++ b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Assertions/assert-true.xqy @@ -1,4 +1,4 @@ -import module namespace test="http://marklogic.com/roxy/test-helper" at "/test/test-helper.xqy"; +import module namespace test="http://marklogic.com/test/unit" at "/test/assert.xqy"; declare function local:case1() { @@ -27,4 +27,4 @@ test:assert-throws-error(xdmp:function(xs:QName("local:case2")), "ASSERT-TRUE-FA test:assert-true((fn:true(), fn:true()), "test"), test:assert-throws-error(xdmp:function(xs:QName("local:case3")), "ASSERT-TRUE-FAILED"), -test:assert-throws-error(xdmp:function(xs:QName("local:case4")), "ASSERT-TRUE-FAILED") \ No newline at end of file +test:assert-throws-error(xdmp:function(xs:QName("local:case4")), "ASSERT-TRUE-FAILED") diff --git a/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Unit Test Tests/assertEqual.sjs b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Assertions/assertEqual.sjs similarity index 100% rename from marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Unit Test Tests/assertEqual.sjs rename to marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Assertions/assertEqual.sjs diff --git a/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Unit Test Tests/fail.xqy b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Assertions/fail.xqy similarity index 53% rename from marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Unit Test Tests/fail.xqy rename to marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Assertions/fail.xqy index 7775c40..aa4b12e 100644 --- a/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Unit Test Tests/fail.xqy +++ b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Assertions/fail.xqy @@ -1,8 +1,8 @@ -import module namespace test="http://marklogic.com/roxy/test-helper" at "/test/test-helper.xqy"; +import module namespace test="http://marklogic.com/test/unit" at "/test/assert.xqy"; declare function local:case1() { test:fail('i failed') }; -test:assert-throws-error(xdmp:function(xs:QName("local:case1")), "USER-FAIL") \ No newline at end of file +test:assert-throws-error(xdmp:function(xs:QName("local:case1")), "USER-FAIL") diff --git a/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Assertions/success.xqy b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Assertions/success.xqy new file mode 100644 index 0000000..da08eb5 --- /dev/null +++ b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Assertions/success.xqy @@ -0,0 +1,5 @@ +import module namespace test="http://marklogic.com/test/unit" at "/test/assert.xqy"; + +declare namespace t="http://marklogic.com/test/unit"; + +test:assert-equal(, test:success()) diff --git a/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/More Unit Tests/http-helpers.xqy b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Helpers/http-helpers.xqy similarity index 61% rename from marklogic-unit-test-client/src/test/ml-modules/root/test/suites/More Unit Tests/http-helpers.xqy rename to marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Helpers/http-helpers.xqy index ef5e8d0..4b17fc0 100644 --- a/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/More Unit Tests/http-helpers.xqy +++ b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Helpers/http-helpers.xqy @@ -1,4 +1,4 @@ -import module namespace test="http://marklogic.com/roxy/test-helper" at "/test/test-helper.xqy"; +import module namespace test="http://marklogic.com/test/unit" at "/test/test-helper.xqy", "/test/assert.xqy"; test:assert-http-get-status("v1/search?format=xml", $test:DEFAULT_HTTP_OPTIONS,200), diff --git a/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Nested Directory/Another Nested Directory/Double Nested Test Suite/double-nested-test.xqy b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Nested Directory/Another Nested Directory/Double Nested Test Suite/double-nested-test.xqy index 73e376c..8daac03 100644 --- a/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Nested Directory/Another Nested Directory/Double Nested Test Suite/double-nested-test.xqy +++ b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Nested Directory/Another Nested Directory/Double Nested Test Suite/double-nested-test.xqy @@ -1,4 +1,4 @@ -import module namespace test="http://marklogic.com/roxy/test-helper" at "/test/test-helper.xqy"; +import module namespace test="http://marklogic.com/test/unit" at "/test/assert.xqy"; (: This file is used to ensure we detect double nested tests when returning a list of tests and suites. The below assertion is not meaningful. diff --git a/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Nested Directory/Another Nested Directory/nested-test.xqy b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Nested Directory/Another Nested Directory/nested-test.xqy index 346139c..7e6a48a 100644 --- a/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Nested Directory/Another Nested Directory/nested-test.xqy +++ b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Nested Directory/Another Nested Directory/nested-test.xqy @@ -1,4 +1,4 @@ -import module namespace test="http://marklogic.com/roxy/test-helper" at "/test/test-helper.xqy"; +import module namespace test="http://marklogic.com/test/unit" at "/test/assert.xqy"; (: This file is used to ensure we detect nested tests when returning a list of tests and suites. The below assertion is not meaningful. diff --git a/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Test Suites/ignored-directories.xqy b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Test Suites/ignored-directories.xqy index 94bea5b..cb82068 100644 --- a/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Test Suites/ignored-directories.xqy +++ b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Test Suites/ignored-directories.xqy @@ -1,6 +1,6 @@ xquery version "1.0-ml"; -import module namespace test = "http://marklogic.com/roxy/test-helper" at "/test/test-helper.xqy", +import module namespace test = "http://marklogic.com/test/unit" at "/test/assert.xqy", "/test/test-controller.xqy"; let $list := test:list() diff --git a/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Test Suites/ignored-files.xqy b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Test Suites/ignored-files.xqy index 32d7377..88f824e 100644 --- a/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Test Suites/ignored-files.xqy +++ b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Test Suites/ignored-files.xqy @@ -1,20 +1,17 @@ xquery version "1.0-ml"; -import module namespace test = "http://marklogic.com/roxy/test-helper" at "/test/test-helper.xqy", -"/test/test-controller.xqy"; - -declare namespace t = "http://marklogic.com/roxy/test"; - +import module namespace test = "http://marklogic.com/test/unit" at "/test/test-controller.xqy", + "/test/assert.xqy"; let $list := test:list() return ( - test:assert-not-exists($list/t:suite[@path="Setup and Teardown"]/t:tests/t:test[@path="setup.xqy"]), - test:assert-not-exists($list/t:suite[@path="Setup and Teardown"]/t:tests/t:test[@path="teardown.xqy"]), - test:assert-not-exists($list/t:suite[@path="Setup and Teardown"]/t:tests/t:test[@path="setup.sjs"]), - test:assert-not-exists($list/t:suite[@path="Setup and Teardown"]/t:tests/t:test[@path="teardown.sjs"]), - test:assert-not-exists($list/t:suite[@path="Setup and Teardown"]/t:tests/t:test[@path="suite-setup.xqy"]), - test:assert-not-exists($list/t:suite[@path="Setup and Teardown"]/t:tests/t:test[@path="suite-teardown.xqy"]), - test:assert-not-exists($list/t:suite[@path="Setup and Teardown"]/t:tests/t:test[@path="suiteSetup.sjs"]), - test:assert-not-exists($list/t:suite[@path="Setup and Teardown"]/t:tests/t:test[@path="suiteTeardown.sjs"]) + test:assert-not-exists($list/test:suite[@path="Setup and Teardown"]/test:tests/test:test[@path="setup.xqy"]), + test:assert-not-exists($list/test:suite[@path="Setup and Teardown"]/test:tests/test:test[@path="teardown.xqy"]), + test:assert-not-exists($list/test:suite[@path="Setup and Teardown"]/test:tests/test:test[@path="setup.sjs"]), + test:assert-not-exists($list/test:suite[@path="Setup and Teardown"]/test:tests/test:test[@path="teardown.sjs"]), + test:assert-not-exists($list/test:suite[@path="Setup and Teardown"]/test:tests/test:test[@path="suite-setup.xqy"]), + test:assert-not-exists($list/test:suite[@path="Setup and Teardown"]/test:tests/test:test[@path="suite-teardown.xqy"]), + test:assert-not-exists($list/test:suite[@path="Setup and Teardown"]/test:tests/test:test[@path="suiteSetup.sjs"]), + test:assert-not-exists($list/test:suite[@path="Setup and Teardown"]/test:tests/test:test[@path="suiteTeardown.sjs"]) ) diff --git a/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Test Suites/nested-suite.xqy b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Test Suites/nested-suite.xqy index f69fd5f..d16e3f1 100644 --- a/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Test Suites/nested-suite.xqy +++ b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Test Suites/nested-suite.xqy @@ -1,17 +1,13 @@ -import module namespace test = "http://marklogic.com/roxy/test-helper" at "/test/test-helper.xqy", -"/test/test-controller.xqy"; - -declare namespace t = "http://marklogic.com/roxy/test"; - +import module namespace test = "http://marklogic.com/test/unit" at "/test/test-controller.xqy", + "/test/assert.xqy"; let $list := test:list() -let $_ := xdmp:log($list, "info") return ( - test:assert-exists($list/t:suite[@path="Nested Directory/Another Nested Directory"] - /t:tests/t:test[@path="nested-test.xqy"]), + test:assert-exists($list/test:suite[@path="Nested Directory/Another Nested Directory"] + /test:tests/test:test[@path="nested-test.xqy"]), - test:assert-exists($list/t:suite[@path="Nested Directory/Another Nested Directory/Double Nested Test Suite"] - /t:tests/t:test[@path="double-nested-test.xqy"]) + test:assert-exists($list/test:suite[@path="Nested Directory/Another Nested Directory/Double Nested Test Suite"] + /test:tests/test:test[@path="double-nested-test.xqy"]) ) diff --git a/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Test Suites/non-nested-suite.xqy b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Test Suites/non-nested-suite.xqy index 139ddac..c501a83 100644 --- a/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Test Suites/non-nested-suite.xqy +++ b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Test Suites/non-nested-suite.xqy @@ -1,11 +1,8 @@ xquery version "1.0-ml"; -import module namespace test = "http://marklogic.com/roxy/test-helper" at "/test/test-helper.xqy", -"/test/test-controller.xqy"; - -declare namespace t = "http://marklogic.com/roxy/test"; - +import module namespace test = "http://marklogic.com/test/unit" at "/test/test-controller.xqy", + "/test/assert.xqy"; let $list := test:list() -return test:assert-exists($list/t:suite[@path="Unit Test Tests"]/t:tests/t:test[@path="assert-all-exist.xqy"]) +return test:assert-exists($list/test:suite[@path="Assertions"]/test:tests/test:test[@path="assert-exists.xqy"]) diff --git a/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Test Suites/non-xquery-or-serverside-javascript.xqy b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Test Suites/non-xquery-or-serverside-javascript.xqy index b5e0950..f35728a 100644 --- a/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Test Suites/non-xquery-or-serverside-javascript.xqy +++ b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Test Suites/non-xquery-or-serverside-javascript.xqy @@ -1,11 +1,8 @@ xquery version "1.0-ml"; -import module namespace test = "http://marklogic.com/roxy/test-helper" at "/test/test-helper.xqy", -"/test/test-controller.xqy"; - -declare namespace t = "http://marklogic.com/roxy/test"; - +import module namespace test = "http://marklogic.com/test/unit" at "/test/test-controller.xqy", + "/test/assert.xqy"; let $list := test:list() (: should only find tests that end with .sjs or .xqy :) -return test:assert-not-exists($list//t:test[fn:matches(@path, "([^.xqy|.sjs])$")]) +return test:assert-not-exists($list//test:test[fn:matches(@path, "([^.xqy|.sjs])$")]) diff --git a/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Unit Test Tests/success.xqy b/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Unit Test Tests/success.xqy deleted file mode 100644 index 969f16b..0000000 --- a/marklogic-unit-test-client/src/test/ml-modules/root/test/suites/Unit Test Tests/success.xqy +++ /dev/null @@ -1,5 +0,0 @@ -import module namespace test="http://marklogic.com/roxy/test-helper" at "/test/test-helper.xqy"; - -declare namespace t="http://marklogic.com/roxy/test"; - -test:assert-equal(, test:success()) \ No newline at end of file diff --git a/marklogic-unit-test-modules/src/main/ml-modules/root/test/assert.xqy b/marklogic-unit-test-modules/src/main/ml-modules/root/test/assert.xqy new file mode 100644 index 0000000..a475591 --- /dev/null +++ b/marklogic-unit-test-modules/src/main/ml-modules/root/test/assert.xqy @@ -0,0 +1,393 @@ +xquery version "1.0-ml"; + +module namespace test = "http://marklogic.com/test/unit"; + +import module namespace json = "http://marklogic.com/xdmp/json" at "/MarkLogic/json/json.xqy"; + +declare variable $test:PREVIOUS_LINE_FILE as xs:string := + try { + fn:error(xs:QName("boom"), "") + } + catch($ex) { + fn:concat($ex/error:stack/error:frame[3]/error:uri, " : Line ", $ex/error:stack/error:frame[3]/error:line) + }; + +(:~ + : constructs a success xml element + :) +declare function test:success() { + +}; + +(:~ + : constructs a failure xml element + :) +declare function test:fail($expected as item(), $actual as item()) { + test:fail(Expected {$expected} but got {$actual} at {$test:PREVIOUS_LINE_FILE}) +}; + +(:~ + : constructs a failure xml element + :) +declare function test:fail($message as item()*) { + element test:result { + attribute type { "fail" }, + typeswitch($message) + case element(error:error) return $message + default return + fn:error(xs:QName("USER-FAIL"), $message) + } +}; + +declare function test:assert-all-exist($count as xs:unsignedInt, $item as item()*) { + if ($count eq fn:count($item)) then + test:success() + else + fn:error(xs:QName("ASSERT-ALL-EXIST-FAILED"), "Assert All Exist failed", $item) +}; + +declare function test:assert-exists($item as item()*) { + if (fn:exists($item)) then + test:success() + else + fn:error(xs:QName("ASSERT-EXISTS-FAILED"), "Assert Exists failed", $item) +}; + +declare function test:assert-not-exists($item as item()*) { + if (fn:not(fn:exists($item))) then + test:success() + else + fn:error(xs:QName("ASSERT-NOT-EXISTS-FAILED"), "Assert Not Exists failed", $item) +}; + +declare function test:assert-at-least-one-equal($expected as item()*, $actual as item()*) { + if ($expected = $actual) then + test:success() + else + fn:error(xs:QName("ASSERT-AT-LEAST-ONE-EQUAL-FAILED"), "Assert At Least one Equal failed", ()) +}; + +declare private function test:are-these-equal($expected as item()*, $actual as item()*) { + if (fn:count($expected) eq fn:count($actual)) then + if ($expected instance of json:array and $actual instance of json:array) then + test:assert-equal-json-recursive($expected, $actual) + else + fn:count(( + for $item at $i in $expected + return + fn:deep-equal($item, $actual[$i]))[. = fn:true()]) eq fn:count($expected) + else + fn:false() +}; + +(: Return true if and only if the two sequences have the same values, regardless + : of order. fn:deep-equal() returns false if items are not in the same order. :) +declare function test:assert-same-values($expected as item()*, $actual as item()*) +{ + let $expected-ordered := + for $e in $expected + order by $e + return $e + let $actual-ordered := + for $a in $actual + order by $a + return $a + return test:assert-equal($expected-ordered, $actual-ordered) +}; + +declare function test:assert-equal($expected as item()*, $actual as item()*) { + if (test:are-these-equal($expected, $actual)) then + test:success() + else + fn:error(xs:QName("ASSERT-EQUAL-FAILED"), "Assert Equal failed", ($expected, $actual)) +}; + +declare function test:assert-equal($expected as item()*, $actual as item()*, $error-object as item()*) { + if (test:are-these-equal($expected, $actual)) then + test:success() + else + fn:error(xs:QName("ASSERT-EQUAL-FAILED"), "Assert Equal failed", ($expected, $actual, " : ", $error-object)) +}; + +declare function test:assert-not-equal($expected as item()*, $actual as item()*) { + if (fn:not(test:are-these-equal($expected, $actual))) then + test:success() + else + fn:error( + xs:QName("ASSERT-NOT-EQUAL-FAILED"), + fn:concat("test name", ": Assert Not Equal failed"), + ($expected, $actual)) +}; + +declare function test:assert-equal-xml($expected, $actual) { + typeswitch ($actual) + case document-node() return + typeswitch ($expected) + case document-node() return + test:assert-equal-xml($expected/node(), $actual/node()) + default return + test:assert-equal-xml($expected, $actual/node()) + case element() return + if (fn:empty($expected)) then + test:assert-true(fn:false(), ("element not found in $expected : ", xdmp:path($actual))) + else typeswitch ($expected) + case element() return ( + test:assert-equal(fn:name($expected), fn:name($actual), ("mismatched node name ($expected=", xdmp:path($expected), ", $actual=", xdmp:path($actual), ")")), + test:assert-equal(fn:count($expected/@*), fn:count($actual/@*), ("mismatched attribute count ($expected=", xdmp:path($expected), ", $actual=", xdmp:path($actual), ")")), + for $attribute in $actual/@* return + test:assert-equal-xml($expected/@*[fn:name(.) = fn:name($attribute)], $attribute), + for $text at $i in $actual/text() return + test:assert-equal(fn:normalize-space($expected/text()[$i]), fn:normalize-space($text), ("mismatched element text ($expected=", xdmp:path($expected), ", $actual=", xdmp:path($actual), ")")), + test:assert-equal(fn:count($expected/*), fn:count($actual/*), ("mismatched element count ($expected=", xdmp:path($expected), ", $actual=", xdmp:path($actual), ")")), + for $element at $i in $actual/* return + test:assert-equal-xml($expected/*[$i], $element) + ) + default return + test:assert-true(fn:false(), ("type mismatch ($expected=", xdmp:path($expected), ", $actual=", xdmp:path($actual), ")")) + case attribute() return + if (fn:empty($expected)) then + test:assert-true(fn:false(), ("attribute not found in $expected : ", xdmp:path($actual))) + else typeswitch ($expected) + case attribute() return ( + test:assert-equal(fn:name($expected), fn:name($actual), ("mismatched attribute name ($expected=", xdmp:path($expected), ", $actual=", xdmp:path($actual), ")")), + test:assert-equal($expected/fn:data(), $actual/fn:data(), ("mismatched attribute text ($expected=", xdmp:path($expected), ", $actual=", xdmp:path($actual), ")")) + ) + default return + test:assert-true(fn:false(), ("type mismatch : $expected=", xdmp:path($expected), ", $actual=", xdmp:path($actual))) + default return + test:assert-true(fn:false(), ("unsupported type in $actual : ", xdmp:path($actual))) +}; + +declare function test:assert-equal-json($expected, $actual) { + if ($expected instance of object-node()*) then + if ($actual instance of object-node()*) then + if (fn:count($expected) = fn:count($actual)) then + if (test:assert-equal-json-recursive($expected, $actual)) then + test:success() + else + fn:error(xs:QName("ASSERT-EQUAL-JSON-FAILED"), "Assert Equal Json failed", ($expected, $actual)) + else + fn:error(xs:QName("ASSERT-EQUAL-JSON-FAILED"), "Assert Equal Json failed (different counts of objects)", ($expected, $actual)) + else + (: $actual is not object-node()* :) + fn:error(xs:QName("ASSERT-EQUAL-JSON-FAILED"), "Assert Equal Json failed ($actual does not consist of objects)", ($expected, $actual)) + else if ($expected instance of map:map*) then + if ($actual instance of map:map*) then + if (fn:count($expected) = fn:count($actual)) then + if (test:assert-equal-json-recursive($expected, $actual)) then + test:success() + else + fn:error(xs:QName("ASSERT-EQUAL-JSON-FAILED"), "Assert Equal Json failed", ($expected, $actual)) + else + fn:error(xs:QName("ASSERT-EQUAL-JSON-FAILED"), "Assert Equal Json failed (different counts of objects)", ($expected, $actual)) + else + fn:error(xs:QName("ASSERT-EQUAL-JSON-FAILED"), "Assert Equal Json failed ($actual does not consist of objects)", ($expected, $actual)) + else if ($expected instance of array-node()*) then + if ($actual instance of array-node()*) then + if (fn:count($expected) = fn:count($actual)) then + if (test:assert-equal-json-recursive($expected, $actual)) then + test:success() + else + fn:error(xs:QName("ASSERT-EQUAL-JSON-FAILED"), "Assert Equal Json failed", ($expected, $actual)) + else + fn:error(xs:QName("ASSERT-EQUAL-JSON-FAILED"), "Assert Equal Json failed (different counts of arrays)", ($expected, $actual)) + else + fn:error(xs:QName("ASSERT-EQUAL-JSON-FAILED"), "Assert Equal Json failed ($actual does not consist of arrays)", ($expected, $actual)) + else if ($expected instance of document-node()) then + if ($actual instance of document-node()) then + if (fn:count($expected) = fn:count($actual)) then + if (test:assert-equal-json-recursive($expected/node(), $actual/node())) then + test:success() + else + fn:error(xs:QName("ASSERT-EQUAL-JSON-FAILED"), "Assert Equal Json failed (documents not equal)", ($expected, $actual)) + else + fn:error(xs:QName("ASSERT-EQUAL-JSON-FAILED"), "Assert Equal Json failed (different counts of documents)", ($expected, $actual)) + else + fn:error(xs:QName("ASSERT-EQUAL-JSON-FAILED"), "Assert Equal Json failed ($actual is not a document)", ($expected, $actual)) + else + (: scalar values :) + test:assert-equal($expected, $actual) +}; + +declare function test:assert-equal-json-recursive($object1, $object2) as xs:boolean +{ + typeswitch($object1) + case map:map return + let $k1 := map:keys($object1) + let $k2 := + if ($object2 instance of map:map) then + map:keys($object2) + else + fn:error( + xs:QName("ASSERT-EQUAL-JSON-FAILED"), + "Assert Equal Json failed: comparing map to non-map", + ($object1, $object2) + ) + let $counts-equal := fn:count($k1) eq fn:count($k2) + let $maps-equal := + for $key in map:keys($object1) + let $v1 := map:get($object1, $key) + let $v2 := map:get($object2, $key) + return + test:assert-equal-json-recursive($v1, $v2) + return $counts-equal and fn:not($maps-equal = fn:false()) + case json:array return + let $counts-equal := fn:count($object1) = fn:count($object2) + let $items-equal := + let $o1 := json:array-values($object1) + let $o2 := + if ($object2 instance of json:array) then + json:array-values($object2) + else + fn:error( + xs:QName("ASSERT-EQUAL-JSON-FAILED"), + "Assert Equal JSON failed: comparing json:array to non-array", + ($object1, $object2) + ) + for $item at $i in $o1 + return + test:assert-equal-json-recursive($item, $o2[$i]) + return + $counts-equal and fn:not($items-equal = fn:false()) + case object-node() return + let $m1 := fn:data($object1) + let $m2 := + if ($object2 instance of object-node()) then + fn:data($object2) + else + fn:error( + xs:QName("ASSERT-EQUAL-JSON-FAILED"), + "Assert Equal JSON failed: comparing object-node to non-object-node", + ($object1, $object2) + ) + let $k1 := map:keys($m1) + let $k2 := map:keys($m2) + let $counts-equal := fn:count($k1) eq fn:count($k2) + let $maps-equal := + for $key in map:keys($m1) + let $v1 := map:get($m1, $key) + let $v2 := map:get($m2, $key) + return + test:assert-equal-json-recursive($v1, $v2) + return $counts-equal and fn:not($maps-equal = fn:false()) + default return + $object1 = $object2 +}; + +declare function test:assert-true($supposed-truths as xs:boolean*) { + test:assert-true($supposed-truths, $supposed-truths) +}; + +declare function test:assert-true($supposed-truths as xs:boolean*, $msg as item()*) { + if (fn:false() = $supposed-truths) then + fn:error(xs:QName("ASSERT-TRUE-FAILED"), "Assert True failed", $msg) + else + test:success() +}; + +declare function test:assert-false($supposed-falsehoods as xs:boolean*) { + if (fn:true() = $supposed-falsehoods) then + fn:error(xs:QName("ASSERT-FALSE-FAILED"), "Assert False failed", $supposed-falsehoods) + else + test:success() +}; + + +declare function test:assert-meets-minimum-threshold($expected as xs:decimal, $actual as xs:decimal+) { + if (every $i in 1 to fn:count($actual) satisfies $actual[$i] ge $expected) then + test:success() + else + fn:error( + xs:QName("ASSERT-MEETS-MINIMUM-THRESHOLD-FAILED"), + fn:concat("test name", ": Assert Meets Minimum Threshold failed"), + ($expected, $actual)) +}; + +declare function test:assert-meets-maximum-threshold($expected as xs:decimal, $actual as xs:decimal+) { + if (every $i in 1 to fn:count($actual) satisfies $actual[$i] le $expected) then + test:success() + else + fn:error( + xs:QName("ASSERT-MEETS-MAXIMUM-THRESHOLD-FAILED"), + fn:concat("test name", ": Assert Meets Maximum Threshold failed"), + ($expected, $actual)) +}; + +declare function test:assert-throws-error($function as xdmp:function) +{ + test:assert-throws-error_($function, json:to-array(), ()) +}; + +declare function test:assert-throws-error($function as xdmp:function, $error-code as xs:string?) +{ + test:assert-throws-error_($function, json:to-array(), $error-code) +}; + +declare function test:assert-throws-error($function as xdmp:function, $param1 as item()*, $error-code as xs:string?) +{ + test:assert-throws-error_($function, json:to-array( (json:to-array($param1), json:to-array('make me a sequence')), 1 ), $error-code) +}; + +declare function test:assert-throws-error($function as xdmp:function, $param1 as item()*, $param2 as item()*, $error-code as xs:string?) +{ + test:assert-throws-error_($function, json:to-array((json:to-array($param1), json:to-array($param2))), $error-code) +}; + +declare function test:assert-throws-error($function as xdmp:function, $param1 as item()*, $param2 as item()*, $param3 as item()*, $error-code as xs:string?) +{ + test:assert-throws-error_($function, json:to-array((json:to-array($param1), json:to-array($param2), json:to-array($param3))), $error-code) +}; + +declare function test:assert-throws-error($function as xdmp:function, $param1 as item()*, $param2 as item()*, $param3 as item()*, $param4 as item()*, $error-code as xs:string?) +{ + test:assert-throws-error_($function, json:to-array((json:to-array($param1), json:to-array($param2), json:to-array($param3), json:to-array($param4))), $error-code) +}; + +declare function test:assert-throws-error($function as xdmp:function, $param1 as item()*, $param2 as item()*, $param3 as item()*, $param4 as item()*, $param5 as item()*, $error-code as xs:string?) +{ + test:assert-throws-error_($function, json:to-array((json:to-array($param1), json:to-array($param2), json:to-array($param3), json:to-array($param4), json:to-array($param5))), $error-code) +}; + +declare function test:assert-throws-error($function as xdmp:function, $param1 as item()*, $param2 as item()*, $param3 as item()*, $param4 as item()*, $param5 as item()*, $param6 as item()*, $error-code as xs:string?) +{ + test:assert-throws-error_($function, json:to-array((json:to-array($param1), json:to-array($param2), json:to-array($param3), json:to-array($param4), json:to-array($param5), json:to-array($param6))), $error-code) +}; + +declare private function test:assert-throws-error_($function as xdmp:function, $params as json:array, $error-code as xs:string?) +{ + let $size := json:array-size($params) + return + try { + if ($size eq 0) then + xdmp:apply($function) + else if ($size eq 1) then + xdmp:apply($function, json:array-values($params[1])) + else if ($size eq 2) then + xdmp:apply($function, json:array-values($params[1]), json:array-values($params[2])) + else if ($size eq 3) then + xdmp:apply($function, json:array-values($params[1]), json:array-values($params[2]), json:array-values($params[3])) + else if ($size eq 4) then + xdmp:apply($function, json:array-values($params[1]), json:array-values($params[2]), json:array-values($params[3]), json:array-values($params[4])) + else if ($size eq 5) then + xdmp:apply($function, json:array-values($params[1]), json:array-values($params[2]), json:array-values($params[3]), json:array-values($params[4]), json:array-values($params[5])) + else if ($size eq 6) then + xdmp:apply($function, json:array-values($params[1]), json:array-values($params[2]), json:array-values($params[3]), json:array-values($params[4]), json:array-values($params[5]), json:array-values($params[6])) + else (: arbitrary fall-back :) + xdmp:apply($function, json:array-values($params)) + , + fn:error(xs:QName("ASSERT-THROWS-ERROR-FAILED"), "It did not throw an error") + } + catch($ex) { + if ($ex/error:name eq "ASSERT-THROWS-ERROR-FAILED") then + xdmp:rethrow() + else if ($error-code) then + if ($ex/error:code eq $error-code or $ex/error:name eq $error-code) then + test:success() + else + ( + fn:error(xs:QName("ASSERT-THROWS-ERROR-FAILED"), fn:concat("Error code was: ", $ex/error:code, " not: ", $error-code)) + ) + else + test:success() + } +}; diff --git a/marklogic-unit-test-modules/src/main/ml-modules/root/test/default.xqy b/marklogic-unit-test-modules/src/main/ml-modules/root/test/default.xqy index b6e9f85..7777b65 100644 --- a/marklogic-unit-test-modules/src/main/ml-modules/root/test/default.xqy +++ b/marklogic-unit-test-modules/src/main/ml-modules/root/test/default.xqy @@ -15,11 +15,9 @@ limitations under the License. :) xquery version "1.0-ml"; -import module namespace helper="http://marklogic.com/roxy/test-helper" -at "/test/test-helper.xqy", "/test/test-controller.xqy"; -import module namespace coverage="http://marklogic.com/roxy/test-coverage" at "/test/test-coverage.xqy"; - -declare namespace t="http://marklogic.com/roxy/test"; +import module namespace test = "http://marklogic.com/test/unit" at "/test/test-helper.xqy", + "/test/test-controller.xqy"; +import module namespace coverage = "http://marklogic.com/test/coverage" at "/test/test-coverage.xqy"; declare option xdmp:mapping "false"; @@ -32,10 +30,10 @@ declare function local:run() { let $calculate-coverage as xs:boolean := xdmp:get-request-field("calculatecoverage", "") eq "true" return if ($suite) then - let $result := helper:run-suite($suite, $tests, $run-suite-teardown, $run-teardown, $calculate-coverage) + let $result := test:run-suite($suite, $tests, $run-suite-teardown, $run-teardown, $calculate-coverage) return if ($format) then - helper:format($result, $format, $suite) + test:format($result, $format, $suite) else $result else () @@ -43,7 +41,7 @@ declare function local:run() { declare function local:list() { - helper:list() + test:list() }; (:~ @@ -117,7 +115,7 @@ declare function local:main() { { - for $suite at $index in helper:list()/t:suite + for $suite at $index in test:list()/test:suite let $class := if ($index mod 2 = 1) then "odd" else "even" return ( @@ -130,7 +128,7 @@ declare function local:main() { {fn:data($suite/@path)} Running... - {fn:count($suite/t:tests/t:test)} + {fn:count($suite/test:tests/test:test)} - - - @@ -141,7 +139,7 @@ declare function local:main() {
Run All Tests