nondescript/tests/test.nim

50 lines
1.0 KiB
Nim

import hashtable
import ndlist
import os
import re
import strutils
import osproc
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
echo "expected output:"
echo expoutput
echo "got output:"
echo output
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)