added 'sortoutput' option to make output deterministic for threading tests

This commit is contained in:
Araq 2014-05-29 13:19:26 +02:00
commit f12a0820e0
2 changed files with 13 additions and 3 deletions

View file

@ -46,7 +46,7 @@ type
msg*: string msg*: string
ccodeCheck*: string ccodeCheck*: string
err*: TResultEnum err*: TResultEnum
substr*: bool substr*, sortoutput*: bool
targets*: set[TTarget] targets*: set[TTarget]
const const
@ -113,6 +113,8 @@ proc parseSpec*(filename: string): TSpec =
result.action = actionRun result.action = actionRun
result.outp = e.value result.outp = e.value
result.substr = true result.substr = true
of "sortoutput":
result.sortoutput = parseCfgBool(e.value)
of "exitcode": of "exitcode":
discard parseInt(e.value, result.exitCode) discard parseInt(e.value, result.exitCode)
of "msg": of "msg":

View file

@ -11,7 +11,8 @@
import import
parseutils, strutils, pegs, os, osproc, streams, parsecfg, json, parseutils, strutils, pegs, os, osproc, streams, parsecfg, json,
marshal, backend, parseopt, specs, htmlgen, browsers, terminal marshal, backend, parseopt, specs, htmlgen, browsers, terminal, sequtils,
algorithm
const const
resultsFile = "testresults.html" resultsFile = "testresults.html"
@ -150,6 +151,11 @@ proc codegenCheck(test: TTest, check: string, given: var TSpec) =
except EIO: except EIO:
given.err = reCodeNotFound given.err = reCodeNotFound
proc makeDeterministic(s: string): string =
var x = toSeq(s.lines)
sort(x, system.cmp)
result = join(x, "\n")
proc testSpec(r: var TResults, test: TTest) = proc testSpec(r: var TResults, test: TTest) =
# major entry point for a single test # major entry point for a single test
let tname = test.name.addFileExt(".nim") let tname = test.name.addFileExt(".nim")
@ -191,7 +197,9 @@ proc testSpec(r: var TResults, test: TTest) =
r.addResult(test, "exitcode: " & $expected.exitCode, r.addResult(test, "exitcode: " & $expected.exitCode,
"exitcode: " & $exitCode, reExitCodesDiffer) "exitcode: " & $exitCode, reExitCodesDiffer)
else: else:
if strip(buf.string) != strip(expected.outp): var bufB = strip(buf.string)
if expected.sortoutput: bufB = makeDeterministic(bufB)
if bufB != strip(expected.outp):
if not (expected.substr and expected.outp in buf.string): if not (expected.substr and expected.outp in buf.string):
given.err = reOutputsDiffer given.err = reOutputsDiffer
if given.err == reSuccess: if given.err == reSuccess: