make megatest consistent with unjoined tests wrt newlines, honor newlines in output spec (#16151)

* fix megatest newlines
* still allow missing trailing newline for now but in a more strict way than before
This commit is contained in:
Timothee Cour 2020-11-28 00:09:31 -08:00 • committed by GitHub
commit b809562c7c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
33 changed files with 110 additions and 96 deletions

View file

@ -591,7 +591,9 @@ proc isJoinableSpec(spec: TSpec): bool =
if spec.file.readFile.contains "when isMainModule": if spec.file.readFile.contains "when isMainModule":
result = false result = false
proc norm(s: var string) = when false:
proc norm(s: var string) =
## strip empty newlines
while true: while true:
let tmp = s.replace("\n\n", "\n") let tmp = s.replace("\n\n", "\n")
if tmp == s: break if tmp == s: break
@ -654,16 +656,16 @@ proc runJoinedTest(r: var TResults, cat: Category, testsDir: string) =
echo buf.string echo buf.string
quit(failString & "megatest execution failed") quit(failString & "megatest execution failed")
norm buf.string
const outputExceptedFile = "outputExpected.txt" const outputExceptedFile = "outputExpected.txt"
const outputGottenFile = "outputGotten.txt" const outputGottenFile = "outputGotten.txt"
writeFile(outputGottenFile, buf.string) writeFile(outputGottenFile, buf.string)
var outputExpected = "" var outputExpected = ""
for i, runSpec in specs: for i, runSpec in specs:
outputExpected.add marker & runSpec.file & "\n" outputExpected.add marker & runSpec.file & "\n"
outputExpected.add runSpec.output.strip if runSpec.output.len > 0:
outputExpected.add runSpec.output
if not runSpec.output.endsWith "\n":
outputExpected.add '\n' outputExpected.add '\n'
norm outputExpected
if buf.string != outputExpected: if buf.string != outputExpected:
writeFile(outputExceptedFile, outputExpected) writeFile(outputExceptedFile, outputExpected)

View file

@ -280,7 +280,7 @@ proc parseSpec*(filename: string): TSpec =
of "output": of "output":
if result.outputCheck != ocSubstr: if result.outputCheck != ocSubstr:
result.outputCheck = ocEqual result.outputCheck = ocEqual
result.output = strip(e.value) result.output = e.value
of "input": of "input":
result.input = e.value result.input = e.value
of "outputsub": of "outputsub":

View file

@ -469,6 +469,10 @@ proc checkDisabled(r: var TResults, test: TTest): bool =
var count = 0 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, proc testSpecHelper(r: var TResults, test: var TTest, expected: TSpec,
target: TTarget, nimcache: string, extraOptions = "") = target: TTarget, nimcache: string, extraOptions = "") =
test.startTime = epochTime() test.startTime = epochTime()
@ -513,16 +517,18 @@ proc testSpecHelper(r: var TResults, test: var TTest, expected: TSpec,
if exitCode != 0: exitCode = 1 if exitCode != 0: exitCode = 1
let bufB = let bufB =
if expected.sortoutput: if expected.sortoutput:
var x = splitLines(strip(buf.string)) var buf2 = buf.string
buf2.stripLineEnd
var x = splitLines(buf2)
sort(x, system.cmp) sort(x, system.cmp)
join(x, "\n") join(x, "\n") & "\n"
else: else:
strip(buf.string) buf.string
if exitCode != expected.exitCode: if exitCode != expected.exitCode:
r.addResult(test, target, "exitcode: " & $expected.exitCode, r.addResult(test, target, "exitcode: " & $expected.exitCode,
"exitcode: " & $exitCode & "\n\nOutput:\n" & "exitcode: " & $exitCode & "\n\nOutput:\n" &
bufB, reExitcodesDiffer) 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): (expected.outputCheck == ocSubstr and expected.output notin bufB):
given.err = reOutputsDiffer given.err = reOutputsDiffer
r.addResult(test, target, expected.output, bufB, reOutputsDiffer) r.addResult(test, target, expected.output, bufB, reOutputsDiffer)

View file

@ -1,5 +1,7 @@
discard """ discard """
output: '''verstuff''' output: '''
verstuff
'''
cmd: "nim c --gc:arc $file" cmd: "nim c --gc:arc $file"
""" """

View file

@ -1,7 +1,8 @@
discard """ discard """
output: '''string 1 output: '''string 1
string 2 string 2
string 3''' string 3
'''
""" """
# bug #5532 # bug #5532
import os, asyncfile, asyncdispatch import os, asyncfile, asyncdispatch

View file

@ -1,6 +1,8 @@
discard """ discard """
output: ''' output: '''
''' '''
""" """

View file

@ -3,7 +3,7 @@ discard """
output: ''' output: '''
z z
e e
''' '''
""" """
type type

View file

@ -1,8 +1,9 @@
discard """ discard """
targets: "c cpp" targets: "c cpp"
output: '''Hello output: '''
Hello Hello
''' Hello
'''
""" """
proc test[T]() = proc test[T]() =
try: try:

View file

@ -1,5 +1,6 @@
discard """ discard """
output: ''' output: '''
BEFORE BEFORE
FINALLY FINALLY

View file

@ -2,21 +2,13 @@ discard """
output: ''' output: '''
(10, ("test", 1.2)) (10, ("test", 1.2))
3x3 Matrix [[0.0, 2.0, 3.0], [2.0, 0.0, 5.0], [2.0, 0.0, 5.0]] 3x3 Matrix [[0.0, 2.0, 3.0], [2.0, 0.0, 5.0], [2.0, 0.0, 5.0]]
2x3 Matrix [[0.0, 2.0, 3.0], [2.0, 0.0, 5.0]] 2x3 Matrix [[0.0, 2.0, 3.0], [2.0, 0.0, 5.0]]
2x3 Literal [[0.0, 2.0, 3.0], [2.0, 0.0, 5.0]] 2x3 Literal [[0.0, 2.0, 3.0], [2.0, 0.0, 5.0]]
2x3 Matrix [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0]] 2x3 Matrix [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0]]
2x2 ArrayArray[[0.0, 0.0, 0.0], [0.0, 0.0, 0.0]] 2x2 ArrayArray[[0.0, 0.0, 0.0], [0.0, 0.0, 0.0]]
2x3 ArrayVector[[0.0, 0.0, 0.0], [0.0, 0.0, 0.0]] 2x3 ArrayVector[[0.0, 0.0, 0.0], [0.0, 0.0, 0.0]]
2x3 VectorVector [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0]] 2x3 VectorVector [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0]]
2x3 VectorArray [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0]] 2x3 VectorArray [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0]]
@[1, 2] @[1, 2]
@[1, 2] @[1, 2]
@[1, 2]@[3, 4] @[1, 2]@[3, 4]

View file

@ -1,7 +1,9 @@
discard """ discard """
output: ''' output: '''
[Suite] Bacon [Suite] Bacon
[OK] >:)''' [OK] >:)
'''
""" """
import unittest import unittest

View file

@ -1,7 +1,7 @@
discard """ discard """
output: ''' output: '''
[Suite] memoization
[Suite] memoization
''' '''
""" """

View file

@ -1,5 +1,6 @@
discard """ discard """
output: ''' output: '''
var data = @[(1, "one"), (2, "two")] var data = @[(1, "one"), (2, "two")]
for (i, d) in pairs(data): for (i, d) in pairs(data):
discard discard

View file

@ -5,6 +5,7 @@ res: yes
yes yes
running someProc(false) running someProc(false)
res: res:
''' '''
""" """

View file

@ -1,5 +1,5 @@
discard """ discard """
output: "" output: "\n"
""" """
type Matrix[M,N: static[int]] = array[M, array[N, float]] type Matrix[M,N: static[int]] = array[M, array[N, float]]

View file

@ -1,13 +1,11 @@
discard """ discard """
output: '''before tensor2: output: '''
before tensor2:
[0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0] [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0]
before tensor3: before tensor3:
[0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0, 25.0, 26.0] [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0, 25.0, 26.0]
after tensor3: after tensor3:
[0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0, 25.0, 26.0] [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0, 25.0, 26.0]
a3: a3:
[1000.0, 1001.0, 1002.0, 1003.0, 1004.0, 1005.0, 1006.0, 1007.0, 1008.0, 1009.0, 1010.0, 1011.0, 1012.0, 1013.0, 1014.0, 1015.0, 1016.0, 1017.0, 1018.0, 1019.0, 1020.0, 1021.0, 1022.0, 1023.0, 1024.0, 1025.0, 1026.0]''' [1000.0, 1001.0, 1002.0, 1003.0, 1004.0, 1005.0, 1006.0, 1007.0, 1008.0, 1009.0, 1010.0, 1011.0, 1012.0, 1013.0, 1014.0, 1015.0, 1016.0, 1017.0, 1018.0, 1019.0, 1020.0, 1021.0, 1022.0, 1023.0, 1024.0, 1025.0, 1026.0]'''
""" """

View file

@ -1,2 +1,6 @@
discard """
output: "\n"
"""
echo() echo()

View file

@ -1,5 +1,5 @@
discard """ discard """
output: "[Suite] object basic methods" output: "\n[Suite] object basic methods"
""" """
import unittest import unittest

View file

@ -1,6 +1,8 @@
discard """ discard """
output: ''' output: '''
9.0''' 9.0
'''
""" """
### bug #6773 ### bug #6773
@ -41,6 +43,7 @@ proc `^`(x: vfloat, exp: static[float]): vfloat =
proc `$`(x: vfloat): string = proc `$`(x: vfloat): string =
let y = cast[ptr float](unsafeAddr x) let y = cast[ptr float](unsafeAddr x)
# xxx not sure if intentional in this issue, but this returns ""
echo y[] echo y[]
let x = set1(9.0) let x = set1(9.0)

View file

@ -1,5 +1,6 @@
discard """ discard """
output: ''' output: '''
10 10
assigning z = 20 assigning z = 20
reading field y reading field y
@ -12,7 +13,8 @@ no params call to b
100 100
one param call to c with 10 one param call to c with 10
100 100
0 4''' 0 4
'''
""" """
type type

View file

@ -1,13 +1,9 @@
discard """ discard """
output: ''' output: '''
[[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]] [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[1, 2, 3, 4] [1, 2, 3, 4]
''' '''
""" """

View file

@ -1,6 +1,6 @@
discard """ discard """
output:'''@["3", "2", "1"] output:'''@["3", "2", "1"]
''' '''
""" """
#12928,10456 #12928,10456
import sequtils, strutils, algorithm, json import sequtils, strutils, algorithm, json

View file

@ -1,5 +1,6 @@
discard """ discard """
output: ''' output: '''
[Suite] Test cgi module [Suite] Test cgi module
(key: "a", value: "1") (key: "a", value: "1")
(key: "b", value: "0") (key: "b", value: "0")

View file

@ -1,6 +1,8 @@
discard """ discard """
action: run action: run
output: '''[Suite] random int output: '''
[Suite] random int
[Suite] random float [Suite] random float
@ -9,7 +11,6 @@ discard """
[Suite] random sample [Suite] random sample
[Suite] ^ [Suite] ^
''' '''
""" """

View file

@ -1,6 +1,7 @@
discard """ discard """
action: run action: run
output: ''' output: '''
[Suite] inet_ntop tests [Suite] inet_ntop tests
''' '''
""" """

View file

@ -4,7 +4,9 @@ discard """
# codes to differ and be reported as a failure # codes to differ and be reported as a failure
output: output:
'''[Suite] Test NRE initialization '''
[Suite] Test NRE initialization
[Suite] captures [Suite] captures

View file

@ -1,12 +1,13 @@
discard """ discard """
action: run action: run
output: ''' output: '''
[Suite] parseutils'''
[Suite] parseutils
'''
""" """
import unittest, strutils import unittest, strutils
suite "parseutils": suite "parseutils":
test "uint":
check: parseBiggestUInt("0") == 0'u64 check: parseBiggestUInt("0") == 0'u64
check: parseBiggestUInt("18446744073709551615") == 0xFFFF_FFFF_FFFF_FFFF'u64 check: parseBiggestUInt("18446744073709551615") == 0xFFFF_FFFF_FFFF_FFFF'u64
expect(ValueError): expect(ValueError):

View file

@ -1,5 +1,6 @@
discard """ discard """
output: ''' output: '''
[Suite] RST include directive [Suite] RST include directive
''' '''
""" """

View file

@ -455,6 +455,3 @@ block:
yield i yield i
doAssert: iter(3).mapIt(2*it).foldl(a + b) == 6 doAssert: iter(3).mapIt(2*it).foldl(a + b) == 6
when not defined(testing):
echo "Finished doc tests"

View file

@ -1,5 +1,7 @@
discard """ discard """
output: '''[Suite] suite with only teardown output: '''
[Suite] suite with only teardown
[Suite] suite with only setup [Suite] suite with only setup
@ -16,7 +18,6 @@ discard """
[Suite] test suite [Suite] test suite
[Suite] test name filtering [Suite] test name filtering
''' '''
""" """
@ -141,8 +142,7 @@ suite "test suite":
check(a == b) check(a == b)
when defined(testing): suite "test name filtering":
suite "test name filtering":
test "test name": test "test name":
check matchFilter("suite1", "foo", "") check matchFilter("suite1", "foo", "")
check matchFilter("suite1", "foo", "foo") check matchFilter("suite1", "foo", "foo")

View file

@ -2,10 +2,8 @@ discard """
output: ''' output: '''
1 1
[a, b] [a, b]
2 2
[c, d] [c, d]
4 4
[e, f]''' [e, f]'''
""" """

View file

@ -1,8 +1,6 @@
discard """ discard """
output: '''[0.0, 0.0, 0.0] output: '''[0.0, 0.0, 0.0]
[0.0, 0.0, 0.0, 0.0] [0.0, 0.0, 0.0, 0.0]
5050 5050
123''' 123'''
""" """