Basic unit testing facilities (suites, fixtures, cases)
Added: PNimrodNode.lineinfo for better error messages from macros Added: seq.splice For easier use from templates and macros, except stament now supports the list of exception types to be supplied in nkBraket node (array literal).
This commit is contained in:
parent
eaeed1f846
commit
22546c44d1
8 changed files with 258 additions and 16 deletions
|
|
@ -369,7 +369,7 @@ type
|
|||
mCompileOption, mCompileOptionArg,
|
||||
mNLen, mNChild, mNSetChild, mNAdd, mNAddMultiple, mNDel, mNKind,
|
||||
mNIntVal, mNFloatVal, mNSymbol, mNIdent, mNGetType, mNStrVal, mNSetIntVal,
|
||||
mNSetFloatVal, mNSetSymbol, mNSetIdent, mNSetType, mNSetStrVal,
|
||||
mNSetFloatVal, mNSetSymbol, mNSetIdent, mNSetType, mNSetStrVal, mNLineInfo,
|
||||
mNNewNimNode, mNCopyNimNode, mNCopyNimTree, mStrToIdent, mIdentToStr,
|
||||
mEqIdent, mEqNimrodNode, mNHint, mNWarning, mNError, mGetTypeInfo
|
||||
|
||||
|
|
|
|||
|
|
@ -798,8 +798,9 @@ proc evalMacroCall*(c: PEvalContext, n: PNode, sym: PSym): PNode =
|
|||
import
|
||||
semdata, sem
|
||||
|
||||
proc evalExpandToAst(c: PEvalContext, n: PNode): PNode =
|
||||
var
|
||||
proc evalExpandToAst(c: PEvalContext, original: PNode): PNode =
|
||||
var
|
||||
n = original.copyTree
|
||||
macroCall = n.sons[1]
|
||||
expandedSym = macroCall.sons[0].sym
|
||||
|
||||
|
|
@ -854,7 +855,7 @@ proc evalMagicOrCall(c: PEvalContext, n: PNode): PNode =
|
|||
of mParseExprToAst: result = evalParseExpr(c, n)
|
||||
of mParseStmtToAst: result = evalParseStmt(c, n)
|
||||
of mExpandMacroToAst: result = evalExpandToAst(c, n)
|
||||
of mNLen:
|
||||
of mNLen:
|
||||
result = evalAux(c, n.sons[1], {efLValue})
|
||||
if isSpecial(result): return
|
||||
var a = result
|
||||
|
|
@ -1060,6 +1061,10 @@ proc evalMagicOrCall(c: PEvalContext, n: PNode): PNode =
|
|||
if (a == b) or
|
||||
(b.kind in {nkNilLit, nkEmpty}) and (a.kind in {nkNilLit, nkEmpty}):
|
||||
result.intVal = 1
|
||||
of mNLineInfo:
|
||||
result = evalAux(c, n.sons[1], {})
|
||||
if isSpecial(result): return
|
||||
result = newStrNodeT(result.info.toFileLineCol, n)
|
||||
of mAstToYaml:
|
||||
var ast = evalAux(c, n.sons[1], {efLValue})
|
||||
result = newStrNode(nkStrLit, ast.treeToYaml.ropeToStr)
|
||||
|
|
|
|||
|
|
@ -456,6 +456,12 @@ proc ToLinenumber*(info: TLineInfo): int {.inline.} =
|
|||
proc toColumn*(info: TLineInfo): int {.inline.} =
|
||||
result = info.col
|
||||
|
||||
proc toFileLine*(info: TLineInfo): string {.inline.} =
|
||||
result = info.toFilename & ":" & $info.line
|
||||
|
||||
proc toFileLineCol*(info: TLineInfo): string {.inline.} =
|
||||
result = info.toFilename & "(" & $info.line & "," & $info.col & ")"
|
||||
|
||||
var checkPoints: seq[TLineInfo] = @[]
|
||||
|
||||
proc addCheckpoint*(info: TLineInfo) =
|
||||
|
|
|
|||
|
|
@ -428,7 +428,7 @@ proc semRaise(c: PContext, n: PNode): PNode =
|
|||
var typ = n.sons[0].typ
|
||||
if typ.kind != tyRef or typ.sons[0].kind != tyObject:
|
||||
localError(n.info, errExprCannotBeRaised)
|
||||
|
||||
|
||||
proc semTry(c: PContext, n: PNode): PNode =
|
||||
result = n
|
||||
checkMinSonsLen(n, 2)
|
||||
|
|
@ -438,15 +438,19 @@ proc semTry(c: PContext, n: PNode): PNode =
|
|||
var a = n.sons[i]
|
||||
checkMinSonsLen(a, 1)
|
||||
var length = sonsLen(a)
|
||||
if a.kind == nkExceptBranch:
|
||||
for j in countup(0, length - 2):
|
||||
if a.kind == nkExceptBranch:
|
||||
if length == 2 and a.sons[0].kind == nkBracket:
|
||||
a.sons.splice(0, 1, a.sons[0].sons)
|
||||
length = a.sonsLen
|
||||
|
||||
for j in countup(0, length - 2):
|
||||
var typ = semTypeNode(c, a.sons[j], nil)
|
||||
if typ.kind == tyRef: typ = typ.sons[0]
|
||||
if typ.kind != tyObject:
|
||||
if typ.kind != tyObject:
|
||||
GlobalError(a.sons[j].info, errExprCannotBeRaised)
|
||||
a.sons[j] = newNodeI(nkType, a.sons[j].info)
|
||||
a.sons[j].typ = typ
|
||||
if ContainsOrIncl(check, typ.id):
|
||||
if ContainsOrIncl(check, typ.id):
|
||||
localError(a.sons[j].info, errExceptionAlreadyHandled)
|
||||
elif a.kind != nkFinally:
|
||||
illFormedAst(n)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue