nimsuggest: make all tests green
This commit is contained in:
parent
2adb4ce9eb
commit
2df5a6f863
2 changed files with 34 additions and 31 deletions
|
|
@ -402,14 +402,18 @@ proc mainThread(graph: ModuleGraph; cache: IdentCache) =
|
||||||
logStr(PStrEntry(it).data)
|
logStr(PStrEntry(it).data)
|
||||||
it = it.next
|
it = it.next
|
||||||
|
|
||||||
msgs.writelnHook = writelnToChannel
|
proc wrHook(line: string) {.closure.} =
|
||||||
|
if gMode == mepc: discard
|
||||||
|
else: writelnToChannel(line)
|
||||||
|
|
||||||
|
msgs.writelnHook = wrHook
|
||||||
suggestionResultHook = sugResultHook
|
suggestionResultHook = sugResultHook
|
||||||
graph.doStopCompile = proc (): bool = requests.peek() > 0
|
graph.doStopCompile = proc (): bool = requests.peek() > 0
|
||||||
var idle = 0
|
var idle = 0
|
||||||
while true:
|
while true:
|
||||||
let (hasData, req) = requests.tryRecv()
|
let (hasData, req) = requests.tryRecv()
|
||||||
if hasData:
|
if hasData:
|
||||||
msgs.writelnHook = writelnToChannel
|
msgs.writelnHook = wrHook
|
||||||
suggestionResultHook = sugResultHook
|
suggestionResultHook = sugResultHook
|
||||||
|
|
||||||
execCmd(req, graph, cache)
|
execCmd(req, graph, cache)
|
||||||
|
|
|
||||||
|
|
@ -176,7 +176,7 @@ proc sexpToAnswer(s: SexpNode): string =
|
||||||
let typ = a[4].getStr
|
let typ = a[4].getStr
|
||||||
let line = a[5].getNum
|
let line = a[5].getNum
|
||||||
let col = a[6].getNum
|
let col = a[6].getNum
|
||||||
let doc = a[7].getStr.escapeJson
|
let doc = a[7].getStr.escape
|
||||||
result.add section
|
result.add section
|
||||||
result.add '\t'
|
result.add '\t'
|
||||||
result.add symk
|
result.add symk
|
||||||
|
|
@ -201,6 +201,20 @@ proc sexpToAnswer(s: SexpNode): string =
|
||||||
result.add "100"
|
result.add "100"
|
||||||
result.add '\L'
|
result.add '\L'
|
||||||
|
|
||||||
|
proc doReport(filename, answer, resp: string; report: var string) =
|
||||||
|
if resp != answer and not smartCompare(resp, answer):
|
||||||
|
report.add "\nTest failed: " & filename
|
||||||
|
var hasDiff = false
|
||||||
|
for i in 0..min(resp.len-1, answer.len-1):
|
||||||
|
if resp[i] != answer[i]:
|
||||||
|
report.add "\n Expected: " & resp.substr(i)
|
||||||
|
report.add "\n But got: " & answer.substr(i)
|
||||||
|
hasDiff = true
|
||||||
|
break
|
||||||
|
if not hasDiff:
|
||||||
|
report.add "\n Expected: " & resp
|
||||||
|
report.add "\n But got: " & answer
|
||||||
|
|
||||||
proc runEpcTest(filename: string): int =
|
proc runEpcTest(filename: string): int =
|
||||||
let s = parseTest filename
|
let s = parseTest filename
|
||||||
for cmd in s.startup:
|
for cmd in s.startup:
|
||||||
|
|
@ -224,19 +238,10 @@ proc runEpcTest(filename: string): int =
|
||||||
for req, resp in items(s.script):
|
for req, resp in items(s.script):
|
||||||
if not runCmd(req, s.dest):
|
if not runCmd(req, s.dest):
|
||||||
socket.sendEpcStr(req)
|
socket.sendEpcStr(req)
|
||||||
var answer = sexpToAnswer(parseSexp(socket.recvEpc()))
|
let sx = parseSexp(socket.recvEpc())
|
||||||
if resp != answer and not smartCompare(resp, answer):
|
if not req.startsWith("mod "):
|
||||||
report.add "\nTest failed: " & filename
|
let answer = sexpToAnswer(sx)
|
||||||
var hasDiff = false
|
doReport(filename, answer, resp, report)
|
||||||
for i in 0..min(resp.len-1, answer.len-1):
|
|
||||||
if resp[i] != answer[i]:
|
|
||||||
report.add "\n Expected: " & resp.substr(i)
|
|
||||||
report.add "\n But got: " & answer.substr(i)
|
|
||||||
hasDiff = true
|
|
||||||
break
|
|
||||||
if not hasDiff:
|
|
||||||
report.add "\n Expected: " & resp
|
|
||||||
report.add "\n But got: " & answer
|
|
||||||
else:
|
else:
|
||||||
raise newException(ValueError, "cannot read port number")
|
raise newException(ValueError, "cannot read port number")
|
||||||
finally:
|
finally:
|
||||||
|
|
@ -272,18 +277,7 @@ proc runTest(filename: string): int =
|
||||||
if a == DummyEof: break
|
if a == DummyEof: break
|
||||||
answer.add a
|
answer.add a
|
||||||
answer.add '\L'
|
answer.add '\L'
|
||||||
if resp != answer and not smartCompare(resp, answer):
|
doReport(filename, answer, resp, report)
|
||||||
report.add "\nTest failed: " & filename
|
|
||||||
var hasDiff = false
|
|
||||||
for i in 0..min(resp.len-1, answer.len-1):
|
|
||||||
if resp[i] != answer[i]:
|
|
||||||
report.add "\n Expected: " & resp.substr(i)
|
|
||||||
report.add "\n But got: " & answer.substr(i)
|
|
||||||
hasDiff = true
|
|
||||||
break
|
|
||||||
if not hasDiff:
|
|
||||||
report.add "\n Expected: " & resp
|
|
||||||
report.add "\n But got: " & answer
|
|
||||||
finally:
|
finally:
|
||||||
inp.writeLine("quit")
|
inp.writeLine("quit")
|
||||||
inp.flush()
|
inp.flush()
|
||||||
|
|
@ -295,11 +289,16 @@ proc runTest(filename: string): int =
|
||||||
|
|
||||||
proc main() =
|
proc main() =
|
||||||
var failures = 0
|
var failures = 0
|
||||||
for x in walkFiles(getAppDir() / "tests/t*.nim"):
|
when false:
|
||||||
echo "Test ", x
|
let x = getAppDir() / "tests/twithin_macro.nim"
|
||||||
let xx = expandFilename x
|
let xx = expandFilename x
|
||||||
failures += runTest(xx)
|
|
||||||
failures += runEpcTest(xx)
|
failures += runEpcTest(xx)
|
||||||
|
else:
|
||||||
|
for x in walkFiles(getAppDir() / "tests/t*.nim"):
|
||||||
|
echo "Test ", x
|
||||||
|
let xx = expandFilename x
|
||||||
|
failures += runTest(xx)
|
||||||
|
failures += runEpcTest(xx)
|
||||||
if failures > 0:
|
if failures > 0:
|
||||||
quit 1
|
quit 1
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue