Minor improvements to build script and fixed a bug in the test suite where it would mark a test as completed before checking its output

This commit is contained in:
nocturn9x 2021-01-10 08:24:34 +01:00
parent 87fa674b15
commit 5f55ea53ac
2 changed files with 11 additions and 15 deletions

View File

@ -150,16 +150,13 @@ def build(path: str, flags: Dict[str, str] = {}, options: Dict[str, bool] = {},
start = time()
try:
# TODO: Find a better way of running the test suite
process = run(f"{tests_path}", stdout=PIPE, stderr=PIPE, shell=True)
process = run(f"{tests_path}", shell=True, stderr=PIPE)
stderr = process.stderr.decode()
assert process.returncode == 0, f"Command '{command}' exited with non-0 exit code {process.returncode}, output below:\n{stderr}"
except Exception as fatal:
logging.error(f"A fatal unhandled exception occurred -> {type(fatal).__name__}: {fatal}")
else:
logging.debug(f"Test suite ran in {time() - start:.2f} seconds")
# This way it *looks* like we're running it now when it
# actually already happened
print(process.stdout.decode().rstrip("\n"))
logging.info("Test suite completed!")

View File

@ -19,7 +19,7 @@
# - Assumes "japl" binary in ../src/japl built with all debugging off
# - Goes through all tests in (/tests/)
# - Runs all tests in (/tests/)japl/ and checks their output (marked by `//output:{output}`)
#
# Imports nim tests as well
import multibyte, os, strformat, times, re
@ -73,13 +73,12 @@ proc main(testsDir: string, japlExec: string, testResultsFile: File): tuple[numO
try:
for file in walkDir(testsDir):
block singleTest:
for exc in exceptions:
if exc == file.path.extractFilename:
detail(testResultsFile, &"Skipping '{file.path}'")
numOfTests += 1
skippedTests += 1
break singleTest
if file.path.dirExists():
if file.path.extractFilename in exceptions:
detail(testResultsFile, &"Skipping '{file.path}'")
numOfTests += 1
skippedTests += 1
break singleTest
elif file.path.dirExists():
detail(testResultsFile, "Descending into '" & file.path & "'")
var subTestResult = main(file.path, japlExec, testResultsFile)
numOfTests += subTestResult.numOfTests
@ -96,7 +95,6 @@ proc main(testsDir: string, japlExec: string, testResultsFile: File): tuple[numO
failedTests += 1
log(testResultsFile, &"Test '{file.path}' has crashed!")
else:
successTests += 1
let expectedOutput = compileExpectedOutput(file.path).replace(re"(\n*)$", "")
let realOutputFile = open("testoutput.txt", fmRead)
let realOutput = realOutputFile.readAll().replace(re"([\n\r]*)$", "")
@ -104,13 +102,14 @@ proc main(testsDir: string, japlExec: string, testResultsFile: File): tuple[numO
removeFile("testoutput.txt")
let comparison = deepComp(expectedOutput, realOutput)
if comparison.same:
successTests += 1
log(testResultsFile, &"Test '{file.path}' was successful")
else:
failedTests += 1
detail(testResultsFile, &"Expected output:\n{expectedOutput}\n")
detail(testResultsFile, &"Received output:\n{realOutput}\n")
detail(testResultsFile, &"Mismatch at pos {comparison.place}")
if comparison.place > expectedOutput.high() or
comparison.place > realOutput.high():
if comparison.place > expectedOutput.high() or comparison.place > realOutput.high():
detail(testResultsFile, &"Length mismatch")
else:
detail(testResultsFile, &"Expected is '{expectedOutput[comparison.place]}' while received '{realOutput[comparison.place]}'")