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:
parent
a068aaed3c
commit
1e26047c3b
5 changed files with 31 additions and 6 deletions
|
|
@ -11,4 +11,5 @@ path:"$projectPath/.."
|
|||
path:"$lib/packages/docutils"
|
||||
|
||||
define:booting
|
||||
import:testability
|
||||
|
||||
|
|
|
|||
|
|
@ -76,5 +76,7 @@ when compileOption("gc", "v2") or compileOption("gc", "refc"):
|
|||
# the new correct mark&sweet collector is too slow :-/
|
||||
GC_disableMarkAndSweep()
|
||||
condsyms.InitDefines()
|
||||
HandleCmdLine()
|
||||
quit(int8(msgs.gErrorCounter > 0))
|
||||
|
||||
when not defined(selftest):
|
||||
HandleCmdLine()
|
||||
quit(int8(msgs.gErrorCounter > 0))
|
||||
|
|
|
|||
|
|
@ -1130,7 +1130,7 @@ proc matches*(c: PContext, n, nOrig: PNode, m: var TCandidate) =
|
|||
var f = 1
|
||||
while f < sonsLen(m.callee.n):
|
||||
var formal = m.callee.n.sons[f].sym
|
||||
if not ContainsOrIncl(marker, formal.position):
|
||||
if not ContainsOrIncl(marker, formal.position):
|
||||
if formal.ast == nil:
|
||||
if formal.typ.kind == tyVarargs:
|
||||
var container = newNodeIT(nkBracket, n.info, arrayConstr(c, n.info))
|
||||
|
|
@ -1145,7 +1145,7 @@ proc matches*(c: PContext, n, nOrig: PNode, m: var TCandidate) =
|
|||
setSon(m.call, formal.position + 1, copyTree(formal.ast))
|
||||
inc(f)
|
||||
|
||||
proc argtypeMatches*(c: PContext, f, a: PType): bool =
|
||||
proc argtypeMatches*(c: PContext, f, a: PType): bool =
|
||||
var m: TCandidate
|
||||
initCandidate(m, f)
|
||||
let res = paramTypesMatch(c, m, f, a, ast.emptyNode, nil)
|
||||
|
|
@ -1155,3 +1155,16 @@ proc argtypeMatches*(c: PContext, f, a: PType): bool =
|
|||
result = res != nil
|
||||
|
||||
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
5
compiler/testability.nim
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
template tests*(body: stmt) {.immediate.} =
|
||||
when defined(selftest):
|
||||
when not defined(unittest): import unittest
|
||||
body
|
||||
|
||||
|
|
@ -98,8 +98,12 @@ template fail* =
|
|||
|
||||
when not defined(ECMAScript):
|
||||
if AbortOnError: quit(1)
|
||||
|
||||
TestStatusIMPL = FAILED
|
||||
|
||||
when defined(TestStatusIMPL):
|
||||
TestStatusIMPL = FAILED
|
||||
else:
|
||||
program_result += 1
|
||||
|
||||
checkpoints = @[]
|
||||
|
||||
macro check*(conditions: stmt): stmt {.immediate.} =
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue