adding some provisions for writing lower-level unit tests targeting specific sub-systems of the compiler

see sigmatch as an example.
tests are compiled only when the compiler is compiled with -d:selftest
to execute them, just run the resulting binary without arguments
This commit is contained in:
Zahary Karadjov 2013-12-07 20:30:44 +02:00
commit 1e26047c3b
5 changed files with 31 additions and 6 deletions

View file

@ -11,4 +11,5 @@ path:"$projectPath/.."
path:"$lib/packages/docutils" path:"$lib/packages/docutils"
define:booting define:booting
import:testability

View file

@ -76,5 +76,7 @@ when compileOption("gc", "v2") or compileOption("gc", "refc"):
# the new correct mark&sweet collector is too slow :-/ # the new correct mark&sweet collector is too slow :-/
GC_disableMarkAndSweep() GC_disableMarkAndSweep()
condsyms.InitDefines() condsyms.InitDefines()
when not defined(selftest):
HandleCmdLine() HandleCmdLine()
quit(int8(msgs.gErrorCounter > 0)) quit(int8(msgs.gErrorCounter > 0))

View file

@ -1155,3 +1155,16 @@ proc argtypeMatches*(c: PContext, f, a: PType): bool =
result = res != nil result = res != nil
include suggest include suggest
tests:
suite "typerel":
test "ordinals":
# var owner = newSym(skModule, getIdent("dummy"), nil, UnknownLineInfo())
var m: TCandidate
InitCandidate(m, f)
# let f = newType(tyOrdinal, owner)
# let a = getSysType(tyInt)
# check typerel(m, f, a) == isGeneric

5
compiler/testability.nim Normal file
View file

@ -0,0 +1,5 @@
template tests*(body: stmt) {.immediate.} =
when defined(selftest):
when not defined(unittest): import unittest
body

View file

@ -99,7 +99,11 @@ template fail* =
when not defined(ECMAScript): when not defined(ECMAScript):
if AbortOnError: quit(1) if AbortOnError: quit(1)
when defined(TestStatusIMPL):
TestStatusIMPL = FAILED TestStatusIMPL = FAILED
else:
program_result += 1
checkpoints = @[] checkpoints = @[]
macro check*(conditions: stmt): stmt {.immediate.} = macro check*(conditions: stmt): stmt {.immediate.} =