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

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

View File

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

View File

@@ -11,7 +11,8 @@
import
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
resultsFile = "testresults.html"
@@ -150,6 +151,11 @@ proc codegenCheck(test: TTest, check: string, given: var TSpec) =
except EIO:
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) =
# major entry point for a single test
let tname = test.name.addFileExt(".nim")
@@ -191,7 +197,9 @@ proc testSpec(r: var TResults, test: TTest) =
r.addResult(test, "exitcode: " & $expected.exitCode,
"exitcode: " & $exitCode, reExitCodesDiffer)
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):
given.err = reOutputsDiffer
if given.err == reSuccess: