mirror of https://github.com/japl-lang/japl.git
Preparing for merge
This commit is contained in:
parent
76b92e85a7
commit
614b62441e
|
@ -0,0 +1,5 @@
|
|||
# Constants for communication between the test runner and the test suite
|
||||
const nextTestPre = "\rNEXTTEST{"
|
||||
const nextTestPost = "}"
|
||||
const nextTestRe = "^\rNEXTTEST{.*}$"
|
||||
const nextTestNameRe = "{(.*)}$"
|
|
@ -17,14 +17,25 @@
|
|||
# a testrunner process
|
||||
|
||||
import ../src/vm
|
||||
import directives
|
||||
import os, strformat
|
||||
|
||||
var btvm = initVM()
|
||||
try:
|
||||
discard btvm.interpret(readFile(paramStr(1)), "")
|
||||
quit(0)
|
||||
except:
|
||||
let error = getCurrentException()
|
||||
writeLine stderr, error.msg
|
||||
quit(1)
|
||||
|
||||
if paramCount() > 0 and paramStr(1) == "stdin":
|
||||
block main:
|
||||
while true:
|
||||
block test:
|
||||
var test = ""
|
||||
while true:
|
||||
let nl = stdin.readLine()
|
||||
if
|
||||
|
||||
elif paramCount() > 0:
|
||||
try:
|
||||
discard btvm.interpret(readFile(paramStr(1)), "")
|
||||
quit(0)
|
||||
except:
|
||||
let error = getCurrentException()
|
||||
writeLine stderr, error.msg
|
||||
quit(1)
|
||||
|
||||
|
|
|
@ -18,9 +18,11 @@ import nim/nimtests
|
|||
|
||||
import testobject, testutils, logutils
|
||||
|
||||
import os, strformat, parseopt, strutils
|
||||
import os, strformat, parseopt, strutils, terminal
|
||||
|
||||
when isMainModule:
|
||||
|
||||
|
||||
const jatsVersion = "(dev)"
|
||||
|
||||
var optparser = initOptParser(commandLineParams())
|
||||
|
@ -34,9 +36,10 @@ when isMainModule:
|
|||
var verbose = true
|
||||
|
||||
type QuitValue {.pure.} = enum
|
||||
Success, Failure, ArgParseErr, InternalErr
|
||||
Success, Failure, ArgParseErr, InternalErr, Interrupt
|
||||
var quitVal = QuitValue.Success
|
||||
|
||||
|
||||
proc evalKey(key: string) =
|
||||
let key = key.toLower()
|
||||
if key == "h" or key == "help":
|
||||
|
@ -130,6 +133,12 @@ Flags:
|
|||
log(LogLevel.Info, &"Building tests...")
|
||||
let tests: seq[Test] = buildTests(testDir)
|
||||
log(LogLevel.Debug, &"Tests built.")
|
||||
proc ctrlc() {.noconv.} =
|
||||
showCursor()
|
||||
tests.killTests()
|
||||
echo "Interrupted by ^C."
|
||||
quit(int(QuitValue.Interrupt))
|
||||
setControlCHook(ctrlc)
|
||||
log(LogLevel.Info, &"Running tests...")
|
||||
tests.runTests(jatr)
|
||||
log(LogLevel.Debug, &"Tests ran.")
|
||||
|
|
|
@ -54,5 +54,5 @@ proc compileInput*(source: string): string =
|
|||
# stuff for cleaning test output
|
||||
|
||||
proc tuStrip*(input: string): string =
|
||||
return input.replace(re"[\n\r]*$", "")
|
||||
return input.replace(re"\[DEBUG.*\n","\n").replace(re"[\n\r]*", "\n").replace(re"\n$","")
|
||||
|
||||
|
|
|
@ -50,17 +50,21 @@ proc runTest(test: Test, runner: string) =
|
|||
let suc = f.open(process.inputHandle, fmWrite)
|
||||
if suc:
|
||||
f.write(test.input)
|
||||
f.close()
|
||||
else:
|
||||
log(LogLevel.Error, &"Stdin File handle could not be opened for test {test.path}")
|
||||
test.result = Crash
|
||||
|
||||
test.result = TestResult.Running
|
||||
|
||||
proc readOutputs(test: Test) =
|
||||
test.output = test.process.outputStream.readAll()
|
||||
test.error = test.process.errorStream.readAll()
|
||||
|
||||
proc tryFinishTest(test: Test): bool =
|
||||
if test.process.running():
|
||||
return false
|
||||
test.output = test.process.outputStream.readAll()
|
||||
test.error = test.process.errorStream.readAll()
|
||||
test.readOutputs()
|
||||
if test.process.peekExitCode() == 0:
|
||||
test.result = TestResult.ToEval
|
||||
else:
|
||||
|
@ -71,10 +75,17 @@ proc tryFinishTest(test: Test): bool =
|
|||
|
||||
proc killTest(test: Test) =
|
||||
if test.process.running():
|
||||
test.readOutputs()
|
||||
test.process.kill()
|
||||
discard test.process.waitForExit()
|
||||
test.result = TestResult.Crash
|
||||
log(LogLevel.Error, &"Test {test.path} was killed for taking too long.")
|
||||
discard test.tryFinishTest()
|
||||
|
||||
proc killTests*(tests: seq[Test]) =
|
||||
for test in tests:
|
||||
if test.result == TestResult.Running:
|
||||
killTest(test)
|
||||
|
||||
|
||||
const maxAliveTests = 16
|
||||
const testWait = 100
|
||||
|
@ -149,7 +160,7 @@ proc printResults*(tests: seq[Test]): bool =
|
|||
log(LogLevel.Debug, &"[{test.path}\noutput:\n{test.output}\nerror:\n{test.error}\nexpected output:\n{test.expectedOutput}\nexpectedError:\n{test.expectedError}\n]")
|
||||
of TestResult.Crash:
|
||||
inc crash
|
||||
log(LogLevel.Debug, &"{test.path} \ncrash:\n{test.error}")
|
||||
log(LogLevel.Debug, &"{test.path} \ncrash:\n{test.output}")
|
||||
of TestResult.Success:
|
||||
inc success
|
||||
else:
|
||||
|
|
Loading…
Reference in New Issue