diff --git a/docs/clean.svg b/docs/clean.svg index 551caba..cf12a15 100644 --- a/docs/clean.svg +++ b/docs/clean.svg @@ -43,5 +43,5 @@ - 🟢 this is a test of goats## 1 +224 Bytes 9.7μs🟢 a test of pigs## 2 +112 Bytes 3.3μs🟢 var r = 3🟢 sometimes the wolf is nice## 3 +240 Bytes 3.0μs🟢 unnamed block## 4 +112 Bytes 2.6μs🟢 block:🟢 discard "unnamed test"## 5 +248 Bytes 3.3μs🟢 check a list of statements in a block## 6 +352 Bytes 3.5μs🟢 inc r## 7 +192 Bytes 2.8μs🟢 check r > 0## 8 +112 Bytes 2.6μs## this is a nice comment🟢 type🟢 TypesAreNotTests = bool## there's really nothing else to say🟢 const🟢 VariablesDefinedOutsideBlocksAreNotTests = true🟢 a test: block is fine## 9 +128 Bytes 2.8μsomission: skipped## 10 +120 Bytes 5.0μsomitted: i just don't wanna## 11 +200 Bytes 4.0μs🟢 assert "any statement is a test" != ""## 12 +256 Bytes 3.3μs🟢 check r > 0, $r & " is a good test of dynamic messages"## 13 +288 Bytes 4.2μs## report for expression expansion: ## StmtListExpr## Empty## Prefix## Sym "not"## Infix## Sym "=="## Sym "r"## IntLit 5🟢 report "report for expression expansion:", r != 5## 14 +184 Bytes 10.9μsbut checkpoint behaves as it does in unittest: true🟢 checkpoint "but checkpoint behaves as it does in unittest: ", r == 5## 15 +344 Bytes 5.7μsyou love to see it🟢 great expectations## 16 +296 Bytes 5.4μs## 16 tests 🟢14 ❔2 + 🟢 this is a test of goats## 1 +224 Bytes 9.5μs🟢 a test of pigs## 2 +112 Bytes 2.8μs🟢 var r = 3🟢 sometimes the wolf is nice## 3 +240 Bytes 3.0μs🟢 unnamed block## 4 +112 Bytes 2.3μs🟢 block:🟢 discard "unnamed test"## 5 +248 Bytes 3.3μs🟢 check a list of statements in a block## 6 +352 Bytes 3.0μs🟢 inc r## 7 +192 Bytes 3.0μs🟢 check r > 0## 8 +112 Bytes 3.0μs## this is a nice comment🟢 type🟢 TypesAreNotTests = bool## there's really nothing else to say🟢 const🟢 VariablesDefinedOutsideBlocksAreNotTests = true🟢 a test: block is fine## 9 +128 Bytes 3.0μsomission: skipped## 10 +120 Bytes 5.4μsomitted: i just don't wanna## 11 +200 Bytes 4.5μs🟢 assert "any statement is a test" != ""## 12 +256 Bytes 3.0μs🟢 check r > 0, $r & " is a good test of dynamic messages"## 13 +288 Bytes 3.8μs## report for expression expansion: ## StmtListExpr## Empty## Prefix## Sym "not"## Infix## Sym "=="## Sym "r"## IntLit 5🟢 report "report for expression expansion:", r != 5## 14 +184 Bytes 11.9μsbut checkpoint behaves as it does in unittest: true🟢 checkpoint "but checkpoint behaves as it does in unittest: ", r == 5## 15 +344 Bytes 4.2μsyou love to see it🟢 great expectations## 16 +296 Bytes 4.0μs## 16 tests 🟢14 ❔2 \ No newline at end of file diff --git a/docs/demo.svg b/docs/demo.svg index 07c0309..502f150 100644 --- a/docs/demo.svg +++ b/docs/demo.svg @@ -43,5 +43,5 @@ - 🟢 this is a test of goats🟢 a test of pigs var r = 3🟢 sometimes the wolf is nice💥 sheepies: ValueError: you're terrible💥 🗏 20 block sheepies:💥 🗏 21 raise newException(ValueError, "you\'re terrible")💥 🗇 examples/balls.nim💥 🗇 21 raise newException(ValueError, "you're terrible") # balls()🔴 checking some things: r == 3🔴 🗏 23 block check_r:🔴 🗏 24 ## checking some things🔴 🗏 25 ## this block exists only to test inclusion of🔴 🗏 26 ## comments in the test code display...🔴 🗏 27 check r == 3🔴 🗏 28 echo r🟢 check a list of statements in a block🟢 unnamed block🟢 block:🟢 discard "unnamed test"🟢 inc r🟢 assert r > 0## this is a nice comment type TypesAreNotTests = bool## there's really nothing else to say const VariablesDefinedOutsideBlocksAreNotTests = true🟢 a test: block is fineomission: skippedbroken: compile failed⛔ 🗏 69 block:⛔ 🗏 70 proc broken() =⛔ 🗏 71 doesnt(compile)⛔ 🗏 72 ## 26 tests 🟢9 ❔1 🔴1 💥1 ⛔1🟢 hide this gory when statement🔴 assertions: /home/adavidoff/git/testes/examples/balls.nim(74, 12) `2 != 4 div 2` 🔴 🗏 72 block assertions:🔴 🗏 73 assert 2 == 4 div 2🔴 🗏 74 assert 2 != 4 div 2omitted: i just don't wanna🟢 assert "any statement is a test" != ""🟢 check r > 0, $r & " is a good test of dynamic messages"## report for expression expansion: ## StmtListExpr## Empty## Prefix## Sym "not"## Infix## Sym "=="## Sym "r"## IntLit 5🟢 report "report for expression expansion:", r != 5but checkpoint behaves as it does in unittest: true🟢 checkpoint "but checkpoint behaves as it does in unittest: ", r == 5🔴 explicit failure: this looks bad🔴 🗏 85 block explicit_failure:🔴 🗏 86 fail("this looks bad")🔴 check with message: empty strings are STILL too long🔴 🗏 88 block check_with_message:🔴 🗏 89 let x = 0🔴 🗏 90 check "".len < x, "empty strings are STILL too long"you love to see it🟢 great expectationshere comes trouble💥 unmet expectations: ExpectedError: expected ValueError exception💥 🗏 97 block unmet_expectations:💥 🗏 98 expect ValueError:💥 🗏 99 checkpoint "here comes trouble"💥 🗇 testes.nim💥 🗇 440 raise newException(ExpectedError, # balls()🔴 dashed expectations: the truth hurts, but not as much as the false🔴 🗏 101 block dashed_expectations:🔴 🗏 102 expect ValueError:🔴 🗏 103 check false, "the truth hurts, but not as much as the false"## 24 tests 🟢15 ❔2 🔴5 💥2 ⛔1 + 🟢 this is a test of goats🟢 a test of pigs var r = 3🟢 sometimes the wolf is nice💥 sheepies: ValueError: you're terrible💥 🗏 20 block sheepies:💥 🗏 21 raise newException(ValueError, "you\'re terrible")💥 🗇 examples/balls.nim💥 🗇 21 raise newException(ValueError, "you're terrible") # balls()🔴 checking some things: r == 3🔴 🗏 23 block check_r:🔴 🗏 24 ## checking some things🔴 🗏 25 ## this block exists only to test inclusion of🔴 🗏 26 ## comments in the test code display...🔴 🗏 27 check r == 3🔴 🗏 28 echo r🟢 check a list of statements in a block🟢 unnamed block🟢 block:🟢 discard "unnamed test"🟢 inc r🟢 assert r > 0## this is a nice comment type TypesAreNotTests = bool## there's really nothing else to say const VariablesDefinedOutsideBlocksAreNotTests = true🟢 a test: block is fineomission: skippedbroken: compile failed⛔ 🗏 69 block:⛔ 🗏 70 proc broken() =⛔ 🗏 71 doesnt(compile)⛔ 🗏 72 ## 26 tests 🟢9 ❔1 🔴1 💥1 ⛔1🟢 hide this gory when statement🔴 assertions: /home/adavidoff/git/testes/examples/balls.nim(74, 12) `2 != 4 div 2` 🔴 🗏 72 block assertions:🔴 🗏 73 assert 2 == 4 div 2🔴 🗏 74 assert 2 != 4 div 2omitted: i just don't wanna🟢 assert "any statement is a test" != ""🟢 check r > 0, $r & " is a good test of dynamic messages"## report for expression expansion: ## StmtListExpr## Empty## Prefix## Sym "not"## Infix## Sym "=="## Sym "r"## IntLit 5🟢 report "report for expression expansion:", r != 5but checkpoint behaves as it does in unittest: true🟢 checkpoint "but checkpoint behaves as it does in unittest: ", r == 5🔴 explicit failure: this looks bad🔴 🗏 85 block explicit_failure:🔴 🗏 86 fail("this looks bad")🔴 check with message: empty strings are STILL too long🔴 🗏 88 block check_with_message:🔴 🗏 89 let x = 0🔴 🗏 90 check "".len < x, "empty strings are STILL too long"you love to see it🟢 great expectationshere comes trouble💥 unmet expectations: ExpectedError: expected ValueError exception💥 🗏 97 block unmet_expectations:💥 🗏 98 expect ValueError:💥 🗏 99 checkpoint "here comes trouble"💥 🗇 testes.nim💥 🗇 475 raise newException(ExpectedError, # balls()🔴 dashed expectations: the truth hurts, but not as much as the false🔴 🗏 101 block dashed_expectations:🔴 🗏 102 expect ValueError:🔴 🗏 103 check false, "the truth hurts, but not as much as the false"## 24 tests 🟢15 ❔2 🔴5 💥2 ⛔1 \ No newline at end of file diff --git a/examples/balls.nim b/examples/balls.nim index 5ad4cd5..973a9cf 100644 --- a/examples/balls.nim +++ b/examples/balls.nim @@ -29,7 +29,7 @@ testes: block: ## check a list of statements in a block - check: + check "r should be 4": r < 5 r > 3 diff --git a/testes.nim b/testes.nim index d324b8d..cb35b16 100644 --- a/testes.nim +++ b/testes.nim @@ -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)) diff --git a/testes.nimble b/testes.nimble index 8e8ab8e..60fe1d5 100644 --- a/testes.nimble +++ b/testes.nimble @@ -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" diff --git a/tests/testicles.nim b/tests/testicles.nim index 01a2cf9..0961844 100644 --- a/tests/testicles.nim +++ b/tests/testicles.nim @@ -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