* fix #16978 unittest js foreign exception
This commit is contained in:
parent
21e60b9a97
commit
fff5819ee7
2 changed files with 24 additions and 3 deletions
|
|
@ -515,7 +515,9 @@ template suite*(name, body) {.dirty.} =
|
||||||
finally:
|
finally:
|
||||||
suiteEnded()
|
suiteEnded()
|
||||||
|
|
||||||
template exceptionTypeName(e: typed): string = $e.name
|
proc exceptionTypeName(e: ref Exception): string {.inline.} =
|
||||||
|
if e == nil: "<foreign exception>"
|
||||||
|
else: $e.name
|
||||||
|
|
||||||
template test*(name, body) {.dirty.} =
|
template test*(name, body) {.dirty.} =
|
||||||
## Define a single test case identified by `name`.
|
## Define a single test case identified by `name`.
|
||||||
|
|
@ -552,8 +554,11 @@ template test*(name, body) {.dirty.} =
|
||||||
let e = getCurrentException()
|
let e = getCurrentException()
|
||||||
let eTypeDesc = "[" & exceptionTypeName(e) & "]"
|
let eTypeDesc = "[" & exceptionTypeName(e) & "]"
|
||||||
checkpoint("Unhandled exception: " & getCurrentExceptionMsg() & " " & eTypeDesc)
|
checkpoint("Unhandled exception: " & getCurrentExceptionMsg() & " " & eTypeDesc)
|
||||||
var stackTrace {.inject.} = e.getStackTrace()
|
if e == nil: # foreign
|
||||||
fail()
|
fail()
|
||||||
|
else:
|
||||||
|
var stackTrace {.inject.} = e.getStackTrace()
|
||||||
|
fail()
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
if testStatusIMPL == TestStatus.FAILED:
|
if testStatusIMPL == TestStatus.FAILED:
|
||||||
|
|
|
||||||
16
tests/js/tunittest_error2.nim
Normal file
16
tests/js/tunittest_error2.nim
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
discard """
|
||||||
|
exitcode: 1
|
||||||
|
outputsub: '''
|
||||||
|
Unhandled exception: Cannot read property 'charCodeAt' of null [<foreign exception>]
|
||||||
|
[FAILED] Bad test
|
||||||
|
'''
|
||||||
|
matrix: "-d:nodejs"
|
||||||
|
targets: "js"
|
||||||
|
joinable: false
|
||||||
|
"""
|
||||||
|
|
||||||
|
# bug #16978
|
||||||
|
import unittest
|
||||||
|
test "Bad test":
|
||||||
|
var x: cstring = nil
|
||||||
|
let y = x[0]
|
||||||
Loading…
Add table
Add a link
Reference in a new issue