diff options
Diffstat (limited to 'testament')
-rw-r--r-- | testament/categories.nim | 22 | ||||
-rw-r--r-- | testament/specs.nim | 2 | ||||
-rw-r--r-- | testament/testament.nim | 14 |
3 files changed, 23 insertions, 15 deletions
diff --git a/testament/categories.nim b/testament/categories.nim index 0d19842ec..4f6e40659 100644 --- a/testament/categories.nim +++ b/testament/categories.nim @@ -591,12 +591,14 @@ proc isJoinableSpec(spec: TSpec): bool = if spec.file.readFile.contains "when isMainModule": result = false -proc norm(s: var string) = - while true: - let tmp = s.replace("\n\n", "\n") - if tmp == s: break - s = tmp - s = s.strip +when false: + proc norm(s: var string) = + ## strip empty newlines + while true: + let tmp = s.replace("\n\n", "\n") + if tmp == s: break + s = tmp + s = s.strip proc quoted(a: string): string = # todo: consider moving to system.nim @@ -654,16 +656,16 @@ proc runJoinedTest(r: var TResults, cat: Category, testsDir: string) = echo buf.string quit(failString & "megatest execution failed") - norm buf.string const outputExceptedFile = "outputExpected.txt" const outputGottenFile = "outputGotten.txt" writeFile(outputGottenFile, buf.string) var outputExpected = "" for i, runSpec in specs: outputExpected.add marker & runSpec.file & "\n" - outputExpected.add runSpec.output.strip - outputExpected.add '\n' - norm outputExpected + if runSpec.output.len > 0: + outputExpected.add runSpec.output + if not runSpec.output.endsWith "\n": + outputExpected.add '\n' if buf.string != outputExpected: writeFile(outputExceptedFile, outputExpected) diff --git a/testament/specs.nim b/testament/specs.nim index eaae598bb..37fe12275 100644 --- a/testament/specs.nim +++ b/testament/specs.nim @@ -280,7 +280,7 @@ proc parseSpec*(filename: string): TSpec = of "output": if result.outputCheck != ocSubstr: result.outputCheck = ocEqual - result.output = strip(e.value) + result.output = e.value of "input": result.input = e.value of "outputsub": diff --git a/testament/testament.nim b/testament/testament.nim index 2912b03ab..94f66c2db 100644 --- a/testament/testament.nim +++ b/testament/testament.nim @@ -469,6 +469,10 @@ proc checkDisabled(r: var TResults, test: TTest): bool = var count = 0 +proc equalModuloLastNewline(a, b: string): bool = + # allow lazy output spec that omits last newline, but really those should be fixed instead + result = a == b or b.endsWith("\n") and a == b[0 ..< ^1] + proc testSpecHelper(r: var TResults, test: var TTest, expected: TSpec, target: TTarget, nimcache: string, extraOptions = "") = test.startTime = epochTime() @@ -513,16 +517,18 @@ proc testSpecHelper(r: var TResults, test: var TTest, expected: TSpec, if exitCode != 0: exitCode = 1 let bufB = if expected.sortoutput: - var x = splitLines(strip(buf.string)) + var buf2 = buf.string + buf2.stripLineEnd + var x = splitLines(buf2) sort(x, system.cmp) - join(x, "\n") + join(x, "\n") & "\n" else: - strip(buf.string) + buf.string if exitCode != expected.exitCode: r.addResult(test, target, "exitcode: " & $expected.exitCode, "exitcode: " & $exitCode & "\n\nOutput:\n" & bufB, reExitcodesDiffer) - elif (expected.outputCheck == ocEqual and expected.output != bufB) or + elif (expected.outputCheck == ocEqual and not expected.output.equalModuloLastNewline(bufB)) or (expected.outputCheck == ocSubstr and expected.output notin bufB): given.err = reOutputsDiffer r.addResult(test, target, expected.output, bufB, reOutputsDiffer) |