This commit is contained in:
Arne Döring 2018-11-21 14:39:06 +01:00 • committed by Araq
commit fa6a9a21e0
3 changed files with 39 additions and 30 deletions

View file

@ -521,6 +521,8 @@ proc processCategory(r: var TResults, cat: Category, options: string) =
testNimblePackages(r, cat, pfAll) testNimblePackages(r, cat, pfAll)
of "niminaction": of "niminaction":
testNimInAction(r, cat, options) testNimInAction(r, cat, options)
of "testament":
testTestament(r, cat, options)
of "untestable": of "untestable":
# We can't test it because it depends on a third party. # We can't test it because it depends on a third party.
discard # TODO: Move untestable tests to someplace else, i.e. nimble repo. discard # TODO: Move untestable tests to someplace else, i.e. nimble repo.

View file

@ -25,6 +25,11 @@ type
actionReject = "reject" actionReject = "reject"
actionRunNoSpec = "runNoSpec" actionRunNoSpec = "runNoSpec"
TOutputCheck* = enum
ocIgnore = "ignore"
ocEqual = "equal"
ocSubstr = "substr"
TResultEnum* = enum TResultEnum* = enum
reNimcCrash, # nim compiler seems to have crashed reNimcCrash, # nim compiler seems to have crashed
reMsgsDiffer, # error messages differ reMsgsDiffer, # error messages differ
@ -51,6 +56,8 @@ type
action*: TTestAction action*: TTestAction
file*, cmd*: string file*, cmd*: string
input*: string input*: string
outputCheck*: TOutputCheck
sortoutput*: bool
outp*: string outp*: string
line*, column*: int line*, column*: int
tfile*: string tfile*: string
@ -60,7 +67,6 @@ type
ccodeCheck*: string ccodeCheck*: string
maxCodeSize*: int maxCodeSize*: int
err*: TResultEnum err*: TResultEnum
substr*, sortoutput*: bool
targets*: set[TTarget] targets*: set[TTarget]
nimout*: string nimout*: string
@ -145,14 +151,13 @@ proc parseSpec*(filename: string): TSpec =
of "tline": discard parseInt(e.value, result.tline) of "tline": discard parseInt(e.value, result.tline)
of "tcolumn": discard parseInt(e.value, result.tcolumn) of "tcolumn": discard parseInt(e.value, result.tcolumn)
of "output": of "output":
result.action = actionRun result.outputCheck = ocEqual
result.outp = e.value result.outp = strip(e.value)
of "input": of "input":
result.input = e.value result.input = e.value
of "outputsub": of "outputsub":
result.action = actionRun result.outputCheck = ocSubstr
result.outp = e.value result.outp = strip(e.value)
result.substr = true
of "sortoutput": of "sortoutput":
result.sortoutput = parseCfgBool(e.value) result.sortoutput = parseCfgBool(e.value)
of "exitcode": of "exitcode":

View file

@ -328,11 +328,6 @@ proc nimoutCheck(test: TTest; expectedNimout: string; given: var TSpec) =
given.err = reMsgsDiffer given.err = reMsgsDiffer
return return
proc makeDeterministic(s: string): string =
var x = splitLines(s)
sort(x, system.cmp)
result = join(x, "\n")
proc compilerOutputTests(test: TTest, target: TTarget, given: var TSpec, proc compilerOutputTests(test: TTest, target: TTarget, given: var TSpec,
expected: TSpec; r: var TResults) = expected: TSpec; r: var TResults) =
var expectedmsg: string = "" var expectedmsg: string = ""
@ -350,27 +345,31 @@ proc compilerOutputTests(test: TTest, target: TTarget, given: var TSpec,
if given.err == reSuccess: inc(r.passed) if given.err == reSuccess: inc(r.passed)
r.addResult(test, target, expectedmsg, givenmsg, given.err) r.addResult(test, target, expectedmsg, givenmsg, given.err)
proc testSpec(r: var TResults, test: TTest, target = targetC) = proc testSpec(r: var TResults, test: TTest, targets: set[TTarget] = {}) =
let tname = test.name.addFileExt(".nim") let tname = test.name.addFileExt(".nim")
var expected: TSpec var expected: TSpec
if test.action != actionRunNoSpec: if test.action != actionRunNoSpec:
expected = parseSpec(tname) expected = parseSpec(tname)
if test.action == actionRun and expected.action == actionCompile:
expected.action = actionRun
else: else:
specDefaults expected specDefaults expected
expected.action = actionRunNoSpec expected.action = actionRunNoSpec
expected.outputCheck = ocIgnore # this is default so it is unnecessary
if expected.err == reIgnored: if expected.err == reIgnored:
r.addResult(test, target, "", "", reIgnored) # targetC is a lie
r.addResult(test, targetC, "", "", reIgnored)
inc(r.skipped) inc(r.skipped)
inc(r.total) inc(r.total)
return return
if getEnv("NIM_COMPILE_TO_CPP", "false").string == "true" and target == targetC and expected.targets == {}: expected.targets.incl targets
expected.targets.incl(targetCpp)
elif expected.targets == {}: # still no target specified at all
expected.targets.incl(target) if expected.targets == {}:
if getEnv("NIM_COMPILE_TO_CPP", "false").string == "true":
expected.targets = {targetCpp}
else:
expected.targets = {targetC}
for target in expected.targets: for target in expected.targets:
inc(r.total) inc(r.total)
@ -433,9 +432,13 @@ proc testSpec(r: var TResults, test: TTest, target = targetC) =
# to return other codes, but for us it is sufficient to know that it's not 0. # to return other codes, but for us it is sufficient to know that it's not 0.
if exitCode != 0: exitCode = 1 if exitCode != 0: exitCode = 1
let bufB = if expected.sortoutput: makeDeterministic(strip(buf.string)) let bufB =
else: strip(buf.string) if expected.sortoutput:
let expectedOut = strip(expected.outp) var x = splitLines(strip(buf.string))
sort(x, system.cmp)
join(x, "\n")
else:
strip(buf.string)
if exitCode != expected.exitCode: if exitCode != expected.exitCode:
r.addResult(test, target, "exitcode: " & $expected.exitCode, r.addResult(test, target, "exitcode: " & $expected.exitCode,
@ -443,11 +446,11 @@ proc testSpec(r: var TResults, test: TTest, target = targetC) =
bufB, reExitCodesDiffer) bufB, reExitCodesDiffer)
continue continue
if bufB != expectedOut and expected.action != actionRunNoSpec: if (expected.outputCheck == ocEqual and bufB != expected.outp) or
if not (expected.substr and expectedOut in bufB): (expected.outputCheck == ocSubstr and bufB notin expected.outp):
given.err = reOutputsDiffer given.err = reOutputsDiffer
r.addResult(test, target, expected.outp, bufB, reOutputsDiffer) r.addResult(test, target, expected.outp, bufB, reOutputsDiffer)
continue continue
compilerOutputTests(test, target, given, expected, r) compilerOutputTests(test, target, given, expected, r)
continue continue
@ -495,11 +498,10 @@ proc testExec(r: var TResults, test: TTest) =
if given.err == reSuccess: inc(r.passed) if given.err == reSuccess: inc(r.passed)
r.addResult(test, targetC, "", given.msg, given.err) r.addResult(test, targetC, "", given.msg, given.err)
proc makeTest(test, options: string, cat: Category, action = actionCompile, proc makeTest(test, options: string, cat: Category,
env: string = ""): TTest = env: string = ""): TTest =
# start with 'actionCompile', will be overwritten in the spec: # start with 'actionCompile', will be overwritten in the spec:
result = TTest(cat: cat, name: test, options: options, result = TTest(cat: cat, name: test, options: options, startTime: epochTime())
action: action, startTime: epochTime())
when defined(windows): when defined(windows):
const const