Tester tests (#9787)
* remove --lib:lib * added some tests for testatment * tests are addad WIP: add colors switch to tester * meta tester is integrated
This commit is contained in:
parent
8990764709
commit
cc0364e72f
15 changed files with 164 additions and 21 deletions
|
|
@ -16,7 +16,7 @@ let isTravis* = existsEnv("TRAVIS")
|
||||||
let isAppVeyor* = existsEnv("APPVEYOR")
|
let isAppVeyor* = existsEnv("APPVEYOR")
|
||||||
|
|
||||||
proc cmdTemplate*(): string =
|
proc cmdTemplate*(): string =
|
||||||
compilerPrefix & " $target --lib:lib --hints:on -d:testing --nimblePath:tests/deps $options $file"
|
compilerPrefix & " $target --hints:on -d:testing --nimblePath:tests/deps $options $file"
|
||||||
|
|
||||||
type
|
type
|
||||||
TTestAction* = enum
|
TTestAction* = enum
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,8 @@ import
|
||||||
marshal, backend, parseopt, specs, htmlgen, browsers, terminal,
|
marshal, backend, parseopt, specs, htmlgen, browsers, terminal,
|
||||||
algorithm, compiler/nodejs, times, sets, md5
|
algorithm, compiler/nodejs, times, sets, md5
|
||||||
|
|
||||||
|
var useColors = true
|
||||||
|
|
||||||
const
|
const
|
||||||
resultsFile = "testresults.html"
|
resultsFile = "testresults.html"
|
||||||
#jsonFile = "testresults.json" # not used
|
#jsonFile = "testresults.json" # not used
|
||||||
|
|
@ -32,6 +34,8 @@ Options:
|
||||||
--failing only show failing/ignored tests
|
--failing only show failing/ignored tests
|
||||||
--targets:"c c++ js objc" run tests for specified targets (default: all)
|
--targets:"c c++ js objc" run tests for specified targets (default: all)
|
||||||
--nim:path use a particular nim executable (default: compiler/nim)
|
--nim:path use a particular nim executable (default: compiler/nim)
|
||||||
|
--directory:dir Change to directory dir before reading the tests or doing anything else.
|
||||||
|
--colors:on|off turn messagescoloring on|off
|
||||||
""" % resultsFile
|
""" % resultsFile
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
@ -180,11 +184,30 @@ proc initResults: TResults =
|
||||||
result.skipped = 0
|
result.skipped = 0
|
||||||
result.data = ""
|
result.data = ""
|
||||||
|
|
||||||
#proc readResults(filename: string): TResults = # not used
|
import macros
|
||||||
# result = marshal.to[TResults](readFile(filename).string)
|
|
||||||
|
macro ignoreStyleEcho(args: varargs[typed]): untyped =
|
||||||
|
let typForegroundColor = bindSym"ForegroundColor".getType
|
||||||
|
let typBackgroundColor = bindSym"BackgroundColor".getType
|
||||||
|
let typStyle = bindSym"Style".getType
|
||||||
|
let typTerminalCmd = bindSym"TerminalCmd".getType
|
||||||
|
result = newCall(bindSym"echo")
|
||||||
|
for arg in children(args):
|
||||||
|
if arg.kind == nnkNilLit: continue
|
||||||
|
let typ = arg.getType
|
||||||
|
if typ.kind != nnkEnumTy or
|
||||||
|
typ != typForegroundColor and
|
||||||
|
typ != typBackgroundColor and
|
||||||
|
typ != typStyle and
|
||||||
|
typ != typTerminalCmd:
|
||||||
|
result.add(arg)
|
||||||
|
|
||||||
|
template maybeStyledEcho(args: varargs[untyped]): untyped =
|
||||||
|
if useColors:
|
||||||
|
styledEcho(args)
|
||||||
|
else:
|
||||||
|
ignoreStyleEcho(args)
|
||||||
|
|
||||||
#proc writeResults(filename: string, r: TResults) = # not used
|
|
||||||
# writeFile(filename, $$r)
|
|
||||||
|
|
||||||
proc `$`(x: TResults): string =
|
proc `$`(x: TResults): string =
|
||||||
result = ("Tests passed: $1 / $3 <br />\n" &
|
result = ("Tests passed: $1 / $3 <br />\n" &
|
||||||
|
|
@ -205,17 +228,17 @@ proc addResult(r: var TResults, test: TTest, target: TTarget,
|
||||||
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 == reSuccess:
|
if success == reSuccess:
|
||||||
styledEcho fgGreen, "PASS: ", fgCyan, alignLeft(name, 60), fgBlue, " (", durationStr, " secs)"
|
maybeStyledEcho fgGreen, "PASS: ", fgCyan, alignLeft(name, 60), fgBlue, " (", durationStr, " secs)"
|
||||||
elif success == reIgnored:
|
elif success == reIgnored:
|
||||||
styledEcho styleDim, fgYellow, "SKIP: ", styleBright, fgCyan, name
|
maybeStyledEcho styleDim, fgYellow, "SKIP: ", styleBright, fgCyan, name
|
||||||
else:
|
else:
|
||||||
styledEcho styleBright, fgRed, "FAIL: ", fgCyan, name
|
maybeStyledEcho styleBright, fgRed, "FAIL: ", fgCyan, name
|
||||||
styledEcho styleBright, fgCyan, "Test \"", test.name, "\"", " in category \"", test.cat.string, "\""
|
maybeStyledEcho styleBright, fgCyan, "Test \"", test.name, "\"", " in category \"", test.cat.string, "\""
|
||||||
styledEcho styleBright, fgRed, "Failure: ", $success
|
maybeStyledEcho styleBright, fgRed, "Failure: ", $success
|
||||||
styledEcho fgYellow, "Expected:"
|
maybeStyledEcho fgYellow, "Expected:"
|
||||||
styledEcho styleBright, expected, "\n"
|
maybeStyledEcho styleBright, expected, "\n"
|
||||||
styledEcho fgYellow, "Gotten:"
|
maybeStyledEcho fgYellow, "Gotten:"
|
||||||
styledEcho styleBright, given, "\n"
|
maybeStyledEcho styleBright, given, "\n"
|
||||||
|
|
||||||
if existsEnv("APPVEYOR"):
|
if existsEnv("APPVEYOR"):
|
||||||
let (outcome, msg) =
|
let (outcome, msg) =
|
||||||
|
|
@ -295,10 +318,15 @@ proc codegenCheck(test: TTest, target: TTarget, spec: TSpec, expectedMsg: var st
|
||||||
echo getCurrentExceptionMsg()
|
echo getCurrentExceptionMsg()
|
||||||
|
|
||||||
proc nimoutCheck(test: TTest; expectedNimout: string; given: var TSpec) =
|
proc nimoutCheck(test: TTest; expectedNimout: string; given: var TSpec) =
|
||||||
let exp = expectedNimout.strip.replace("\C\L", "\L")
|
let giv = given.nimout.strip
|
||||||
let giv = given.nimout.strip.replace("\C\L", "\L")
|
var currentPos = 0
|
||||||
if exp notin giv:
|
# Only check that nimout contains all expected lines in that order.
|
||||||
given.err = reMsgsDiffer
|
# There may be more output in nimout. It is ignored here.
|
||||||
|
for line in expectedNimout.strip.splitLines:
|
||||||
|
currentPos = giv.find(line.strip, currentPos)
|
||||||
|
if currentPos < 0:
|
||||||
|
given.err = reMsgsDiffer
|
||||||
|
return
|
||||||
|
|
||||||
proc makeDeterministic(s: string): string =
|
proc makeDeterministic(s: string): string =
|
||||||
var x = splitLines(s)
|
var x = splitLines(s)
|
||||||
|
|
@ -324,7 +352,6 @@ proc compilerOutputTests(test: TTest, target: TTarget, given: var TSpec,
|
||||||
|
|
||||||
proc testSpec(r: var TResults, test: TTest, target = targetC) =
|
proc testSpec(r: var TResults, test: TTest, target = targetC) =
|
||||||
let tname = test.name.addFileExt(".nim")
|
let tname = test.name.addFileExt(".nim")
|
||||||
#echo "TESTING ", tname
|
|
||||||
var expected: TSpec
|
var expected: TSpec
|
||||||
if test.action != actionRunNoSpec:
|
if test.action != actionRunNoSpec:
|
||||||
expected = parseSpec(tname)
|
expected = parseSpec(tname)
|
||||||
|
|
@ -363,6 +390,12 @@ proc testSpec(r: var TResults, test: TTest, target = targetC) =
|
||||||
var given = callCompiler(expected.cmd, test.name, test.options,
|
var given = callCompiler(expected.cmd, test.name, test.options,
|
||||||
target)
|
target)
|
||||||
|
|
||||||
|
# echo "expected.cmd: ", expected.cmd
|
||||||
|
# echo "nimout: ", given.nimout
|
||||||
|
# echo "outp: ", given.outp
|
||||||
|
# echo "msg: ", given.msg
|
||||||
|
# echo "err: ", given.err
|
||||||
|
|
||||||
if given.err != reSuccess:
|
if given.err != reSuccess:
|
||||||
r.addResult(test, target, "", given.msg, given.err)
|
r.addResult(test, target, "", given.msg, given.err)
|
||||||
continue
|
continue
|
||||||
|
|
@ -437,7 +470,7 @@ proc testC(r: var TResults, test: TTest) =
|
||||||
# runs C code. Doesn't support any specs, just goes by exit code.
|
# runs C code. Doesn't support any specs, just goes by exit code.
|
||||||
let tname = test.name.addFileExt(".c")
|
let tname = test.name.addFileExt(".c")
|
||||||
inc(r.total)
|
inc(r.total)
|
||||||
styledEcho "Processing ", fgCyan, extractFilename(tname)
|
maybeStyledEcho "Processing ", fgCyan, extractFilename(tname)
|
||||||
var given = callCCompiler(cmdTemplate(), test.name & ".c", test.options, targetC)
|
var given = callCCompiler(cmdTemplate(), test.name & ".c", test.options, targetC)
|
||||||
if given.err != reSuccess:
|
if given.err != reSuccess:
|
||||||
r.addResult(test, targetC, "", given.msg, given.err)
|
r.addResult(test, targetC, "", given.msg, given.err)
|
||||||
|
|
@ -494,6 +527,7 @@ proc main() =
|
||||||
|
|
||||||
var targetsStr = ""
|
var targetsStr = ""
|
||||||
|
|
||||||
|
|
||||||
var p = initOptParser()
|
var p = initOptParser()
|
||||||
p.next()
|
p.next()
|
||||||
while p.kind == cmdLongoption:
|
while p.kind == cmdLongoption:
|
||||||
|
|
@ -505,7 +539,17 @@ proc main() =
|
||||||
targetsStr = p.val.string
|
targetsStr = p.val.string
|
||||||
targets = parseTargets(targetsStr)
|
targets = parseTargets(targetsStr)
|
||||||
of "nim": compilerPrefix = p.val.string
|
of "nim": compilerPrefix = p.val.string
|
||||||
else: quit Usage
|
of "directory":
|
||||||
|
setCurrentDir(p.val.string)
|
||||||
|
of "colors":
|
||||||
|
if p.val.string == "on":
|
||||||
|
useColors = true
|
||||||
|
elif p.val.string == "off":
|
||||||
|
useColors = false
|
||||||
|
else:
|
||||||
|
quit Usage
|
||||||
|
else:
|
||||||
|
quit Usage
|
||||||
p.next()
|
p.next()
|
||||||
if p.kind != cmdArgument: quit Usage
|
if p.kind != cmdArgument: quit Usage
|
||||||
var action = p.key.string.normalize
|
var action = p.key.string.normalize
|
||||||
|
|
|
||||||
8
testament/tests/shouldfail/tccodecheck.nim
Normal file
8
testament/tests/shouldfail/tccodecheck.nim
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
discard """
|
||||||
|
ccodecheck: "baz"
|
||||||
|
"""
|
||||||
|
|
||||||
|
proc foo(): void {.exportc: "bar".}=
|
||||||
|
echo "Hello World"
|
||||||
|
|
||||||
|
foo()
|
||||||
8
testament/tests/shouldfail/tcolumn.nim
Normal file
8
testament/tests/shouldfail/tcolumn.nim
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
discard """
|
||||||
|
line: 8
|
||||||
|
column: 7
|
||||||
|
errormsg: "undeclared identifier: 'undeclared'"
|
||||||
|
"""
|
||||||
|
|
||||||
|
# test should fail because the line directive is wrong
|
||||||
|
echo undeclared
|
||||||
8
testament/tests/shouldfail/terrormsg.nim
Normal file
8
testament/tests/shouldfail/terrormsg.nim
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
discard """
|
||||||
|
line: 8
|
||||||
|
column: 6
|
||||||
|
errormsg: "wrong error message"
|
||||||
|
"""
|
||||||
|
|
||||||
|
# test should fail because the line directive is wrong
|
||||||
|
echo undeclared
|
||||||
3
testament/tests/shouldfail/texitcode1.nim
Normal file
3
testament/tests/shouldfail/texitcode1.nim
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
discard """
|
||||||
|
exitcode: 1
|
||||||
|
"""
|
||||||
6
testament/tests/shouldfail/tfile.nim
Normal file
6
testament/tests/shouldfail/tfile.nim
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
discard """
|
||||||
|
file: "notthisfile.nim"
|
||||||
|
errmsg: "undeclared identifier: 'undefined'"
|
||||||
|
"""
|
||||||
|
|
||||||
|
echo undefined
|
||||||
8
testament/tests/shouldfail/tline.nim
Normal file
8
testament/tests/shouldfail/tline.nim
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
discard """
|
||||||
|
line: 9
|
||||||
|
column: 6
|
||||||
|
errormsg: "undeclared identifier: 'undeclared'"
|
||||||
|
"""
|
||||||
|
|
||||||
|
# test should fail because the line directive is wrong
|
||||||
|
echo undeclared
|
||||||
5
testament/tests/shouldfail/tmaxcodesize.nim
Normal file
5
testament/tests/shouldfail/tmaxcodesize.nim
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
discard """
|
||||||
|
maxcodesize: 1
|
||||||
|
"""
|
||||||
|
|
||||||
|
echo "Hello World"
|
||||||
6
testament/tests/shouldfail/tmsg.nim
Normal file
6
testament/tests/shouldfail/tmsg.nim
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
discard """
|
||||||
|
msg: "Hello World"
|
||||||
|
"""
|
||||||
|
|
||||||
|
static:
|
||||||
|
echo "something else"
|
||||||
7
testament/tests/shouldfail/tnimout.nim
Normal file
7
testament/tests/shouldfail/tnimout.nim
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
discard """
|
||||||
|
nimout: "Hello World!"
|
||||||
|
action: compile
|
||||||
|
"""
|
||||||
|
|
||||||
|
static:
|
||||||
|
echo "something else"
|
||||||
7
testament/tests/shouldfail/toutput.nim
Normal file
7
testament/tests/shouldfail/toutput.nim
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
discard """
|
||||||
|
output: '''
|
||||||
|
done
|
||||||
|
'''
|
||||||
|
"""
|
||||||
|
|
||||||
|
echo "broken"
|
||||||
5
testament/tests/shouldfail/toutputsub.nim
Normal file
5
testament/tests/shouldfail/toutputsub.nim
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
discard """
|
||||||
|
outputsub: "something else"
|
||||||
|
"""
|
||||||
|
|
||||||
|
echo "Hello World!"
|
||||||
11
testament/tests/shouldfail/tsortoutput.nim
Normal file
11
testament/tests/shouldfail/tsortoutput.nim
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
discard """
|
||||||
|
sortoutput: true
|
||||||
|
output: '''
|
||||||
|
2
|
||||||
|
1
|
||||||
|
'''
|
||||||
|
"""
|
||||||
|
|
||||||
|
# this test should ensure that the output is actually sorted
|
||||||
|
echo "2"
|
||||||
|
echo "1"
|
||||||
17
tests/testament/tshouldfail.nim
Normal file
17
tests/testament/tshouldfail.nim
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
discard """
|
||||||
|
cmd: "testament/tester --directory:testament --colors:off --nim:../compiler/nim category shouldfail"
|
||||||
|
action: compile
|
||||||
|
nimout: '''
|
||||||
|
FAIL: tccodecheck.nim C
|
||||||
|
FAIL: tcolumn.nim C
|
||||||
|
FAIL: terrormsg.nim C
|
||||||
|
FAIL: texitcode1.nim C
|
||||||
|
FAIL: tfile.nim C
|
||||||
|
FAIL: tline.nim C
|
||||||
|
FAIL: tmaxcodesize.nim C
|
||||||
|
FAIL: tnimout.nim C
|
||||||
|
FAIL: toutput.nim C
|
||||||
|
FAIL: toutputsub.nim C
|
||||||
|
FAIL: tsortoutput.nim C
|
||||||
|
'''
|
||||||
|
"""
|
||||||
Loading…
Add table
Add a link
Reference in a new issue