Skip to content

Commit

Permalink
1.0.0: break the check api
Browse files Browse the repository at this point in the history
  • Loading branch information
disruptek committed Jan 8, 2021
1 parent 1063bab commit d9db2ad
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 16 deletions.
2 changes: 1 addition & 1 deletion docs/clean.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/demo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion examples/balls.nim
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ testes:

block:
## check a list of statements in a block
check:
check "r should be 4":
r < 5
r > 3

Expand Down
25 changes: 15 additions & 10 deletions testes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -236,16 +236,21 @@ proc checkOne(condition: NimNode; message: NimNode): NimNode =
newCall(ident"newException", assertion, message)
result = newIfStmt (newCall(ident"not", condition), clause)

macro check*(body: untyped; message = "") =
## Check one or more expressions (in a block); raises an AssertionDefect
## in the event that the expression is `false` regardless of `assertions`
## settings. Optionally specify a custom message a la `assert`.
if body.kind == nnkStmtList:
result = newStmtList()
for child in body.items:
result.add: checkOne(child, message)
else:
result = checkOne(body, message)
macro check*(body: bool; message: string = "") =
## Check a single expression; raises an AssertionDefect in the event
## that the expression is `false` regardless of `assertions` settings.
## Specify a custom `message` a la `assert`.
result = checkOne(body, message)

macro check*(message: string; body: untyped) =
## Check one or more expressions in a block; raises an AssertionDefect
## in the event that an expression is `false` regardless of `assertions`
## settings. Specify a custom `message` a la `assert`.
body.expectKind nnkStmtList
result = newStmtList()
for child in body.items:
result.add:
newCall(bindSym"check", child, message)

proc `status=`(t: var Test; s: StatusKind) {.used.} =
system.`=`(t.status, max(t.status, s))
Expand Down
4 changes: 2 additions & 2 deletions testes.nimble
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
version = "0.10.0"
version = "1.0.0"
author = "disruptek"
description = "a cure for salty testes"
license = "MIT"
requires "nim >= 1.0.4"

#requires "cligen >= 0.9.41 & <= 0.9.45"
#requires "bump >= 1.8.18 & < 2.0.0"
requires "https://github.com/disruptek/grok >= 0.0.4 & < 1.0.0"
Expand Down
2 changes: 1 addition & 1 deletion tests/testicles.nim
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ suite "a pretty suite shim":

block:
## check a list of statements in a block
check:
check "something failed":
r < 5
r > 3

Expand Down

0 comments on commit d9db2ad

Please sign in to comment.