Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheecour committed Nov 12, 2020
1 parent acc6848 commit e22d1f4
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/stdlib/tassertions.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
discard """
targets: "c cpp js"
"""

template main =
doAssertRaises(ValueError): raise newException(ValueError, "foo")
doAssertRaises(ValueError, block: raise newException(ValueError, "foo"))
static: main()
main()

when defined(cpp) or defined(js):
when defined(cpp):
{.emit:"""
#include <stdexcept>
void fn(){throw std::runtime_error("asdf");}""".}
proc fn(){.importcpp.}
else:
{.emit:"""
function fn(){ throw 42;} """.}
proc fn(){.importc.}

var witness = false
try:
doAssertRaises(ValueError): fn()
except AssertionDefect:
witness = true
doAssert witness
doAssertRaises: fn()
doAssertRaises(block: fn())

0 comments on commit e22d1f4

Please sign in to comment.