Added: type name output when exception raised from unittest (#7869)
This commit is contained in:
parent
21fb0db6e2
commit
b6b6382e0b
3 changed files with 19 additions and 3 deletions
|
|
@ -76,6 +76,8 @@
|
||||||
- The `terminal` module now exports additional procs for generating ANSI color
|
- The `terminal` module now exports additional procs for generating ANSI color
|
||||||
codes as strings.
|
codes as strings.
|
||||||
- Added the parameter ``val`` for the ``CritBitTree[int].inc`` proc.
|
- Added the parameter ``val`` for the ``CritBitTree[int].inc`` proc.
|
||||||
|
- An exception raised from ``test`` block of ``unittest`` now show its type in
|
||||||
|
error message
|
||||||
|
|
||||||
### Language additions
|
### Language additions
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -462,6 +462,8 @@ template suite*(name, body) {.dirty.} =
|
||||||
finally:
|
finally:
|
||||||
suiteEnded()
|
suiteEnded()
|
||||||
|
|
||||||
|
template exceptionTypeName(e: typed): string = $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`.
|
||||||
##
|
##
|
||||||
|
|
@ -476,7 +478,7 @@ template test*(name, body) {.dirty.} =
|
||||||
## .. code-block::
|
## .. code-block::
|
||||||
##
|
##
|
||||||
## [OK] roses are red
|
## [OK] roses are red
|
||||||
bind shouldRun, checkpoints, formatters, ensureInitialized, testEnded
|
bind shouldRun, checkpoints, formatters, ensureInitialized, testEnded, exceptionTypeName
|
||||||
|
|
||||||
ensureInitialized()
|
ensureInitialized()
|
||||||
|
|
||||||
|
|
@ -495,8 +497,10 @@ template test*(name, body) {.dirty.} =
|
||||||
|
|
||||||
except:
|
except:
|
||||||
when not defined(js):
|
when not defined(js):
|
||||||
checkpoint("Unhandled exception: " & getCurrentExceptionMsg())
|
let e = getCurrentException()
|
||||||
var stackTrace {.inject.} = getCurrentException().getStackTrace()
|
let eTypeDesc = "[" & exceptionTypeName(e) & "]"
|
||||||
|
checkpoint("Unhandled exception: " & getCurrentExceptionMsg() & " " & eTypeDesc)
|
||||||
|
var stackTrace {.inject.} = e.getStackTrace()
|
||||||
fail()
|
fail()
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
|
|
|
||||||
10
tests/stdlib/tunittestexceptiontype.nim
Normal file
10
tests/stdlib/tunittestexceptiontype.nim
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
discard """
|
||||||
|
exitcode: 1
|
||||||
|
outputsub: '''exception type is [ValueError]'''
|
||||||
|
"""
|
||||||
|
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
suite "exception from test":
|
||||||
|
test "show exception type":
|
||||||
|
raise newException(ValueError, "exception type is")
|
||||||
Loading…
Add table
Add a link
Reference in a new issue