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 #627 from rhdunn/test-report-setup-teardown-errors
Browse files Browse the repository at this point in the history
Fix #573 Report exceptions in the setup/teardown logic to the test framework.
  • Loading branch information
dmcassel authored Jul 21, 2016
2 parents 4f8ee5c + 087e96a commit f11f595
Showing 1 changed file with 60 additions and 13 deletions.
73 changes: 60 additions & 13 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", "suite-setup.xqy", "suite-teardown.xqy")
let $test-ignore-list := ("setup.xqy", "teardown.xqy")
return
element t:tests {
let $db-id as xs:unsignedLong := xdmp:modules-database()
Expand Down Expand Up @@ -111,14 +111,28 @@ declare function t:run-suite($suite as xs:string, $tests as xs:string*, $run-sui
helper:log(text {"SUITE:", $suite}),
try {
helper:log(" - invoking suite setup"),
xdmp:invoke(fn:concat("suites/", $suite, "/suite-setup.xqy"))
xdmp:invoke(fn:concat("suites/", $suite, "/suite-setup.xqy")),
element t:test {
attribute name { "suite-setup.xqy" },
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(), "/suite-setup.xqy$")) then
()
else
(helper:log($ex), xdmp:rethrow())
element t:test {
attribute name { "suite-setup.xqy" },
attribute time { functx:total-seconds-from-duration(xdmp:elapsed-time() - $start-time) },
element t:result {
attribute type {"fail"},
$ex
}
}
},

helper:log(" - invoking tests"),
Expand All @@ -132,16 +146,31 @@ declare function t:run-suite($suite as xs:string, $tests as xs:string*, $run-sui
t:run($suite, $test, fn:concat("suites/", $suite, "/", $test), $run-teardown),

if ($run-suite-teardown eq fn:true()) then
try {
let $teardown-start-time := xdmp:elapsed-time()
return try {
helper:log(" - invoking suite teardown"),
xdmp:invoke(fn:concat("suites/", $suite, "/suite-teardown.xqy"))
xdmp:invoke(fn:concat("suites/", $suite, "/suite-teardown.xqy")),
element t:test {
attribute name { "suite-teardown.xqy" },
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(), "/suite-teardown.xqy$")) then
()
else
(helper:log($ex), xdmp:rethrow())
element t:test {
attribute name { "suite-teardown.xqy" },
attribute time { functx:total-seconds-from-duration(xdmp:elapsed-time() - $teardown-start-time) },
element t:result {
attribute type {"fail"},
$ex
}
}
}
else helper:log(" - not running suite teardown"),
helper:log(" ")
Expand Down Expand Up @@ -172,12 +201,17 @@ declare function t:run($suite as xs:string, $name as xs:string, $module, $run-te
fn:matches($ex/error:stack/error:frame[1]/error:uri/fn:string(), "/setup.xqy$")) then
()
else
(helper:log($ex), xdmp:rethrow())
element t:result {
attribute type {"fail"},
$ex
}
}
let $result :=
try {
helper:log(" ...running"),
xdmp:invoke($module)
if (fn:not($setup/@type = "fail")) then
(helper:log(" ...running"), xdmp:invoke($module))
else
()
}
catch($ex) {
helper:fail($ex)
Expand All @@ -191,7 +225,7 @@ declare function t:run($suite as xs:string, $name as xs:string, $module, $run-te
else
$result
let $teardown :=
if ($run-teardown eq fn:true()) then
if ($run-teardown eq fn:true() and fn:not($setup/@type = "fail")) then
try {
helper:log(" ...invoking teardown"),
xdmp:invoke(fn:concat("suites/", $suite, "/teardown.xqy"))
Expand All @@ -201,15 +235,20 @@ declare function t:run($suite as xs:string, $name as xs:string, $module, $run-te
fn:matches($ex/error:stack/error:frame[1]/error:uri/fn:string(), "/teardown.xqy$")) then
()
else
(helper:log($ex), xdmp:rethrow())
element t:result {
attribute type {"fail"},
$ex
}
}
else helper:log(" ...not running teardown")
let $end-time := xdmp:elapsed-time()
return
element t:test {
attribute name { $name },
attribute time { functx:total-seconds-from-duration($end-time - $start-time) },
$result
$setup,
$result,
$teardown
}
};

Expand Down Expand Up @@ -341,7 +380,15 @@ declare function local:main() {
{
for $test in $suite/t:tests/t:test
return
<li class="tests"><input class="test-cb" type="checkbox" checked="checked" value="{fn:data($test/@path)}"/>{fn:string($test/@path)}<span class="outcome"></span></li>
<li class="tests">
{
if ($test/@path = "suite-setup.xqy" or $test/@path = "suite-teardown.xqy") then
<input type="hidden" value="{fn:data($test/@path)}"/>
else
<input class="test-cb" type="checkbox" checked="checked" value="{fn:data($test/@path)}"/>,
fn:string($test/@path)
}<span class="outcome"></span>
</li>
}
</ul>
</div>
Expand Down

1 comment on commit f11f595

@tomleggett
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi - removing the suite-setup & suite-teardown from the test-ignore-list on line 60 causes the suite-setup/suite-teardown to be run as a unit test where the explicit list of tests is not provided (line 143). This is not apparent from the UI as the UI passes the comma separated list of tests but may be apparent when running from roxy (e.g. ml sit test) if the setup/teardown runs mid-way a suite.

let $test-ignore-list := ("setup.xqy", "teardown.xqy", "suite-setup.xqy", "suite-teardown.xqy")

Example:
GET https://itgsydapd654.macbank:8062/test/default.xqy?func=run&suite=[suite]&tests=a-test1.sjs,z-test2.sjs&runsuiteteardown=true&runteardown=true
Tests = suite-setup.xqy, a-test1.sjs, z-test2.sjs, suite-teardown.xqy
GET https://itgsydapd654.macbank:8062/test/default.xqy?func=run&suite=[suite]&runsuiteteardown=true&runteardown=true
Tests = suite-setup.xqy, a-test1.sjs, suite-setup.xqy, suite-teardown.xqy, z-test2.sjs, suite-teardown.xqy

Please sign in to comment.