nondescript/tests/test.nim

65 lines
1.5 KiB
Nim
Raw Normal View History

2022-01-29 22:33:34 +01:00
import hashtable
2022-02-05 02:45:29 +01:00
import ndlist
import os
import re
import strutils
import osproc
2022-02-06 10:04:49 +01:00
import terminal
2022-01-29 22:33:34 +01:00
2022-02-03 03:18:11 +01:00
testHashtables()
2022-02-05 02:45:29 +01:00
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
2022-02-06 10:04:49 +01:00
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)
2022-02-05 02:45:29 +01:00
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)
2022-02-03 03:18:11 +01:00