diff options
author | Araq <rumpf_a@web.de> | 2014-05-29 13:19:26 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2014-05-29 13:19:26 +0200 |
commit | f12a0820e0e7e5c32378bb56b8d0d2591fc71ae5 (patch) | |
tree | a0f36a7ec4ef635eba2d6b82c51ae6aa575e6f62 /tests | |
parent | 030eac86c05427792d3c3c00b56fbe764d783a40 (diff) | |
download | Nim-f12a0820e0e7e5c32378bb56b8d0d2591fc71ae5.tar.gz |
added 'sortoutput' option to make output deterministic for threading tests
Diffstat (limited to 'tests')
-rw-r--r-- | tests/testament/specs.nim | 4 | ||||
-rw-r--r-- | tests/testament/tester.nim | 12 |
2 files changed, 13 insertions, 3 deletions
diff --git a/tests/testament/specs.nim b/tests/testament/specs.nim index 225ea1891..6e72f4b5e 100644 --- a/tests/testament/specs.nim +++ b/tests/testament/specs.nim @@ -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": diff --git a/tests/testament/tester.nim b/tests/testament/tester.nim index 50d0e6eac..adf9785e0 100644 --- a/tests/testament/tester.nim +++ b/tests/testament/tester.nim @@ -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: |