nondescript/tests/test.nim

65 lines
1.5 KiB
Nim

import hashtable
import ndlist
import os
import re
import strutils
import osproc
import terminal
testHashtables()
testNdlist()
var ndsPath = "bin/nds"
var testsPath = "tests"
proc assembleTestOutput(path: string): string =
for line in path.lines:
if line.contains(re"//expect:"):
result &= line[line.find(re"//expect:") + "//expect:".len()..^1] & "\n"
proc runTest(path: string) =
let (output, exitcode) = execCmdEx(ndsPath & " " & path)
let expoutput = assembleTestOutput(path)
let success = output == expoutput
if not success:
echo "Nds test failed: " & path
let oupLines = output.split('\n')
let expLines = expoutput.split('\n')
for i in 0 .. oupLines.high():
let oupLine = oupLines[i]
var expLine = ""
if expLines.len() > i:
expLine = expLines[i]
if oupLine == expLine:
setForegroundColor(fgGreen)
echo oupLine
else:
setForegroundColor(fgRed)
write stdout, oupLine
setForegroundColor(fgDefault)
write stdout, " (expected: " & expLine & ")\n"
setForegroundColor(fgDefault)
else:
echo "Test success: " & path
if not dirExists(testsPath):
testsPath = "."
if not fileExists(ndsPath):
if fileExists(".." / ndsPath):
ndsPath = ".." / ndsPath
else:
echo "Couldn't find nds binary in bin/nds or ../bin/nds, run nimble build first."
quit 1
for test in walkDir(testsPath):
if test.path.splitFile.ext == ".nds":
runTest(test.path)