123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- import std/asyncdispatch
- import std/re
- from std/strutils import dedent
- proc err() =
- raise newException(ValueError, "the_error_msg")
- block:
- proc recursion(i: int) {.async.} =
- if i == 5:
- err()
- await sleepAsync(1)
- await recursion(i+1)
- proc main {.async.} =
- await recursion(0)
- try:
- waitFor main()
- doAssert false
- except ValueError as err:
- let expected = """
- the_error_msg
- Async traceback:
- tasync_traceback2\.nim\(\d+\) tasync_traceback2
- tasync_traceback2\.nim\(\d+\) main \(Async\)
- tasync_traceback2\.nim\(\d+\) recursion \(Async\)
- tasync_traceback2\.nim\(\d+\) recursion \(Async\)
- tasync_traceback2\.nim\(\d+\) err
- Exception message: the_error_msg
- """.dedent
- doAssert match(err.msg, re(expected)), err.getStackTrace & err.msg
- block:
- proc baz() =
- err()
- proc bar() =
- baz()
- proc foo() {.async.} =
- await sleepAsync(1)
- bar()
- proc main {.async.} =
- await foo()
- try:
- waitFor main()
- doAssert false
- except ValueError as err:
- let expected = """
- the_error_msg
- Async traceback:
- tasync_traceback2\.nim\(\d+\) tasync_traceback2
- tasync_traceback2\.nim\(\d+\) main \(Async\)
- tasync_traceback2\.nim\(\d+\) foo \(Async\)
- tasync_traceback2\.nim\(\d+\) bar
- tasync_traceback2\.nim\(\d+\) baz
- tasync_traceback2\.nim\(\d+\) err
- Exception message: the_error_msg
- """.dedent
- doAssert match(err.msg, re(expected)), err.getStackTrace & err.msg
- block: # async work
- proc baz() {.async.} =
- await sleepAsync(1)
- raise newException(ValueError, "the_error_msg")
- proc bar() {.async.} =
- await sleepAsync(1)
- await baz()
- proc foo() {.async.} =
- await sleepAsync(1)
- await bar()
- proc main {.async.} =
- await foo()
- try:
- waitFor main()
- doAssert false
- except ValueError as err:
- let expected = """
- the_error_msg
- Async traceback:
- tasync_traceback2\.nim\(\d+\) tasync_traceback2
- tasync_traceback2\.nim\(\d+\) main \(Async\)
- tasync_traceback2\.nim\(\d+\) foo \(Async\)
- tasync_traceback2\.nim\(\d+\) bar \(Async\)
- tasync_traceback2\.nim\(\d+\) baz \(Async\)
- Exception message: the_error_msg
- """.dedent
- doAssert match(err.msg, re(expected)), err.getStackTrace & err.msg
- block: # interleaved async work
- proc baz() {.async.} =
- await sleepAsync(1)
- raise newException(ValueError, "the_error_msg")
- proc bar() {.async.} =
- #await sleepAsync(1)
- await baz()
- proc foo() {.async.} =
- await sleepAsync(1)
- await bar()
- proc main {.async.} =
- await foo()
- try:
- waitFor main()
- doAssert false
- except ValueError as err:
- let expected = """
- the_error_msg
- Async traceback:
- tasync_traceback2\.nim\(\d+\) tasync_traceback2
- tasync_traceback2\.nim\(\d+\) main \(Async\)
- tasync_traceback2\.nim\(\d+\) foo \(Async\)
- tasync_traceback2\.nim\(\d+\) bar \(Async\)
- tasync_traceback2\.nim\(\d+\) baz \(Async\)
- Exception message: the_error_msg
- """.dedent
- doAssert match(err.msg, re(expected)), err.getStackTrace & err.msg
- block: # no async work
- proc baz() {.async.} =
- raise newException(ValueError, "the_error_msg")
- proc bar() {.async.} =
- await baz()
- proc foo() {.async.} =
- await bar()
- proc main {.async.} =
- await foo()
- try:
- waitFor main()
- doAssert false
- except ValueError as err:
- let expected = """
- the_error_msg
- Async traceback:
- tasync_traceback2\.nim\(\d+\) tasync_traceback2
- tasync_traceback2\.nim\(\d+\) main \(Async\)
- tasync_traceback2\.nim\(\d+\) foo \(Async\)
- tasync_traceback2\.nim\(\d+\) bar \(Async\)
- tasync_traceback2\.nim\(\d+\) baz \(Async\)
- Exception message: the_error_msg
- """.dedent
- doAssert match(err.msg, re(expected)), err.getStackTrace & err.msg
- echo "ok"
|