diff --git a/docs/demo.svg b/docs/demo.svg index e3eabb1..c1f31ac 100644 --- a/docs/demo.svg +++ b/docs/demo.svg @@ -16,20 +16,20 @@ } :root { - --animation-duration: 10029ms; + --animation-duration: 10061ms; } @keyframes roll { 0.000%{transform:translateY(0px)} -0.150%{transform:translateY(-1054px)} -0.189%{transform:translateY(-2108px)} -0.209%{transform:translateY(-3162px)} -0.289%{transform:translateY(-4216px)} +0.477%{transform:translateY(-1054px)} +0.507%{transform:translateY(-2108px)} +0.527%{transform:translateY(-3162px)} +0.606%{transform:translateY(-4216px)} 100.000%{transform:translateY(-4216px)} } #screen_view { - animation-duration: 10029ms; + animation-duration: 10061ms; animation-iteration-count:infinite; animation-name:roll; animation-timing-function: steps(1,end); @@ -64,5 +64,5 @@ - Hint: used config file '/home/adavidoff/nims/config/nim.cfg' [Conf]Hint: used config file '/home/adavidoff/nims/config/config.nims' [Conf]Hint: used config file '/home/adavidoff/git/testes/nim.cfg' [Conf] Hint: 7694 lines; 0.016s; 12.242MiB peakmem; Debug build; proj: /home/adavidoff/git/testes/tests/testicles.nim; out: /home/adavidoff/git/testes/bin/testicles [SuccessX]Hint: /home/adavidoff/git/testes/bin/testicles [Exec]🟢 this is a test of goats🟢 a test of pigs⚫ var r = 3🟢 sometimes the wolf is nice💥 sheepies: ValueError: you're terrible💥 🗏 23 block sheepies:💥 🗏 24 raise newException(ValueError, "you\'re terrible")💥 🗇 tests/testicles.nim💥 🗇 24 raise newException(ValueError, "you're terrible") # in testicles()r == 3 = false🔴 checking some things🔴 🗏 26 block check_r:🔴 🗏 27 ## checking some things🔴 🗏 28 ## this block exists only to test inclusion of🔴 🗏 29 ## comments in the test code display...🔴 🗏 30 check r == 3🔴 🗏 31 dump r🔴 🗏 🔴 🗏 32 check r == 2🔴 🗇 testes.nim🔴 🗇 93 raise newException(AssertionDefect, "check failed") # in testicl🟢 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 fine🟢 ⚪ omission: skippedbroken: compile failed⛔ 🗏 67 block:⛔ 🗏 68 proc broken() =⛔ 🗏 69 doesnt(compile)⛔ 🗏 70 🟢 hide this gory when statement🔴 assertions🔴 🗏 70 🔴 🗏 70 block assertions:🔴 🗏 71 assert 2 == 4 div 2🔴 🗏 72 assert 2 != 4 div 2🔴 🗇 tests/testicles.nim🔴 🗇 72 assert 2 != 4 div 2 # in testicles()🔴 🗇 ../../nims/lib/system/assertions.nim🔴 🗇 30 cast[Hide](raiseAssert)(msg) # in failedAssertImpl()🔴 🗇 23 sysFatal(AssertionDefect, msg) # in raiseAssert()🔴 🗇 ../../nims/lib/system/fatal.nim🔴 🗇 49 raise (ref exceptn)(msg: message) # in sysFatal()🟢 assert "any statement is a test" != "" + Hint: used config file '/home/adavidoff/nims/config/nim.cfg' [Conf]Hint: used config file '/home/adavidoff/git/testes/nim.cfg' [Conf]Hint: used config file '/home/adavidoff/git/testes/tests/config.nims' [Conf] Hint: operation successful (7777 lines compiled; 0.016 sec total; 10.195MiB peakmem; Debug Build) [SuccessX]Hint: /home/adavidoff/git/testes/bin/balls [Exec]🟢 this is a test of goats🟢 a test of pigs⚫ var r = 3🟢 sometimes the wolf is nice💥 sheepies: ValueError: you're terrible💥 🗏 22 block sheepies:💥 🗏 23 raise newException(ValueError, "you\'re terrible")💥 🗇 tests/balls.nim💥 🗇 23 raise newException(ValueError, "you're terrible") # in balls()r == 3 = false🔴 checking some things: check failed🔴 🗏 25 block check_r:🔴 🗏 26 ## checking some things🔴 🗏 27 ## this block exists only to test inclusion of🔴 🗏 28 ## comments in the test code display...🔴 🗏 29 check r == 3🔴 🗏 30 dump r🔴 🗏 31 check r == 2🟢 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 fine🟢 ⚪ omission: skippedbroken: compile failed⛔ 🗏 66 block:⛔ 🗏 67 proc broken() =⛔ 🗏 68 doesnt(compile)⛔ 🗏 69 🟢 hide this gory when statement🔴 assertions: /home/adavidoff/git/testes/tests/balls.nim(71, 14) `2 != 4 div 2` 🔴 🗏 69 block assertions:🔴 🗏 69 block assertions:🔴 🗏 70 assert 2 == 4 div 2🔴 🗏 71 assert 2 != 4 div 2🟢 assert "any statement is a test" != "" \ No newline at end of file diff --git a/docs/testes.html b/docs/testes.html index 98c3b47..58f3b7d 100644 --- a/docs/testes.html +++ b/docs/testes.html @@ -18,7 +18,772 @@ testes - + @@ -33,28 +798,6 @@ event.target.parentNode.nextElementSibling.style.display = "inline"; } } - - const toggleSwitch = document.querySelector('.theme-switch input[type="checkbox"]'); - function switchTheme(e) { - if (e.target.checked) { - document.documentElement.setAttribute('data-theme', 'dark'); - localStorage.setItem('theme', 'dark'); - } else { - document.documentElement.setAttribute('data-theme', 'light'); - localStorage.setItem('theme', 'light'); - } - } - - toggleSwitch.addEventListener('change', switchTheme, false); - - const currentTheme = localStorage.getItem('theme') ? localStorage.getItem('theme') : null; - if (currentTheme) { - document.documentElement.setAttribute('data-theme', currentTheme); - - if (currentTheme === 'dark') { - toggleSwitch.checked = true; - } - } } @@ -65,18 +808,8 @@

testes

-
- -     Dark Mode -
@@ -167,7 +900,7 @@

Templates

diff --git a/testes.nim b/testes.nim index e05a42c..d391a7a 100644 --- a/testes.nim +++ b/testes.nim @@ -1,13 +1,17 @@ import std/os import std/sequtils -import std/exitprocs import std/terminal import std/sugar import std/strutils import std/macros -import std/compilesettings import std/colors +when (NimMajor, NimMinor) >= (1, 3): + import std/exitprocs +else: + proc setProgramResult(q: int) = + programResult = q + import cutelog export sugar, strutils, macros, cutelog @@ -90,7 +94,10 @@ const template check*(body: typed) = if not body: dump body - raise newException(AssertionDefect, "check failed") + when (NimMajor, NimMinor) >= (1, 3): + raise newException(AssertionDefect, "check failed") + else: + raise newException(AssertionError, "check failed") proc `status=`(t: var Test; s: StatusKind) = system.`=`(t.status, max(t.status, s)) @@ -128,14 +135,15 @@ proc success(t: var Test): NimNode = t.status = Okay result = t.output(successStyle & t.name & ansiResetCode) -proc countComments(n: NimNode): int = - assert not n.isNil - if n.kind == nnkStmtList: - for _ in items(n): - if _.kind == nnkCommentStmt: - result.inc len(_.strVal.splitLines()) - else: - break +when false: + proc countComments(n: NimNode): int = + assert not n.isNil + if n.kind == nnkStmtList: + for _ in items(n): + if _.kind == nnkCommentStmt: + result.inc len(_.strVal.splitLines()) + else: + break proc fromFileGetLine(file: string; line: int): string = let lines = toSeq lines(file) @@ -199,25 +207,30 @@ proc failure(t: var Test; n: NimNode = nil): NimNode = result = newStmtList() result.add t.output(failureStyle & t.name & ansiResetCode) result.add t.renderSource - {.warning: "due to nim bug #15160, we have to leave this in!".} - if not n.isNil: - result.add t.renderTrace(n) + result.add t.renderTrace(n) result.add t.setExitCode +proc exceptionString(n: NimNode): NimNode = + assert not n.isNil + result = infix(infix(newCall(ident"$", newDotExpr(n, ident"name")), + "&", ": ".newLit), + "&", newDotExpr(n, ident"msg")) + proc badassert(t: var Test; n: NimNode = nil): NimNode = ## like failure(), but don't render the stack trace t.status = Fail result = newStmtList() - result.add t.output(t.name) + if n.isNil: + result.add t.output(failureStyle & t.name & ansiResetCode) + else: + result.add t.output(nestList(ident"&", newStmtList( + failureStyle.newLit, + t.name.newLit, newLit(": "), + newDotExpr(n, ident"msg"), + ansiResetCode.newLit))) result.add t.renderSource result.add t.setExitCode -proc exceptionString(n: NimNode): NimNode = - assert not n.isNil - result = infix(infix(newCall(ident"$", newDotExpr(n, ident"name")), - "&", ": ".newLit), - "&", newDotExpr(n, ident"msg")) - proc skipped(t: Test; n: NimNode): NimNode = assert not n.isNil result = newStmtList() @@ -237,7 +250,7 @@ proc exception(t: var Test; n: NimNode): NimNode = result.add t.renderTrace(n) result.add t.setExitCode -proc compilerr(t: var Test): NimNode = +proc compilerr(t: var Test): NimNode {.used.} = t.status = Oops result = newStmtList() result.add t.output(oopsStyle & t.name & ": compile failed" & ansiResetCode) @@ -249,37 +262,30 @@ proc skip*(msg = "skipped") = proc wrapExcept(t: var Test): NimNode = var skipping = bindSym"SkipError" - var assertion = bindSym"AssertionDefect" + when (NimMajor, NimMinor) >= (1, 3): + var assertion = bindSym"AssertionDefect" + else: + var assertion = bindSym"AssertionError" var catchall = bindSym"Exception" - var e1 = genSym(nskLet, "e") - var e2 = genSym(nskLet, "e") - var e3 = genSym(nskLet, "e") + var e1 {.used.} = genSym(nskLet, "e") + var e2 {.used.} = genSym(nskLet, "e") + var e3 {.used.} = genSym(nskLet, "e") result = nnkTryStmt.newTree(t.n, nnkExceptBranch.newTree(infix(skipping, "as", e1), t.skipped(e1)), - nnkExceptBranch.newTree(infix(assertion, "as", e2), t.failure(e2)), + nnkExceptBranch.newTree(infix(assertion, "as", e2), t.badassert(e2)), nnkExceptBranch.newTree(infix(catchall, "as", e3), t.exception(e3))) proc makeTest(n: NimNode; name: string): Test = assert not n.isNil result = Test(name: name, orig: n) - let beuno = genSym(nskLabel, "beuno") # all good, bro - let arrrg = genSym(nskLabel, "arrrg") # bad news, pal + let beuno {.used.} = genSym(nskLabel, "beuno") # all good, bro + let arrrg {.used.} = genSym(nskLabel, "arrrg") # bad news, pal result.n = copyNimTree(n).newStmtList if n.kind in testable: result.n.add result.success - when false: - # emit a success if we exited the block normally - n.add result.success - n.add nnkBreakStmt.newTree(arrrg) - result.n = nnkBlockStmt.newTree(beuno, n) - - # emit a failure if we broke out of the success block - result.n = nnkBlockStmt.newTree(arrrg, - newStmtList(result.n, result.failure)) - # wrap it to catch any exceptions result.n = result.wrapExcept else: @@ -320,12 +326,13 @@ proc rewriteTestBlock(n: NimNode): NimNode = let name = newCommentStmtNode(n[1].strVal) result = nnkBlockStmt.newTree(newEmptyNode(), newStmtList(name, n[2])) -proc shortenRepr(n: NimNode): string = - let splat = repr(n).splitLines - if len(splat) == 1: - result = splat[0] - else: - result = splat[0] & " ⮠..." +when false: + proc shortenRepr(n: NimNode): string = + let splat = repr(n).splitLines + if len(splat) == 1: + result = splat[0] + else: + result = splat[0] & " ⮠..." proc findName(n: NimNode; index: int): string = ## generate a name for a test block diff --git a/testes.nimble b/testes.nimble index 84f56c1..5f0af63 100644 --- a/testes.nimble +++ b/testes.nimble @@ -1,4 +1,4 @@ -version = "0.2.1" +version = "0.2.2" author = "disruptek" description = "a cure for salty testes" license = "MIT" diff --git a/tests/balls.nim b/tests/balls.nim index 457fa9d..c39b2d5 100644 --- a/tests/balls.nim +++ b/tests/balls.nim @@ -1,5 +1,4 @@ import std/os -import std/exitprocs import testes @@ -72,6 +71,3 @@ expandMacros: assert 2 != 4 div 2 assert "any statement is a test" != "" - -if getEnv("TRAVIS_COMPILER", "unlikely") != "unlikely": - setProgramResult QuitSuccess diff --git a/tests/testicles.nim b/tests/testicles.nim index d946117..c292f7f 100644 --- a/tests/testicles.nim +++ b/tests/testicles.nim @@ -1,5 +1,4 @@ import std/os -import std/exitprocs import testes