tester reports ignored tests and supports 'nimout'; fixes #2211
This commit is contained in:
parent
dc8b07fe0b
commit
335c19c869
7 changed files with 48 additions and 10 deletions
|
|
@ -54,6 +54,7 @@ proc mapTypeToBracket(name: string; t: PType; info: TLineInfo): PNode =
|
||||||
if t.sons[i] == nil:
|
if t.sons[i] == nil:
|
||||||
let void = atomicTypeX("void", t, info)
|
let void = atomicTypeX("void", t, info)
|
||||||
void.typ = newType(tyEmpty, t.owner)
|
void.typ = newType(tyEmpty, t.owner)
|
||||||
|
result.add void
|
||||||
else:
|
else:
|
||||||
result.add mapTypeToAst(t.sons[i], info)
|
result.add mapTypeToAst(t.sons[i], info)
|
||||||
|
|
||||||
|
|
@ -105,7 +106,7 @@ proc mapTypeToAst(t: PType, info: TLineInfo; allowRecursion=false): PNode =
|
||||||
of tyPtr: result = mapTypeToBracket("ptr", t, info)
|
of tyPtr: result = mapTypeToBracket("ptr", t, info)
|
||||||
of tyRef: result = mapTypeToBracket("ref", t, info)
|
of tyRef: result = mapTypeToBracket("ref", t, info)
|
||||||
of tyVar: result = mapTypeToBracket("var", t, info)
|
of tyVar: result = mapTypeToBracket("var", t, info)
|
||||||
of tySequence: result = mapTypeToBracket("sequence", t, info)
|
of tySequence: result = mapTypeToBracket("seq", t, info)
|
||||||
of tyProc: result = mapTypeToBracket("proc", t, info)
|
of tyProc: result = mapTypeToBracket("proc", t, info)
|
||||||
of tyOpenArray: result = mapTypeToBracket("openArray", t, info)
|
of tyOpenArray: result = mapTypeToBracket("openArray", t, info)
|
||||||
of tyRange:
|
of tyRange:
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,16 @@
|
||||||
discard """
|
discard """
|
||||||
disabled: true
|
nimout: '''void
|
||||||
|
int'''
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import macros, typetraits
|
import macros
|
||||||
|
|
||||||
macro checkType(ex, expected: expr): stmt {.immediate.} =
|
macro checkType(ex: stmt; expected: expr): stmt =
|
||||||
var t = ex.typ
|
var t = ex.getType()
|
||||||
assert t.name == expected.strVal
|
echo t
|
||||||
|
|
||||||
proc voidProc = echo "hello"
|
proc voidProc = echo "hello"
|
||||||
proc intProc(a, b): int = 10
|
proc intProc(a: int, b: float): int = 10
|
||||||
|
|
||||||
checkType(voidProc(), "void")
|
checkType(voidProc(), "void")
|
||||||
checkType(intProc(10, 20.0), "int")
|
checkType(intProc(10, 20.0), "int")
|
||||||
checkType(noproc(10, 20.0), "Error Type")
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
discard """
|
discard """
|
||||||
output: "bla"
|
output: "bla"
|
||||||
disabled: true
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import macros
|
import macros
|
||||||
|
|
@ -1,3 +1,7 @@
|
||||||
|
discard """
|
||||||
|
disabled: true
|
||||||
|
"""
|
||||||
|
|
||||||
import macro_bug
|
import macro_bug
|
||||||
|
|
||||||
type TObj = object
|
type TObj = object
|
||||||
|
|
|
||||||
17
tests/macros/typesapi.nim
Normal file
17
tests/macros/typesapi.nim
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
discard """
|
||||||
|
nimout: '''proc (x: int): string => typeDesc[proc[string, int]]
|
||||||
|
proc (x: int): void => typeDesc[proc[void, int]]
|
||||||
|
proc (x: int) => typeDesc[proc[void, int]]'''
|
||||||
|
"""
|
||||||
|
|
||||||
|
#2211
|
||||||
|
|
||||||
|
import macros
|
||||||
|
|
||||||
|
macro showType(t:stmt): stmt =
|
||||||
|
let ty = t.getType
|
||||||
|
echo t.repr, " => ", ty.repr
|
||||||
|
|
||||||
|
showType(proc(x:int): string)
|
||||||
|
showType(proc(x:int): void)
|
||||||
|
showType(proc(x:int))
|
||||||
|
|
@ -48,6 +48,7 @@ type
|
||||||
err*: TResultEnum
|
err*: TResultEnum
|
||||||
substr*, sortoutput*: bool
|
substr*, sortoutput*: bool
|
||||||
targets*: set[TTarget]
|
targets*: set[TTarget]
|
||||||
|
nimout*: string
|
||||||
|
|
||||||
const
|
const
|
||||||
targetToExt*: array[TTarget, string] = ["c", "cpp", "m", "js"]
|
targetToExt*: array[TTarget, string] = ["c", "cpp", "m", "js"]
|
||||||
|
|
@ -94,6 +95,7 @@ proc parseSpec*(filename: string): TSpec =
|
||||||
result.file = filename
|
result.file = filename
|
||||||
result.msg = ""
|
result.msg = ""
|
||||||
result.outp = ""
|
result.outp = ""
|
||||||
|
result.nimout = ""
|
||||||
result.ccodeCheck = ""
|
result.ccodeCheck = ""
|
||||||
result.cmd = cmdTemplate
|
result.cmd = cmdTemplate
|
||||||
parseSpecAux:
|
parseSpecAux:
|
||||||
|
|
@ -124,6 +126,8 @@ proc parseSpec*(filename: string): TSpec =
|
||||||
of "errormsg":
|
of "errormsg":
|
||||||
result.msg = e.value
|
result.msg = e.value
|
||||||
result.action = actionReject
|
result.action = actionReject
|
||||||
|
of "nimout":
|
||||||
|
result.nimout = e.value
|
||||||
of "disabled":
|
of "disabled":
|
||||||
if parseCfgBool(e.value): result.err = reIgnored
|
if parseCfgBool(e.value): result.err = reIgnored
|
||||||
of "cmd": result.cmd = e.value
|
of "cmd": result.cmd = e.value
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,9 @@ proc callCompiler(cmdTemplate, filename, options: string,
|
||||||
var suc = ""
|
var suc = ""
|
||||||
var err = ""
|
var err = ""
|
||||||
var x = newStringOfCap(120)
|
var x = newStringOfCap(120)
|
||||||
|
result.nimout = ""
|
||||||
while outp.readLine(x.TaintedString) or running(p):
|
while outp.readLine(x.TaintedString) or running(p):
|
||||||
|
result.nimout.add(x & "\n")
|
||||||
if x =~ pegOfInterest:
|
if x =~ pegOfInterest:
|
||||||
# `err` should contain the last error/warning message
|
# `err` should contain the last error/warning message
|
||||||
err = x
|
err = x
|
||||||
|
|
@ -112,7 +114,9 @@ proc addResult(r: var TResults, test: TTest,
|
||||||
expected = expected,
|
expected = expected,
|
||||||
given = given)
|
given = given)
|
||||||
r.data.addf("$#\t$#\t$#\t$#", name, expected, given, $success)
|
r.data.addf("$#\t$#\t$#\t$#", name, expected, given, $success)
|
||||||
if success notin {reSuccess, reIgnored}:
|
if success == reIgnored:
|
||||||
|
styledEcho styleBright, name, fgYellow, " [", $success, "]"
|
||||||
|
elif success != reSuccess:
|
||||||
styledEcho styleBright, name, fgRed, " [", $success, "]"
|
styledEcho styleBright, name, fgRed, " [", $success, "]"
|
||||||
echo"Expected:"
|
echo"Expected:"
|
||||||
styledEcho styleBright, expected
|
styledEcho styleBright, expected
|
||||||
|
|
@ -151,6 +155,13 @@ proc codegenCheck(test: TTest, check: string, given: var TSpec) =
|
||||||
except IOError:
|
except IOError:
|
||||||
given.err = reCodeNotFound
|
given.err = reCodeNotFound
|
||||||
|
|
||||||
|
proc nimoutCheck(test: TTest; expectedNimout: string; given: var TSpec) =
|
||||||
|
if expectedNimout.len > 0:
|
||||||
|
let exp = expectedNimout.strip.replace("\C\L", "\L")
|
||||||
|
let giv = given.nimout.strip.replace("\C\L", "\L")
|
||||||
|
if exp notin giv:
|
||||||
|
given.err = reMsgsDiffer
|
||||||
|
|
||||||
proc makeDeterministic(s: string): string =
|
proc makeDeterministic(s: string): string =
|
||||||
var x = splitLines(s)
|
var x = splitLines(s)
|
||||||
sort(x, system.cmp)
|
sort(x, system.cmp)
|
||||||
|
|
@ -172,6 +183,7 @@ proc testSpec(r: var TResults, test: TTest) =
|
||||||
test.target)
|
test.target)
|
||||||
if given.err == reSuccess:
|
if given.err == reSuccess:
|
||||||
codegenCheck(test, expected.ccodeCheck, given)
|
codegenCheck(test, expected.ccodeCheck, given)
|
||||||
|
nimoutCheck(test, expected.nimout, given)
|
||||||
r.addResult(test, "", given.msg, given.err)
|
r.addResult(test, "", given.msg, given.err)
|
||||||
if given.err == reSuccess: inc(r.passed)
|
if given.err == reSuccess: inc(r.passed)
|
||||||
of actionRun:
|
of actionRun:
|
||||||
|
|
@ -205,6 +217,7 @@ proc testSpec(r: var TResults, test: TTest) =
|
||||||
given.err = reOutputsDiffer
|
given.err = reOutputsDiffer
|
||||||
if given.err == reSuccess:
|
if given.err == reSuccess:
|
||||||
codeGenCheck(test, expected.ccodeCheck, given)
|
codeGenCheck(test, expected.ccodeCheck, given)
|
||||||
|
nimoutCheck(test, expected.nimout, given)
|
||||||
if given.err == reSuccess: inc(r.passed)
|
if given.err == reSuccess: inc(r.passed)
|
||||||
r.addResult(test, expected.outp, buf.string, given.err)
|
r.addResult(test, expected.outp, buf.string, given.err)
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue