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 =
|
2016-04-02 15:48:22 +00:00
|
|
|
"git clone https://github.com/ingydotnet/yaml-dev-kit.git -b data"
|
2016-03-04 18:10:48 +00:00
|
|
|
|
|
|
|
proc echoError(msg: string) =
|
2016-04-02 15:48:22 +00:00
|
|
|
styledWriteLine(stdout, fgRed, "[error] ", fgWhite, msg, resetStyle)
|
2016-03-04 18:10:48 +00:00
|
|
|
|
|
|
|
proc echoInfo(msg: string) =
|
2016-04-02 15:48:22 +00:00
|
|
|
styledWriteLine(stdout, fgGreen, "[info] ", fgWhite, msg, resetStyle)
|
2016-03-04 18:10:48 +00:00
|
|
|
|
|
|
|
removeDir("yaml-dev-kit")
|
|
|
|
if execShellCmd(gitCmd) != 0:
|
2016-04-02 15:48:22 +00:00
|
|
|
echoError("Could not check out yaml-dev-kit (no internet connection?)")
|
|
|
|
quit(1)
|
2016-03-04 18:10:48 +00:00
|
|
|
|
|
|
|
var gotErrors = false
|
|
|
|
|
2016-03-09 19:15:43 +00:00
|
|
|
for kind, dirPath in walkDir("yaml-dev-kit"):
|
2016-04-02 15:48:22 +00:00
|
|
|
block curTest:
|
|
|
|
if kind == pcDir:
|
|
|
|
if dirPath[^4..^1] in [".git", "name", "tags", "meta"]: continue
|
|
|
|
var
|
|
|
|
tagLib = initExtendedTagLibrary()
|
|
|
|
parser = newYamlParser(tagLib)
|
|
|
|
actualIn = newFileStream(dirPath / "in.yaml")
|
|
|
|
actual = parser.parse(actualIn)
|
|
|
|
expectedIn = newFileStream(dirPath / "test.event")
|
|
|
|
expected = parseEventStream(expectedIn, tagLib)
|
|
|
|
styledWriteLine(stdout, fgBlue, "[test] ", fgWhite, dirPath[^4..^1],
|
|
|
|
": ", strip(readFile(dirPath / "===")), resetStyle)
|
|
|
|
var i = 1
|
|
|
|
try:
|
|
|
|
while not actual.finished():
|
|
|
|
let actualEvent = actual.next()
|
|
|
|
if expected.finished():
|
|
|
|
echoError("At token #" & $i & ": Expected stream end, got " &
|
|
|
|
$actualEvent.kind)
|
|
|
|
gotErrors = true
|
2016-03-18 21:29:35 +00:00
|
|
|
actualIn.close()
|
|
|
|
expectedIn.close()
|
2016-04-02 15:48:22 +00:00
|
|
|
break curTest
|
|
|
|
let expectedEvent = expected.next()
|
|
|
|
if expectedEvent != actualEvent:
|
|
|
|
printDifference(expectedEvent, actualEvent)
|
|
|
|
echoError("At token #" & $i &
|
|
|
|
": Actual tokens do not match expected tokens")
|
|
|
|
gotErrors = true
|
|
|
|
actualIn.close()
|
|
|
|
expectedIn.close()
|
|
|
|
break curTest
|
|
|
|
i.inc()
|
|
|
|
if not expected.finished():
|
|
|
|
echoError("Got fewer tokens than expected, first missing " &
|
|
|
|
"token: " & $expected.next().kind)
|
|
|
|
gotErrors = true
|
|
|
|
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
|
|
|
|
echoError("Catched an exception at token #" & $i &
|
|
|
|
" test was not successful")
|
|
|
|
actualIn.close()
|
|
|
|
expectedIn.close()
|
2016-03-04 18:10:48 +00:00
|
|
|
|
|
|
|
if gotErrors:
|
2016-04-02 15:48:22 +00:00
|
|
|
echoError("There were errors while running the tests")
|
|
|
|
quit(1)
|
2016-03-04 18:10:48 +00:00
|
|
|
else:
|
2016-04-02 15:48:22 +00:00
|
|
|
echoInfo("All tests were successful")
|
|
|
|
quit(0)
|