Skip to content

Commit

Permalink
doAssertRaises catch all
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheecour committed Nov 12, 2020
1 parent 1413818 commit acc6848
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
6 changes: 3 additions & 3 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@

- nodejs now supports osenv: `getEnv`, `putEnv`, `envPairs`, `delEnv`, `existsEnv`

- `doAssertRaises` now correctly handles foreign exceptions.
- `doAssertRaises` now correctly handles foreign exceptions;
it also allows a catch-all form that includes foreign exceptions.

## Language changes

- `nimscript` now handles `except Exception as e`
- The `cstring` doesn't support `[]=` operator in JS backend.


- The `cstring` doesn't support `[]=` operator in JS backend.

## Compiler changes

Expand Down
15 changes: 15 additions & 0 deletions lib/system/assertions.nim
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,18 @@ template doAssertRaises*(exception: typedesc, code: untyped) =
except: raisedForeign()
if wrong:
raiseAssert(begin & " nothing was raised" & msgEnd)

template doAssertRaises*(code: untyped) =
## Raises `AssertionDefect` if specified `code` does not raise anything,
## including a foreign exception.
## Example:
##
## .. code-block:: nim
## doAssertRaises: raise newException(ValueError, "Hello World")
var wrong = false
try:
if true: code
wrong = true
except: discard
if wrong:
raiseAssert("nothing was raised by: " & astToStr(code))

0 comments on commit acc6848

Please sign in to comment.