From b0ea16d23b4636f09a9f8b4ee6c0d062442b3358 Mon Sep 17 00:00:00 2001 From: Reece Dunn Date: Thu, 14 Jul 2016 12:00:55 +0100 Subject: [PATCH 1/3] #573 Report test setup/teardown errors in the test framework. --- src/test/default.xqy | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/test/default.xqy b/src/test/default.xqy index da304e6c..e66277da 100644 --- a/src/test/default.xqy +++ b/src/test/default.xqy @@ -172,12 +172,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) @@ -191,7 +196,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")) @@ -201,7 +206,10 @@ 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() @@ -209,7 +217,9 @@ declare function t:run($suite as xs:string, $name as xs:string, $module, $run-te element t:test { attribute name { $name }, attribute time { functx:total-seconds-from-duration($end-time - $start-time) }, - $result + $setup, + $result, + $teardown } }; From 01949465800e895dfa9e42aca27e0370cfb931fd Mon Sep 17 00:00:00 2001 From: Reece Dunn Date: Thu, 14 Jul 2016 14:11:27 +0100 Subject: [PATCH 2/3] #573 Report test suite setup/teardown errors in the test framework. --- src/test/default.xqy | 67 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 58 insertions(+), 9 deletions(-) diff --git a/src/test/default.xqy b/src/test/default.xqy index e66277da..101e7610 100644 --- a/src/test/default.xqy +++ b/src/test/default.xqy @@ -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() @@ -111,14 +111,34 @@ 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 - () + 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"} + } + } 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"), @@ -132,16 +152,37 @@ 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 - () + 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"} + } + } 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(" ") @@ -351,7 +392,15 @@ declare function local:main() { { for $test in $suite/t:tests/t:test return -
  • {fn:string($test/@path)}
  • +
  • + { + if ($test/@path = "suite-setup.xqy" or $test/@path = "suite-teardown.xqy") then + + else + , + fn:string($test/@path) + } +
  • } From 087e96aa01e7bd0cd8c842a27a26ef73036c80a9 Mon Sep 17 00:00:00 2001 From: Reece Dunn Date: Thu, 21 Jul 2016 09:28:12 +0100 Subject: [PATCH 3/3] Fix #573 Only show suite setup/teardown results if they exist. There should only be a t:test element for suite-setup.xqy and suite-teardown.xqy when those files exist. This is applying feedback from @dmcassel. --- src/test/default.xqy | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/src/test/default.xqy b/src/test/default.xqy index 101e7610..1f286f64 100644 --- a/src/test/default.xqy +++ b/src/test/default.xqy @@ -123,13 +123,7 @@ 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 - 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"} - } - } + () else element t:test { attribute name { "suite-setup.xqy" }, @@ -167,13 +161,7 @@ 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 - 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"} - } - } + () else element t:test { attribute name { "suite-teardown.xqy" },