mirror of https://github.com/status-im/NimYAML.git
make tests green again; final fix for 0.17.0
This commit is contained in:
parent
0caebe2618
commit
0f2dba1a65
|
@ -21,5 +21,4 @@ docout
|
||||||
doc/rstPreproc
|
doc/rstPreproc
|
||||||
doc/tmp.rst
|
doc/tmp.rst
|
||||||
doc/**/code
|
doc/**/code
|
||||||
test/yaml-test-suite
|
|
||||||
nimsuggest.log
|
nimsuggest.log
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
[submodule "test/yaml-test-suite"]
|
||||||
|
path = test/yaml-test-suite
|
||||||
|
url = https://github.com/yaml/yaml-test-suite.git
|
||||||
|
branch = data
|
105
test/tparser.nim
105
test/tparser.nim
|
@ -4,55 +4,18 @@
|
||||||
# See the file "copying.txt", included in this
|
# See the file "copying.txt", included in this
|
||||||
# distribution, for details about the copyright.
|
# distribution, for details about the copyright.
|
||||||
|
|
||||||
import os, osproc, terminal, strutils, streams, macros, unittest
|
import os, osproc, terminal, strutils, streams, macros, unittest, sets
|
||||||
import testEventParser, commonTestUtils
|
import testEventParser, commonTestUtils
|
||||||
import "../yaml"
|
import "../yaml"
|
||||||
|
|
||||||
const
|
const
|
||||||
testSuiteFolder = "yaml-test-suite"
|
testSuiteFolder = "yaml-test-suite"
|
||||||
testSuiteUrl = "https://github.com/yaml/yaml-test-suite.git"
|
|
||||||
|
|
||||||
proc echoError(msg: string) =
|
proc echoError(msg: string) =
|
||||||
styledWriteLine(stdout, fgRed, "[error] ", fgWhite, msg, resetStyle)
|
styledWriteLine(stdout, fgRed, "[error] ", fgWhite, msg, resetStyle)
|
||||||
|
|
||||||
proc ensureTestSuiteCloneCorrect(pwd: string) {.compileTime.} =
|
|
||||||
let absolutePath = pwd / testSuiteFolder
|
|
||||||
if dirExists(absolutePath):
|
|
||||||
var isCorrectClone = true
|
|
||||||
if dirExists(absolutePath / ".git"):
|
|
||||||
let remoteUrl =
|
|
||||||
staticExec("cd \"" & absolutePath & "\" && git remote get-url origin").strip
|
|
||||||
if remoteUrl != testSuiteUrl:
|
|
||||||
isCorrectClone = false
|
|
||||||
let branches = staticExec("cd \"" & absolutePath & "\" && git branch").strip
|
|
||||||
if "* data" notin branches.splitLines():
|
|
||||||
isCorrectClone = false
|
|
||||||
if isCorrectClone:
|
|
||||||
let updateOutput = staticExec("cd \"" & absolutePath & "\" && git pull")
|
|
||||||
#if uError != 0:
|
|
||||||
# echo "could not update yaml-test-suite! please fix this problem and compile again."
|
|
||||||
# echo "output:\n"
|
|
||||||
# echo "$ git pull"
|
|
||||||
# echo updateOutput
|
|
||||||
# quit 1
|
|
||||||
else:
|
|
||||||
echo testSuiteFolder, " exists, but is not in expected state. Make sure it is a git repo,"
|
|
||||||
echo "cloned from ", testSuiteUrl, ", and the data branch"
|
|
||||||
echo "is active. Alternatively, delete the folder " & testSuiteFolder & '.'
|
|
||||||
quit 1
|
|
||||||
else:
|
|
||||||
let cloneOutput = staticExec("cd \"" & pwd &
|
|
||||||
"\" && git clone " & testSuiteUrl & " -b data")
|
|
||||||
#if cError != 0:
|
|
||||||
if not(dirExists(absolutePath)) or not(dirExists(absolutePath / ".git")) or
|
|
||||||
not(dirExists(absolutePath / "229Q")):
|
|
||||||
echo "could not clone ", testSuiteUrl, ". Make sure"
|
|
||||||
echo "you are connected to the internet and your proxy settings are correct. output:\n"
|
|
||||||
echo "$ git clone ", testSuiteUrl, " -b data"
|
|
||||||
echo cloneOutput
|
|
||||||
quit 1
|
|
||||||
|
|
||||||
proc parserTest(path: string): bool =
|
proc parserTest(path: string, errorExpected : bool): bool =
|
||||||
var
|
var
|
||||||
tagLib = initExtendedTagLibrary()
|
tagLib = initExtendedTagLibrary()
|
||||||
parser = newYamlParser(tagLib)
|
parser = newYamlParser(tagLib)
|
||||||
|
@ -68,49 +31,65 @@ proc parserTest(path: string): bool =
|
||||||
while not actual.finished():
|
while not actual.finished():
|
||||||
let actualEvent = actual.next()
|
let actualEvent = actual.next()
|
||||||
if expected.finished():
|
if expected.finished():
|
||||||
echoError("At token #" & $i & ": Expected stream end, got " &
|
result = errorExpected
|
||||||
$actualEvent.kind)
|
if not result:
|
||||||
return false
|
echoError("At token #" & $i & ": Expected stream end, got " &
|
||||||
|
$actualEvent.kind)
|
||||||
|
return
|
||||||
let expectedEvent = expected.next()
|
let expectedEvent = expected.next()
|
||||||
if expectedEvent != actualEvent:
|
if expectedEvent != actualEvent:
|
||||||
printDifference(expectedEvent, actualEvent)
|
result = errorExpected
|
||||||
echoError("At token #" & $i &
|
if not result:
|
||||||
": Actual tokens do not match expected tokens")
|
printDifference(expectedEvent, actualEvent)
|
||||||
return false
|
echoError("At token #" & $i &
|
||||||
|
": Actual tokens do not match expected tokens")
|
||||||
|
return
|
||||||
i.inc()
|
i.inc()
|
||||||
if not expected.finished():
|
if not expected.finished():
|
||||||
echoError("Got fewer tokens than expected, first missing " &
|
result = errorExpected
|
||||||
"token: " & $expected.next().kind)
|
if not result:
|
||||||
return false
|
echoError("Got fewer tokens than expected, first missing " &
|
||||||
|
"token: " & $expected.next().kind)
|
||||||
|
return
|
||||||
|
result = not errorExpected
|
||||||
|
if not result:
|
||||||
|
echo "Expected error, but parsed without error."
|
||||||
except:
|
except:
|
||||||
let e = getCurrentException()
|
result = errorExpected
|
||||||
if e.parent of YamlParserError:
|
if not result:
|
||||||
let pe = (ref YamlParserError)(e.parent)
|
let e = getCurrentException()
|
||||||
echo "line ", pe.line, ", column ", pe.column, ": ", pe.msg
|
if e.parent of YamlParserError:
|
||||||
echo pe.lineContent
|
let pe = (ref YamlParserError)(e.parent)
|
||||||
else: echo e.msg
|
echo "line ", pe.line, ", column ", pe.column, ": ", pe.msg
|
||||||
echoError("Catched an exception at token #" & $i &
|
echo pe.lineContent
|
||||||
" test was not successful")
|
else: echo e.msg
|
||||||
return false
|
echoError("Catched an exception at token #" & $i &
|
||||||
result = true
|
" test was not successful")
|
||||||
|
|
||||||
macro genTests(): untyped =
|
macro genTests(): untyped =
|
||||||
let
|
let
|
||||||
pwd = staticExec("pwd").strip
|
pwd = staticExec("pwd").strip
|
||||||
absolutePath = '"' & (pwd / testSuiteFolder) & '"'
|
absolutePath = '"' & (pwd / testSuiteFolder) & '"'
|
||||||
echo "[tparser] Generating tests from " & absolutePath
|
echo "[tparser] Generating tests from " & absolutePath
|
||||||
ensureTestSuiteCloneCorrect(pwd)
|
discard staticExec("git submodule init && git submodule update --remote")
|
||||||
|
|
||||||
|
let errorTests = toSet(staticExec("cd " & (absolutePath / "tags" / "error") &
|
||||||
|
" && ls -1d *").splitLines())
|
||||||
|
let ignored = toSet(["3MYT", "JDH8", ".git", "name", "tags", "meta"])
|
||||||
|
|
||||||
result = newStmtList()
|
result = newStmtList()
|
||||||
# walkDir for some crude reason does not work with travis build
|
# walkDir for some crude reason does not work with travis build
|
||||||
let dirItems = staticExec("ls -1d " & absolutePath / "*")
|
let dirItems = staticExec("ls -1d " & absolutePath / "*")
|
||||||
for dirPath in dirItems.splitLines():
|
for dirPath in dirItems.splitLines():
|
||||||
if dirPath.strip.len == 0: continue
|
if dirPath.strip.len == 0: continue
|
||||||
if dirPath[^4..^1] in [".git", "name", "tags", "meta"]: continue
|
let testId = dirPath[^4..^1]
|
||||||
|
if ignored.contains(testId): continue
|
||||||
let title = slurp(dirPath / "===")
|
let title = slurp(dirPath / "===")
|
||||||
|
|
||||||
result.add(newCall("test",
|
result.add(newCall("test",
|
||||||
newLit(strip(title) & " [" &
|
newLit(strip(title) & " [" &
|
||||||
dirPath[^4..^1] & ']'), newCall("doAssert", newCall("parserTest",
|
testId & ']'), newCall("doAssert", newCall("parserTest",
|
||||||
newLit(dirPath)))))
|
newLit(dirPath), newLit(errorTests.contains(testId))))))
|
||||||
result = newCall("suite", newLit("Parser Tests (from yaml-test-suite)"), result)
|
result = newCall("suite", newLit("Parser Tests (from yaml-test-suite)"), result)
|
||||||
|
|
||||||
genTests()
|
genTests()
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit daa74b930d50a1863a8f90d7b8376904ad183771
|
Loading…
Reference in New Issue