unittest2.nim: ensure the testTeardownIMPL is performed at the end (#35)
* unittest2.nim: ensure the testTeardownIMPL is performed at the end This is important to prevent failing tests to fail in an uncontrolled way and generating a SIGSEGV (segmentation fault) Particularly, when the test body raises an exception, e.g. "assert false", what happened was that the "testTeardownIMPL" was invoked before the exception handlging and that caused errors like: Traceback (most recent call last, using override) /home/ivansete/workspace/status/nwaku/vendor/nim-unittest2/unittest2.nim(1154) unittest2 /home/ivansete/workspace/status/nwaku/vendor/nim-unittest2/unittest2.nim(1086) runDirect /home/ivansete/workspace/status/nwaku/vendor/nim-unittest2/unittest2.nim(1111) runTestX60gensym398 /home/ivansete/workspace/status/nwaku/vendor/nimbus-build-system/vendor/Nim/lib/system/excpt.nim(631) signalHandler SIGSEGV: Illegal storage access. (Attempt to read from nil?) Segmentation fault (core dumped)
This commit is contained in:
parent
262b697f38
commit
db67e2ad76
|
@ -1105,8 +1105,6 @@ template runtimeTest*(nameParam: string, body: untyped) =
|
||||||
|
|
||||||
try:
|
try:
|
||||||
when declared(testSetupIMPLFlag): testSetupIMPL()
|
when declared(testSetupIMPLFlag): testSetupIMPL()
|
||||||
when declared(testTeardownIMPLFlag):
|
|
||||||
defer: testTeardownIMPL()
|
|
||||||
block:
|
block:
|
||||||
body
|
body
|
||||||
|
|
||||||
|
@ -1126,6 +1124,15 @@ template runtimeTest*(nameParam: string, body: untyped) =
|
||||||
checkpoint("Unhandled exception that may cause undefined behavior: " & e.msg & " " & eTypeDesc)
|
checkpoint("Unhandled exception that may cause undefined behavior: " & e.msg & " " & eTypeDesc)
|
||||||
var stackTrace {.inject.} = e.getStackTrace()
|
var stackTrace {.inject.} = e.getStackTrace()
|
||||||
fail()
|
fail()
|
||||||
|
finally:
|
||||||
|
try:
|
||||||
|
when declared(testTeardownIMPLFlag):
|
||||||
|
testTeardownIMPL()
|
||||||
|
except Exception as e:
|
||||||
|
let eTypeDesc = "[" & $e.name & "]"
|
||||||
|
checkpoint("Exception when calling teardown: " & e.msg & " " & eTypeDesc)
|
||||||
|
var stackTrace {.inject.} = e.getStackTrace()
|
||||||
|
fail()
|
||||||
|
|
||||||
checkpoints = @[]
|
checkpoints = @[]
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue