Skip to content
This repository has been archived by the owner on Nov 9, 2022. It is now read-only.

Commit

Permalink
Merge pull request #657 from bradmann/dev
Browse files Browse the repository at this point in the history
#656 Support JavaScript setup/suite-setup/teardown/suite-teardown
  • Loading branch information
dmcassel committed Sep 14, 2016
2 parents 1a76b51 + 65cb97c commit 24ec18c
Showing 1 changed file with 77 additions and 6 deletions.
83 changes: 77 additions & 6 deletions src/test/default.xqy
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ as xs:string*
:)
declare function t:list() {
let $suite-ignore-list := (".svn", "CVS", ".DS_Store", "Thumbs.db", "thumbs.db", "test-data")
let $test-ignore-list := ("setup.xqy", "teardown.xqy")
let $test-ignore-list := ("setup.xqy", "teardown.xqy", "setup.sjs", "teardown.sjs")
return
element t:tests {
let $db-id as xs:unsignedLong := xdmp:modules-database()
Expand Down Expand Up @@ -123,7 +123,30 @@ declare function t:run-suite($suite as xs:string, $tests as xs:string*, $run-sui
catch($ex) {
if ($ex/error:code = "XDMP-MODNOTFOUND" and
fn:matches($ex/error:stack/error:frame[1]/error:uri/fn:string(), "/suite-setup.xqy$")) then
()
try {
xdmp:invoke(fn:concat("suites/", $suite, "/suiteSetup.sjs")),
element t:test {
attribute name { "suiteSetup.sjs" },
attribute time { functx:total-seconds-from-duration(xdmp:elapsed-time() - $start-time) },
element t:result {
attribute type {"success"}
}
}
}
catch ($ex) {
if ($ex/error:code = "XDMP-MODNOTFOUND" and
fn:matches($ex/error:stack/error:frame[1]/error:uri/fn:string(), "/suiteSetup.sjs$")) then
()
else
element t:test {
attribute name { "suiteSetup.sjs" },
attribute time { functx:total-seconds-from-duration(xdmp:elapsed-time() - $start-time) },
element t:result {
attribute type {"fail"},
$ex
}
}
}
else
element t:test {
attribute name { "suite-setup.xqy" },
Expand Down Expand Up @@ -161,7 +184,30 @@ declare function t:run-suite($suite as xs:string, $tests as xs:string*, $run-sui
catch($ex) {
if ($ex/error:code = "XDMP-MODNOTFOUND" and
fn:matches($ex/error:stack/error:frame[1]/error:uri/fn:string(), "/suite-teardown.xqy$")) then
()
try {
xdmp:invoke(fn:concat("suites/", $suite, "/suiteTeardown.sjs")),
element t:test {
attribute name { "suiteTeardown.sjs" },
attribute time { functx:total-seconds-from-duration(xdmp:elapsed-time() - $start-time) },
element t:result {
attribute type {"success"}
}
}
}
catch($ex) {
if ($ex/error:code = "XDMP-MODNOTFOUND" and
fn:matches($ex/error:stack/error:frame[1]/error:uri/fn:string(), "/suiteTeardown.sjs$")) then
()
else
element t:test {
attribute name { "suiteTeardown.sjs" },
attribute time { functx:total-seconds-from-duration(xdmp:elapsed-time() - $teardown-start-time) },
element t:result {
attribute type {"fail"},
$ex
}
}
}
else
element t:test {
attribute name { "suite-teardown.xqy" },
Expand Down Expand Up @@ -199,7 +245,20 @@ declare function t:run($suite as xs:string, $name as xs:string, $module, $run-te
catch($ex) {
if ($ex/error:code = "XDMP-MODNOTFOUND" and
fn:matches($ex/error:stack/error:frame[1]/error:uri/fn:string(), "/setup.xqy$")) then
()
try {
let $_ := xdmp:invoke(fn:concat("suites/", $suite, "/setup.sjs"))
return ()
}
catch($ex) {
if ($ex/error:code = "XDMP-MODNOTFOUND" and
fn:matches($ex/error:stack/error:frame[1]/error:uri/fn:string(), "/setup.sjs$")) then
()
else
element t:result {
attribute type {"fail"},
$ex
}
}
else
element t:result {
attribute type {"fail"},
Expand Down Expand Up @@ -233,7 +292,19 @@ declare function t:run($suite as xs:string, $name as xs:string, $module, $run-te
catch($ex) {
if ($ex/error:code = "XDMP-MODNOTFOUND" and
fn:matches($ex/error:stack/error:frame[1]/error:uri/fn:string(), "/teardown.xqy$")) then
()
try {
xdmp:invoke(fn:concat("suites/", $suite, "/teardown.sjs"))
}
catch($ex) {
if ($ex/error:code = "XDMP-MODNOTFOUND" and
fn:matches($ex/error:stack/error:frame[1]/error:uri/fn:string(), "/teardown.sjs$")) then
()
else
element t:result {
attribute type {"fail"},
$ex
}
}
else
element t:result {
attribute type {"fail"},
Expand Down Expand Up @@ -382,7 +453,7 @@ declare function local:main() {
return
<li class="tests">
{
if ($test/@path = "suite-setup.xqy" or $test/@path = "suite-teardown.xqy") then
if ($test/@path = "suite-setup.xqy" or $test/@path = "suite-teardown.xqy" or $test/@path = "suiteSetup.sjs" or $test/@path = "suiteTeardown.sjs") then
<input type="hidden" value="{fn:data($test/@path)}"/>
else
<input class="test-cb" type="checkbox" checked="checked" value="{fn:data($test/@path)}"/>,
Expand Down

0 comments on commit 24ec18c

Please sign in to comment.