diff --git a/README.md b/README.md index cf85545..6b1f5f8 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ Because `testament` and `testutils` are going nowhere fast. ## Goals +- we expect everything to work; any statement is a test - better stack traces and test source output - less magical syntax and less output omission - aim to run many cheap tests in fewer files @@ -33,14 +34,16 @@ expandMacros: block goats: ## this is a test of goats + discard block pigs: ## a test of pigs + discard var r = 3 block sometimes_the_wolf_is_nice: - break + assert true inc r block sheepies: @@ -61,7 +64,7 @@ expandMacros: block: discard "unnamed test" - test "a test: block": + test "a test: block is fine": discard block omission: @@ -84,6 +87,8 @@ expandMacros: block assertions: assert 2 == 4 div 2 assert 2 != 4 div 2 + + assert "any statement is a test" != "" ``` ![demonstration](docs/demo.svg "demonstration") diff --git a/docs/demo.svg b/docs/demo.svg index a3bcb1b..568d08e 100644 --- a/docs/demo.svg +++ b/docs/demo.svg @@ -16,59 +16,62 @@ } :root { - --animation-duration: 10661ms; + --animation-duration: 10629ms; } @keyframes roll { 0.000%{transform:translateY(0px)} -0.872%{transform:translateY(-1054px)} -0.910%{transform:translateY(-2108px)} -0.976%{transform:translateY(-3162px)} -0.985%{transform:translateY(-4216px)} -1.051%{transform:translateY(-5270px)} -1.060%{transform:translateY(-6324px)} -1.285%{transform:translateY(-7378px)} -1.313%{transform:translateY(-8432px)} -2.645%{transform:translateY(-9486px)} -2.655%{transform:translateY(-10540px)} -2.664%{transform:translateY(-11594px)} -2.748%{transform:translateY(-12648px)} -2.758%{transform:translateY(-13702px)} -3.358%{transform:translateY(-14756px)} -3.386%{transform:translateY(-15810px)} -3.414%{transform:translateY(-16864px)} -3.424%{transform:translateY(-17918px)} -3.461%{transform:translateY(-18972px)} -3.499%{transform:translateY(-20026px)} -3.593%{transform:translateY(-21080px)} -3.668%{transform:translateY(-22134px)} -3.968%{transform:translateY(-23188px)} -3.996%{transform:translateY(-24242px)} -4.024%{transform:translateY(-25296px)} -4.033%{transform:translateY(-26350px)} -4.249%{transform:translateY(-27404px)} -4.259%{transform:translateY(-28458px)} -4.352%{transform:translateY(-29512px)} -4.380%{transform:translateY(-30566px)} -4.446%{transform:translateY(-31620px)} -4.531%{transform:translateY(-32674px)} -4.671%{transform:translateY(-33728px)} -4.803%{transform:translateY(-34782px)} -5.000%{transform:translateY(-35836px)} -5.178%{transform:translateY(-36890px)} -5.393%{transform:translateY(-37944px)} -5.506%{transform:translateY(-38998px)} -5.619%{transform:translateY(-40052px)} -5.731%{transform:translateY(-41106px)} -5.844%{transform:translateY(-42160px)} -5.956%{transform:translateY(-43214px)} -6.088%{transform:translateY(-44268px)} -6.200%{transform:translateY(-45322px)} -100.000%{transform:translateY(-45322px)} +0.847%{transform:translateY(-1054px)} +0.884%{transform:translateY(-2108px)} +0.950%{transform:translateY(-3162px)} +0.960%{transform:translateY(-4216px)} +1.025%{transform:translateY(-5270px)} +1.035%{transform:translateY(-6324px)} +1.261%{transform:translateY(-7378px)} +1.289%{transform:translateY(-8432px)} +2.540%{transform:translateY(-9486px)} +2.550%{transform:translateY(-10540px)} +2.568%{transform:translateY(-11594px)} +2.653%{transform:translateY(-12648px)} +2.663%{transform:translateY(-13702px)} +3.236%{transform:translateY(-14756px)} +3.274%{transform:translateY(-15810px)} +3.283%{transform:translateY(-16864px)} +3.293%{transform:translateY(-17918px)} +3.302%{transform:translateY(-18972px)} +3.349%{transform:translateY(-20026px)} +3.387%{transform:translateY(-21080px)} +3.472%{transform:translateY(-22134px)} +3.481%{transform:translateY(-23188px)} +3.556%{transform:translateY(-24242px)} +3.566%{transform:translateY(-25296px)} +3.839%{transform:translateY(-26350px)} +3.867%{transform:translateY(-27404px)} +3.895%{transform:translateY(-28458px)} +3.904%{transform:translateY(-29512px)} +4.102%{transform:translateY(-30566px)} +4.121%{transform:translateY(-31620px)} +4.158%{transform:translateY(-32674px)} +4.309%{transform:translateY(-33728px)} +4.347%{transform:translateY(-34782px)} +4.469%{transform:translateY(-35836px)} +4.582%{transform:translateY(-36890px)} +4.695%{transform:translateY(-37944px)} +4.817%{transform:translateY(-38998px)} +4.939%{transform:translateY(-40052px)} +5.080%{transform:translateY(-41106px)} +5.184%{transform:translateY(-42160px)} +5.297%{transform:translateY(-43214px)} +5.419%{transform:translateY(-44268px)} +5.541%{transform:translateY(-45322px)} +5.664%{transform:translateY(-46376px)} +5.795%{transform:translateY(-47430px)} +5.918%{transform:translateY(-48484px)} +100.000%{transform:translateY(-48484px)} } #screen_view { - animation-duration: 10661ms; + animation-duration: 10629ms; animation-iteration-count:infinite; animation-name:roll; animation-timing-function: steps(1,end); @@ -103,5 +106,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]. .. ... .... ........ ......... ........... ............ ............. .............. ............... ................ ................. ................... .................... ...................... ....................... ........................ ......................... .......................... ............................ .............................. ............................... ................................ ................................. .................................. ................................../home/adavidoff/git/testes/testes.nim(66, 6) Hint: 'findWhere' is declared but not used [XDeclaredButNotUsed]/home/adavidoff/git/testes/testes.nim(44, 6) Hint: 'countComments' is declared but not used [XDeclaredButNotUsed]/home/adavidoff/git/testes/testes.nim(5, 11) /home/adavidoff/git/testes/testes.nim(5, 11) Warning: imported and not used: 'unittest' [UnusedImport] /home/adavidoff/git/testes/tests/testicles.nim(4, 3) template/generic instantiation of `testes` from here/home/adavidoff/git/testes/tests/testicles.nim(16, 11) Warning: unreachable code after 'return' statement or '{.noReturn.}' proc [UnreachableCode]/home/adavidoff/git/testes/tests/testicles.nim(14, 11) Warning: unreachable code/home/adavidoff/git/testes/tests/testicles.nim(4, 3) /home/adavidoff/git/testes/tests/testicles.nim(18, 11) Warning: unreachable codetry: block arrrg_17106043: block beuno_17106042: ## this is a test of goats report(["🟢 this is a test of goats"]) break arrrg_17106043 report(["🔴 this is a test of goats"]) report([" 🗏 "]) if not isatty(stdin): setProgramResult(1)except SkipError as e_17106083: report(["⚪ this is a test of goats: " & (`$`(e_17106083.name) & ": " & e_17106083.msg)])except AssertionDefect as e_17106083: report(["🔴 this is a test of goats"]) report([" 🗏 "]) if stackTraceAvailable(): renderStack(getStackTraceEntries(e_17106083)) if not isatty(stdin): setProgramResult(1)except Exception as e_17106083: report(["💥 this is a test of goats: " & (`$`(e_17106083.name) & ": " & e_1710 block arrrg_17106090: block beuno_17106089: ## a test of pigs report(["🟢 a test of pigs"]) break arrrg_17106090 report(["🔴 a test of pigs"])except SkipError as e_17106091: report(["⚪ a test of pigs: " & (`$`(e_17106091.name) & ": " & e_17106091.msg)])except AssertionDefect as e_17106091: report(["🔴 a test of pigs"]) renderStack(getStackTraceEntries(e_17106091))except Exception as e_17106091: report(["💥 a test of pigs: " & (`$`(e_17106091.name) & ": " & e_17106091.msg)report(["⚫ var r = 3"])var r = 3 block arrrg_17106106: block beuno_17106105: break inc r, 1 report(["🟢 sometimes the wolf is nice"]) break arrrg_17106106 report(["🔴 sometimes report(["🔴 sometimes the wolf is nice"]) report([" 🗏 1 break\n 🗏 2 inc r"])except SkipError as e_17106125: report(["⚪ sometimes the wolf is nice: " & (`$`(e_17106125.name) & ": " & e_17106125.msg)])except AssertionDefect as e_17106125: report(["🔴 sometimes the wolf is nice"]) report([" 🗏 1 break\n 🗏 2 inc r"]) renderStack(getStackTraceEntries(e_17106125))except Exception as e_17106125: report(["💥 sometimes the wolf is nice: " & (`$`(e_17106125.name) & ": " & e_1 block arrrg_17106127: block beuno_17106126: raise (ref ValueError)(msg: "you\'re terrible", parent: nil) report(["🟢 sheepies"]) break arrrg_1710 break arrrg_17106127 report(["🔴 sheepies"]) report([" 🗏 1 raise newException(ValueError, \"you\\\'re terrible\")"])except SkipError as e_17106128: report(["⚪ sheepies: " & (`$`(e_17106128.name) & ": " & e_17106128.msg)])except AssertionDefect as e_17106128: report(["🔴 sheepies"]) report([" 🗏 1 raise newException(ValueError, \"you\\\'re terrible\")"]) renderStack(getStackTraceEntries(e_17106128))except Exception as e_17106128: report(["💥 sheepies: " & (`$`(e_17106128.name) & ": " & e_17106128.msg)]) block arrrg_17106130: block beuno_17106129: ## checking some things ## this block exists only to test inclus ## this block exists only to test inclusion of ## comments in the test code display... if not (r == 3): debugEcho ["r == 3", " = ", r == 3] break debugEcho ["r", " = ", r] if not (r == 2): debugEcho ["r == 2", " = ", r == 2] report(["🟢 checking some things"]) break arrrg_17106130 report(["🔴 checking some things"]) report([" 🗏 1 ## this block exists only to test inclusion of\n 🗏 2 ## comments in the test code display...\n 🗏 3 check r == 3\n 🗏 4 dump r\n 🗏 5 check r == 2"])except SkipError as e_17106131: report(["⚪ checking some things: " & (`$`(e_17106131.name) & ": " & e_17106131.msg)])except AssertionDefect as e_17106131: report(["🔴 checking some things"]) report([" 🗏 1 ## this block exists only to test inclusion of\n 🗏 2 ## comments in the test code display...\n 🗏 3 check r == 3\n 🗏 4 dump r\n 🗏 5 check r == 2"]) if renderStack(getStackTraceEntries(e_17106131))except Exception as e_17106131: report(["💥 checking some things: " & (`$`(e_17106131.name) & ": " & e_1710613 block arrrg_17106133: block beuno_17106132: ## unnamed block discard report(["🟢 unnamed block"]) break arrrg_17106133 report(["🔴 unnamed block"]) report([" 🗏 1 discard"])except SkipError as e_17106134: report(["⚪ unnamed block: " & (`$`(e_17106134.name) & ": " & e_17106134.msg)])except AssertionDefect as e_17106134: re report(["🔴 unnamed block"]) report([" 🗏 1 discard"]) renderStack(getStackTraceEntries(e_17106134))except Exception as e_17106134: report(["💥 unnamed block: " & (`$`(e_17106134.name) & ": " & e_17106134.msg)] block arrrg_17106136: block beuno_17106135: discard "unnamed test" report(["🟢 test #7"]) break arrrg_17106136 report(["🔴 test #7"]) report([" 🗏 1 discard \"unnamed test\""])except SkipError as e_17106137: report(["⚪ test #7: " & (`$`(e_17106137.name) & ": " & e_17106137.msg)])except AssertionDefect as e_17106137: report(["🔴 test #7"]) report([" 🗏 1 discard \"unnamed test\""]) r renderStack(getStackTraceEntries(e_17106137))except Exception as e_17106137: report(["💥 test #7: " & (`$`(e_17106137.name) & ": " & e_17106137.msg)]) block arrrg_17106139: block beuno_17106138: ## a test: block report(["🟢 a test: block"]) break arrrg_17106139 report(["🔴 a test: block"])except SkipError as e_17106140: report(["⚪ a test: block: " & (`$`(e_17106140.name) & ": " & e_17106140.msg)]except AssertionDefect as e_17106140: report(["🔴 a test: block"]) renderStack(getStackTraceEntries(e_17106140)) setProgramRes except Exception as e_17106140: report(["💥 a test: block: " & (`$`(e_17106140.name) & ": " & e_17106140.msg)] block arrrg_17106142: block beuno_17106141: skip("skipped") report(["🟢 omission"]) break arrrg_17106142 report(["🔴 omission"]) report([" 🗏 1 skip()"])except SkipError as e_17106143: report(["⚪ omission: " & (`$`(e_17106143.name) & ": " & e_17106143.msg)])except AssertionDefect as e_17106143: report(["🔴 omission"]) report([" 🗏 1 skip()"]) renderStack(getStackTraceEntries(e_17106143))except Exception as e_17106143: report(["💥 omission: " & (`$`(e_17106143.name) & ": " & e_17106143.msg)]) report([" 🗏 report(["⚫ when defined(release):\n⚫ testes:\n⚫ const\n⚫ compile = true\n⚫ proc doesnt(c: bool) =\n⚫ if not c:\n⚫ raise\n⚫ \n⚫ block:\n⚫ proc fixed() =\n⚫ doesnt(compile)\n⚫ \n⚫ else:\n⚫ testes:\n⚫ block:\n⚫ proc broken() =\n⚫ doesnt(compile)\n⚫ "])report(["⛔ broken: compile failed"])report([" 🗏 1 proc broken() =\n 🗏 2 doesnt(compile)\n 🗏 3 "])if not isatty(stdin): setProgramResult(1) block arrrg_17106145: block beuno_17106144: const expr`gensym17 = "2 == 4 div 2" loc`gensym18 = ( filename: "/home/adavidoff/git/testes/tests/testicles.nim", line: 57, column: 13) ploc`gensym18 = "/home/adavidoff/git/testes/tests/testicles.nim(57, 14)" {.line: (fi {.line: (filename: "/home/adavidoff/git/testes/tests/testicles.nim", line: 57, column: 13).}: if false: failedAssertImpl("/home/adavidoff/git/testes/tests/testicles.nim(57, 14) `2 == 4 div 2` ") expr`gensym19 = "2 != 4 div 2" loc`gensym21 = ( filename: "/home/adavidoff/git/testes/tests/testicles.nim", line: 58, ploc`gensym21 = "/home/adavidoff/git/testes/tests/testicles.nim(58, 14)" line: 58, column: 13).}: if true: failedAssertImpl("/home/adavidoff/git/testes/tests/testicles.nim(58, 14) `2 != 4 div 2` ") report(["🟢 assertions"]) break arrrg_17106145 report(["🔴 assertions"]) report([" 🗏 1 assert 2 == 4 div 2\n 🗏 2 assert 2 != 4 div 2"])except SkipError as e_17106146: report(["⚪ assertions: report(["⚪ assertions: " & (`$`(e_17106146.name) & ": " & e_17106146.msg)])except AssertionDefect as e_17106146: report(["🔴 assertions"]) report([" 🗏 1 assert 2 == 4 div 2\n 🗏 2 assert 2 != 4 div 2"]) renderStack(getStackTraceEntries(e_17106146))except Exception as e_17106146: report(["💥 assertions: " & (`$`(e_17106146.name) & ": " & e_17106146.msg)])CC: stdlib_assertions.nimCC: stdlib_dollars.nimCC: stdlib_io.nimCC: stdlib_system.nimCC: stdlib_parseutils.nimCC: stdlib_unicode.nimCC: stdlib_strutils.nimCC: stdlib_pathnorm.nimCC: stdlib_times.nimCC: stdlib_os.nimCC: stdlib_exitprocs.nimCC: stdlib_strformat.nimCC: stdlib_terminal.nimCC: stdlib_streams.nimCC: stdlib_unittest.nimCC: stdl CC: stdlib_logging.nimCC: ../deps/cutelog/cutelog.nimCC: ../testes.nimCC: testicles.nimHint: 65520 lines; 0.621s; 75.941MiB peakmem; Debug build; proj: /home/adavidoff/git/testes/tests/testicles.nim; out: /home/adavidoff/git/testes/tests/testicles [SuccessX]Hint: /home/adavidoff/git/testes/tests/testicles [Exec]🟢 this is a test of goats🟢 a test of pigs⚫ var r = 3🔴 sometimes the wolf is nice 🗏 1 break 🗏 2 inc r💥 sheepies: ValueError: you're terrible 🗏 1 raise newException(ValueError, "you\'re terrible") 🗇 tests/testicles.nim 🗇 19 raise newException(ValueError, "you're terrible") # in testicles()r = 3r == 2 = false🔴 checking some things 🗏 1 ## this block exists only to test inclusion of 🗏 2 ## comments in the test code display... 🗏 3 check r == 3 🗏 4 dump r 🗏 5 check r == 2🟢 unnamed block🟢 test #7🟢 a test: block💣 skipping 💣 skipping is broken on C (not C++) backend due to a bug⚪ omission: SkipError: skipped⚫ when defined(release):⚫ testes:⚫ const⚫ compile = true⚫ proc doesnt(c: bool) =⚫ if not c:⚫ raise⚫ block:⚫ proc fixed() =⚫ doesnt(compile)⚫ else:⚫ proc broken() =⛔ broken: compile failed 🗏 1 proc broken() = 🗏 2 doesnt(compile) 🗏 3 🔴 assertions 🗏 1 assert 2 == 4 div 2 🗏 2 assert 2 != 4 div 2 🗇 58 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() + 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]. .. ... ...... ........ ......... ........... ............ ............. .............. ............... ................ ................. ................... .................... ..................... ...................... ....................... ........................ ......................... .......................... ........................... ............................ ............................. .............................. ............................... ................................ ................................. .................................. ................................../home/adavidoff/git/testes/testes.nim(164, 7) Hint: 'beuno' is declared but not used [XDeclaredButNotUsed]/home/adavidoff/git/testes/testes.nim(165, 7) Hint: 'arrrg' is declared but not /home/adavidoff/git/testes/testes.nim(66, 6) Hint: 'findWhere' is declared but not used [XDeclaredButNotUsed]/home/adavidoff/git/testes/testes.nim(251, 3) Hint: 'statements' is declared but not used [XDeclaredButNotUsed]/home/adavidoff/git/testes/testes.nim(44, 6) Hint: 'countComments' is declared but not used [XDeclaredButNotUsed]/home/adavidoff/git/testes/testes.nim(5, 11) Warning: /home/adavidoff/git/testes/testes.nim(5, 11) Warning: imported and not used: 'unittest' [UnusedImport]try: block goats: ## this is a test of goats discard report(["🟢 this is a test of goats"])except SkipError as e_17106047: report(["⚪ this is a test of goats: " & (`$`(e_17106047.name) & ": " & e_17106047.msg)])except AssertionDefect as e_17106047: report(["🔴 this is a test of goats"]) report([" 🗏 1 ## this is a test of goats\n 🗏 2 discard"]) if stackTraceAvailable(): renderStack(getStackTraceEntries(e_17106047)) if not isatty(stdin): setProgramResult(1)except Exception as e_17106047: report(["💥 this is a test of goats: " & (`$`(e_17106047.name) & ": " & e_1710 block pigs: ## a test of pigs report(["🟢 a test of pigs"])except SkipError as e_17106091: report(["⚪ a test of pigs: " & report(["⚪ a test of pigs: " & (`$`(e_17106091.name) & ": " & e_17106091.msg)])except AssertionDefect as e_17106091: report(["🔴 a test of pigs"]) report([" 🗏 1 ## a test of pigs\n 🗏 2 discard"]) renderStack(getStackTraceEntries(e_17106091))except Exception as e_17106091: report(["💥 a test of pigs: " & (`$`(e_17106091.name) & ": " & e_17106091.msg)report(["⚫ var r = 3"])var r = 3 block sometimes_the_wolf_is_nice: const expr`gensym2 = "true" loc`gensym3 = (filename: "/home/adavidoff/git/testes/tests/testicles.nim", line: 17, column: 13) ploc`gensym3 = "/home/adavidoff/git/testes/tests/testicles.nim(17, 14)" {.line: (filename: "/home/adavidoff/git/testes/tests/tes {.line: (filename: "/home/adavidoff/git/testes/tests/testicles.nim", line: 17, column: 13).}: if false: failedAssertImpl("/home/adavidoff/git/testes/tests/testicles.nim(17, 14) `true` ") inc r, 1 report(["🟢 sometimes the wolf is nice"])except SkipError as e_17106108: report(["⚪ sometimes the wolf is nice: " & (`$`(e_17106108.name) & ": " & e_17106108.msg)])except AssertionDefect as e_17106108: report(["🔴 sometimes the wolf is nice"]) report([" 🗏 1 assert true\n 🗏 2 inc r"]) renderStack(getStackTraceEntries(e_17106108))except Exception as e_17106108: report(["💥 sometimes the wolf is nice: " & (`$`(e_17106108.name) & ": " & e_1 block sheepies: raise (ref ValueError)(msg: "you\'re te (ref ValueError)(msg: "you\'re terrible", parent: nil) report(["🟢 sheepies"])except SkipError as e_17106112: report(["⚪ sheepies: " & (`$`(e_17106112.name) & ": " & e_17106112.msg)])except AssertionDefect as e_17106112: report(["🔴 sheepies"]) report([" 🗏 1 raise newException(ValueError, \"you\\\'re terrible\")"]) renderStack(getStackTraceEntries(e_17106112))except Exception as e_17106112: report(["💥 sheepies: " & (`$`(e_17106112.name) & ": " & e_17106112.msg)]) block check_r: ## checking some things ## this block exists only to test inclusion of ## comments in the test code display... if not (r == 3): debugEcho ["r == 3", " = ", r == 3] break debugEcho ["r", " = " debugEcho ["r", " = ", r] if not (r == 2): debugEcho ["r == 2", " = ", r == 2] report(["🟢 checking some things"])except SkipError as e_17106116: report(["⚪ checking some things: " & (`$`(e_17106116.name) & ": " & e_17106116.msg)])except AssertionDefect as e_17106116: report(["🔴 checking some things"]) report([" 🗏 1 ## checking some things\n 🗏 2 ## this block exists only to test inclusion of\n 🗏 3 ## comments in the test code display...\n 🗏 4 check r == 3\n 🗏 5 dump r\n 🗏 6 check r == 2"]) renderStack(getStackTraceEntries(e_17106116))except Exception as e_17106116: report(["💥 checking some things: " & (`$`(e_17106116.name) & ": " & e_17106114 check r == 3\n 🗏 block: ## unnamed block report(["🟢 unnamed block"])except SkipError as e_17106120: report(["⚪ unnamed block: " & (`$`(e_17106120.name) & ": " & e_17106120.msg)])except AssertionDefect as e_17106120: report(["🔴 unnamed block"]) report([" 🗏 1 ## unnamed block\n 🗏 2 discard"]) renderStack(getStackTraceEntries(e_17106120))except Exception as e_17106120: report(["💥 unnamed block: " & (`$`(e_17106120.name) & ": " & e_17106120.msg)] discard "unnamed test" report(["🟢 tes report(["🟢 test #7 block: ⮠..."])except SkipError as e_17106124: report(["⚪ test #7 block: ⮠...: " & (`$`(e_17106124.name) & ": " & e_17106124.msg)])except AssertionDefect as e_17106124: report(["🔴 test #7 block: ⮠..."]) report([" 🗏 1 discard \"unnamed test\""]) renderStack(getStackTraceEntries(e_17106124))except Exception as e_17106124: report(["💥 test #7 block: ⮠...: " & (`$`(e_17106124.name) & ": " & e_17106124 ## a test: block is fine report(["🟢 a test: block is fine"])except SkipError as e_17106128: report(["⚪ a test: block is fine: " & (`$`(e_17106128.name) & ": " & e_17106128.msg)])except AssertionDefect as e_17106128: report(["🔴 a test: block is fine" report(["🔴 a test: block is fine"]) report([" 🗏 1 ## a test: block is fine\n 🗏 2 discard"]) renderStack(getStackTraceEntries(e_17106128))except Exception as e_17106128: report(["💥 a test: block is fine: " & (`$`(e_17106128.name) & ": " & e_171061 block omission: skip("skipped") report(["🟢 omission"])except SkipError as e_17106132: report(["⚪ omission: " & (`$`(e_17106132.name) & ": " & e_17106132.msg)])except AssertionDefect as e_17106132: report(["🔴 omission"]) report([" 🗏 1 skip()"]) renderStack(getStackTraceEntries(e_17106132))except Exception as e_17106132: report(["💥 omission: " & ( report(["💥 omission: " & (`$`(e_17106132.name) & ": " & e_17106132.msg)]) report(["⛔ broken: compile failed"]) report([" 🗏 1 proc broken() =\n 🗏 2 doesnt(compile)\n 🗏 3 "]) report(["🟢 when defined(release): ⮠..."])except SkipError as e_17106136: report(["⚪ when defined(release): ⮠...: " & (`$`(e_17106136.name) & ": " & e_17106136.msg)])except AssertionDefect as e_17106136: report(["🔴 when defined(release): ⮠..."]) report([" 🗏 1 testes:\n 🗏 2 const\n 🗏 3 compile = true\n 🗏 4 proc doesnt(c: bool) =\n 🗏 5 if not c:\n 🗏 6 raise\n 🗏 7 \n 🗏 8 block:\n 🗏 9 proc fixed() =\n 🗏 10 doesnt(compile)\n 🗏 11 \n 🗏 12 else:\n 🗏 13 testes:\n 🗏 14 oesnt(compile)\n 🗏 11 \n 🗏 12 else:\n 🗏 13 testes:\n 🗏 14 block:\n 🗏 15 proc broken() =\n 🗏 16 doesnt(compile)\n 🗏 17 "]) renderStack(getStackTraceEntries(e_17106136))except Exception as e_17106136: report(["💥 when defined(release): ⮠...: " & (`$`(e_17106136.name) & ": " & e_ block assertions: expr`gensym21 = "2 == 4 div 2" const loc`gensym22 = (filename: "/home/adavidoff/git/testes/tests/testicles.nim", line: 59, column: 13) ploc`gensym22 = "/home/adavidoff/git/testes/tests/testicles.nim(59, 14)" {.line: (filename: "/home/adavidoff/git/testes/tests/testicles.nim", line: 59, failedAssertImpl("/home/adavidoff/git/testes/tests/testicles.nim(59, 14) `2 == 4 div 2` ") expr`gensym23 = "2 != 4 div 2" loc`gensym25 = (filename: "/home/adavidoff/git/testes/tests/testicles.nim" line: 60, column: 13) ploc`gensym25 = "/home/adavidoff/git/testes/tests/testicles.nim(60, 14)" {.line: (filename: "/home/adavidoff/git/testes/tests/testicles.nim", line: 60, if true: failedAssertImpl("/home/adavidoff/git/testes/tests/testicles.nim(60, 14) `2 != 4 div 2` ") report(["🟢 assertions"])except SkipError as e_17106140: report(["⚪ assertions: " & (`$`(e_17106140.name) report(["⚪ assertions: " & (`$`(e_17106140.name) & ": " & e_17106140.msg)])except AssertionDefect as e_17106140: report(["🔴 assertions"]) report([" 🗏 1 assert 2 == 4 div 2\n 🗏 2 assert 2 != 4 div 2"]) renderStack(getStackTraceEntries(e_17106140))except Exception as e_17106140: report(["💥 assertions: " & (`$`(e_17106140.name) & ": " & e_17106140.msg)]) const expr`gensym29 = "\"any statement is a test\" != \"\"" loc`gensym31 = (filename: "/home/adavidoff/git/testes/tests/testicles.nim", line: 62, column: 11) ploc`gensym31 = "/home/adavidoff/git/testes/tests/testicles.nim(62, 12)" {.line: (filename: "/home/adavidoff/git/testes/tests/testicles.nim", line: 62, column: 11).}: if f if false: failedAssertImpl("/home/adavidoff/git/testes/tests/testicles.nim(62, 12) `\"any statement is a test\" != \"\"` ") report(["🟢 assert \"any statement is a test\" != \"\""])except SkipError as e_17106144: report(["⚪ assert \"any statement is a test\" != \"\": " & (`$`(e_17106144.name) & ": " & e_17106144.msg)])except AssertionDefect as e_17106144: report(["🔴 assert \"any statement is a test\" != \"\""]) report([" 🗏 "]) renderStack(getStackTraceEntries(e_17106144))except Exception as e_17106144: report(["💥 assert \"any statement is a test\" != \"\": " &Hint: 65566 lines; 0.537s; 75.949MiB peakmem; Debug build; proj: /home/adavidoff/git/testes/tests/testi /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 🗏 1 raise newException(ValueError, "you\'re terrible") 🗇 tests/testicles.nim 🗇 21 raise newException(ValueError, "you're terrible") # in testicles()r == 3 = false🟢 checking some things🟢 unnamed block🟢 test #7 block: ⮠...🟢 a test: block is fine💣 skipping is broken on C (not C++) backend due to a bug⚪ omission: SkipError: skipped⛔ broken: compile failed 🗏 1 proc broken() = 🗏 2 doesnt(compile) 🗏 3 🟢 when defined(release): ⮠...🔴 assertions 🗏 1 assert 2 == 4 div 2 🗏 2 assert 2 != 4 div 2 🗇 60 assert 2 != 4 div 2 # in testicles() 🗇 ../../nims/lib/ 🗇 ../../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" != "" \ No newline at end of file diff --git a/docs/testes.html b/docs/testes.html index fa68831..af3ced4 100644 --- a/docs/testes.html +++ b/docs/testes.html @@ -176,7 +176,7 @@

Templates

diff --git a/docs/theindex.html b/docs/theindex.html index daf3858..d17db66 100644 --- a/docs/theindex.html +++ b/docs/theindex.html @@ -85,7 +85,7 @@

Index

diff --git a/testes.nim b/testes.nim index f09bc64..396795d 100644 --- a/testes.nim +++ b/testes.nim @@ -160,18 +160,22 @@ proc wrapExcept(t: Test): NimNode = proc makeTest(n: NimNode; name: string): Test = assert not n.isNil - result = Test(name: name, orig: copyNimTree(n)) + result = Test(name: name, orig: n) let beuno = genSym(nskLabel, "beuno") # all good, bro let arrrg = genSym(nskLabel, "arrrg") # bad news, pal - # emit a success if we exited the block normally - n.add result.success - n.add nnkBreakStmt.newTree(arrrg) - result.n = nnkBlockStmt.newTree(beuno, n) + result.n = copyNimTree(n).newStmtList + result.n.add result.success - # emit a failure if we broke out of the success block - result.n = nnkBlockStmt.newTree(arrrg, - newStmtList(result.n, result.failure)) + 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 @@ -180,8 +184,9 @@ proc makeTest(n: NimNode; name: string): Test = when not defined(release): result.n = nnkWhenStmt.newTree( nnkElifBranch.newTree( - newCall(ident"compiles", nnkBlockStmt.newTree(newEmptyNode(), - result.orig)), + newCall(ident"compiles", + nnkBlockStmt.newTree(genSym(nskLabel, "compiles"), + newStmtList(result.orig))), result.n), nnkElse.newTree(result.compilerr)) @@ -217,7 +222,7 @@ proc findName(n: NimNode; index: int): string = ## generate a name for a test block assert not n.isNil block: - if len(n) == 2: + if len(n) == 2 and n.kind == nnkBlockStmt: # grab the body of the block, var body = n.last # and the first node @@ -235,6 +240,9 @@ proc findName(n: NimNode; index: int): string = "test #" & $index & " " & shortenRepr(n) # and we're done. break + else: + result = shortenRepr(n) + break # else we had some kind of parse error echo treeRepr(n) result = "test #" & $index & " (parse error)" @@ -249,7 +257,8 @@ const nnkBreakStmt, nnkAsmStmt, nnkImportStmt, nnkImportExceptStmt, nnkExportStmt, nnkExportExceptStmt, nnkFromStmt, nnkIncludeStmt, nnkTypeSection, nnkMixinStmt, nnkBindStmt, nnkProcDef, nnkIteratorDef, - nnkConverterDef, nnkTemplateDef, nnkFuncDef, nnkMacroDef + nnkConverterDef, nnkTemplateDef, nnkFuncDef, nnkMacroDef, nnkCommand, + nnkCall } @@ -259,7 +268,8 @@ const nnkBlockStmt, nnkIfStmt, nnkWhileStmt, nnkForStmt, nnkTryStmt, nnkReturnStmt, nnkYieldStmt, nnkDiscardStmt, nnkContinueStmt, nnkAsmStmt, nnkImportStmt, nnkImportExceptStmt, nnkExportStmt, - nnkExportExceptStmt, nnkFromStmt, nnkIncludeStmt + nnkExportExceptStmt, nnkFromStmt, nnkIncludeStmt, nnkCommand, + nnkCall, nnkWhenStmt } @@ -268,18 +278,18 @@ macro testes*(tests: untyped) = result = newStmtList() for index, n in pairs(tests): var n = n.rewriteTestBlock - if n.kind notin testable: - result.add output(repr(n).prefixLines("⚫ ").newLit) - result.add n - else: + if n.kind in testable: var test: Test - if len(n) < 2 or len(n.last) == 0: + if false and len(n) < 2 or len(n.last) == 0: test.name = "test #$1 omitted" % [ $index ] test.n = test.output("🔵 " & test.name) else: let name = findName(n, index) test = makeTest(n, name) result.add test.n + else: + result.add output(repr(n).prefixLines("⚫ ").newLit) + result.add n template suite*(title, tests: untyped): untyped = ## suite, suite testes diff --git a/testes.nimble b/testes.nimble index 7c025f3..ed7fe41 100644 --- a/testes.nimble +++ b/testes.nimble @@ -1,4 +1,4 @@ -version = "0.1.1" +version = "0.1.2" author = "disruptek" description = "a cure for salty testes" license = "MIT" diff --git a/tests/testicles.nim b/tests/testicles.nim index 2ca3da2..93f8973 100644 --- a/tests/testicles.nim +++ b/tests/testicles.nim @@ -5,14 +5,16 @@ expandMacros: block goats: ## this is a test of goats + discard block pigs: ## a test of pigs + discard var r = 3 block sometimes_the_wolf_is_nice: - break + assert true inc r block sheepies: @@ -33,7 +35,7 @@ expandMacros: block: discard "unnamed test" - test "a test: block": + test "a test: block is fine": discard block omission: @@ -56,3 +58,5 @@ expandMacros: block assertions: assert 2 == 4 div 2 assert 2 != 4 div 2 + + assert "any statement is a test" != ""