2016-03-04 18:10:48 +00:00
|
|
|
# NimYAML - YAML implementation in Nim
|
|
|
|
# (c) Copyright 2016 Felix Krause
|
|
|
|
#
|
|
|
|
# See the file "copying.txt", included in this
|
|
|
|
# distribution, for details about the copyright.
|
|
|
|
|
2016-03-04 20:23:13 +00:00
|
|
|
import os, terminal, strutils
|
2016-03-09 19:15:43 +00:00
|
|
|
import testEventParser, common
|
2016-03-04 18:10:48 +00:00
|
|
|
import "../yaml"
|
|
|
|
|
|
|
|
const gitCmd =
|
|
|
|
"git clone https://github.com/ingydotnet/yaml-dev-kit.git -b data"
|
|
|
|
|
|
|
|
proc echoError(msg: string) =
|
|
|
|
styledWriteLine(stdout, fgRed, "[error] ", fgWhite, msg, resetStyle)
|
|
|
|
|
|
|
|
proc echoInfo(msg: string) =
|
|
|
|
styledWriteLine(stdout, fgGreen, "[info] ", fgWhite, msg, resetStyle)
|
|
|
|
|
|
|
|
removeDir("yaml-dev-kit")
|
|
|
|
if execShellCmd(gitCmd) != 0:
|
|
|
|
echoError("Could not check out yaml-dev-kit (no internet connection?)")
|
|
|
|
quit(1)
|
|
|
|
|
|
|
|
var gotErrors = false
|
|
|
|
|
2016-03-09 19:15:43 +00:00
|
|
|
for kind, dirPath in walkDir("yaml-dev-kit"):
|
|
|
|
block curTest:
|
|
|
|
if kind == pcDir:
|
|
|
|
if dirPath[^4..^1] in [".git", "name", "tags", "meta"]: continue
|
|
|
|
var
|
|
|
|
tagLib = initExtendedTagLibrary()
|
|
|
|
parser = newYamlParser(tagLib)
|
2016-03-18 21:29:35 +00:00
|
|
|
actualIn = newFileStream(dirPath / "in.yaml")
|
|
|
|
actual = parser.parse(actualIn)
|
|
|
|
expectedIn = newFileStream(dirPath / "test.event")
|
|
|
|
expected = parseEventStream(expectedIn, tagLib)
|
2016-03-09 19:15:43 +00:00
|
|
|
styledWriteLine(stdout, fgBlue, "[test] ", fgWhite, dirPath[^4..^1],
|
|
|
|
": ", strip(readFile(dirPath / "===")), resetStyle)
|
2016-03-19 21:43:03 +00:00
|
|
|
var i = 1
|
2016-03-09 19:15:43 +00:00
|
|
|
try:
|
2016-03-04 18:10:48 +00:00
|
|
|
while not actual.finished():
|
|
|
|
let actualEvent = actual.next()
|
|
|
|
if expected.finished():
|
2016-03-09 19:15:43 +00:00
|
|
|
echoError("At token #" & $i &
|
|
|
|
": Expected stream end, got " &
|
2016-03-04 18:10:48 +00:00
|
|
|
$actualEvent.kind)
|
|
|
|
gotErrors = true
|
2016-03-18 21:29:35 +00:00
|
|
|
actualIn.close()
|
|
|
|
expectedIn.close()
|
2016-03-04 18:10:48 +00:00
|
|
|
break curTest
|
|
|
|
let expectedEvent = expected.next()
|
|
|
|
if expectedEvent != actualEvent:
|
|
|
|
printDifference(expectedEvent, actualEvent)
|
2016-03-09 19:15:43 +00:00
|
|
|
echoError("At token #" & $i &
|
|
|
|
": Actual tokens do not match expected tokens")
|
2016-03-04 18:10:48 +00:00
|
|
|
gotErrors = true
|
2016-03-18 21:29:35 +00:00
|
|
|
actualIn.close()
|
|
|
|
expectedIn.close()
|
2016-03-04 18:10:48 +00:00
|
|
|
break curTest
|
2016-03-09 19:15:43 +00:00
|
|
|
i.inc()
|
2016-03-04 18:10:48 +00:00
|
|
|
if not expected.finished():
|
|
|
|
echoError(
|
2016-03-09 19:15:43 +00:00
|
|
|
"Got fewer tokens than expected, first missing " &
|
|
|
|
"token: " & $expected.next().kind)
|
2016-03-04 18:10:48 +00:00
|
|
|
gotErrors = true
|
2016-03-09 19:15:43 +00:00
|
|
|
except:
|
|
|
|
gotErrors = true
|
|
|
|
let e = getCurrentException()
|
|
|
|
if e.parent of YamlParserError:
|
|
|
|
let pe = (ref YamlParserError)(e.parent)
|
|
|
|
echo "line ", pe.line, ", column ", pe.column, ": ",
|
|
|
|
pe.msg
|
|
|
|
echo pe.lineContent
|
|
|
|
else: echo e.msg
|
2016-03-19 21:43:03 +00:00
|
|
|
echoError("Catched an exception at token #" & $i &
|
|
|
|
" test was not successful")
|
2016-03-18 21:29:35 +00:00
|
|
|
actualIn.close()
|
|
|
|
expectedIn.close()
|
2016-03-04 18:10:48 +00:00
|
|
|
|
|
|
|
if gotErrors:
|
|
|
|
echoError("There were errors while running the tests")
|
|
|
|
quit(1)
|
|
|
|
else:
|
|
|
|
echoInfo("All tests were successful")
|
|
|
|
quit(0)
|