improved docs, removed unneccessary argument

This commit is contained in:
Productive2 2021-02-17 23:41:53 +01:00
parent 19ec90d775
commit 0b6244d794
3 changed files with 26 additions and 4 deletions

View File

@ -196,7 +196,7 @@ Flags:
setControlCHook(ctrlc) setControlCHook(ctrlc)
log(LogLevel.Info, &"Running tests...") log(LogLevel.Info, &"Running tests...")
# run tests (see testrun.nim) # run tests (see testrun.nim)
tests.runTests(jatr) tests.runTests()
log(LogLevel.Debug, &"Tests ran.") log(LogLevel.Debug, &"Tests ran.")
log(LogLevel.Debug, &"Evaluating tests...") log(LogLevel.Debug, &"Evaluating tests...")
# evaluate tests (see testeval.nim) # evaluate tests (see testeval.nim)

View File

@ -30,6 +30,7 @@ proc parseModalLine(line: string): tuple[modal: bool, mode: string, detail: stri
# when non modal, mode becomes the line # when non modal, mode becomes the line
# when comment is true, it must not do anything to whenever it is exported # when comment is true, it must not do anything to whenever it is exported
let line = line let line = line
# initialize result
result.modal = false result.modal = false
result.mode = "" result.mode = ""
result.detail = "" result.detail = ""
@ -37,25 +38,32 @@ proc parseModalLine(line: string): tuple[modal: bool, mode: string, detail: stri
if line.len() > 0 and line[0] == '[': if line.len() > 0 and line[0] == '[':
if line.len() > 1: if line.len() > 1:
if line[1] == '[': if line[1] == '[':
# escaped early return
result.mode = line[1..line.high()] result.mode = line[1..line.high()]
return result return result
elif line[1] == ';': elif line[1] == ';':
# comment early return
result.comment = true result.comment = true
result.modal = true result.modal = true
return result return result
result.modal = true result.modal = true
# not modal line early return
else: else:
result.mode = line result.mode = line
return result return result
var colon = false
# normal modal line:
var colon = false # if there has been a colon already
for i in countup(0, line.high()): for i in countup(0, line.high()):
let ch = line[i] let ch = line[i]
if ch in Letters or ch in Digits or ch in {'_', '-'}: if ch in Letters or ch in Digits or ch in {'_', '-'}:
# legal characters
if colon: if colon:
result.detail &= ($ch).toLower() result.detail &= ($ch).toLower()
else: else:
result.mode &= ($ch).toLower() result.mode &= ($ch).toLower()
elif ch == ':': elif ch == ':':
# colon
if not colon: if not colon:
colon = true colon = true
else: else:
@ -63,18 +71,22 @@ proc parseModalLine(line: string): tuple[modal: bool, mode: string, detail: stri
elif ch in Whitespace: elif ch in Whitespace:
discard discard
elif ch == ']': elif ch == ']':
# closing can only come at the end
if i != line.high(): if i != line.high():
fatal &"] is only allowed to close the line <{line}>." fatal &"] is only allowed to close the line <{line}>."
elif ch == '[': elif ch == '[':
# can only start with it
if i > 0: if i > 0:
fatal &"[ is only allowed to open the modal line <{line}>." fatal &"[ is only allowed to open the modal line <{line}>."
else: else:
fatal &"Illegal character in <{line}>: {ch}." fatal &"Illegal character in <{line}>: {ch}."
# must be closed by it
if line[line.high()] != ']': if line[line.high()] != ']':
fatal &"Line <{line}> must be closed off by ']'." fatal &"Line <{line}> must be closed off by ']'."
proc buildTest(lines: seq[string], i: var int, name: string, path: string): Test = proc buildTest(lines: seq[string], i: var int, name: string, path: string): Test =
## Builds a single test (starting with index i in lines, while i is modified)
result = newTest(name, path) result = newTest(name, path)
# since this is a very simple parser, some state can reduce code length # since this is a very simple parser, some state can reduce code length
inc i # to discard the first "test" mode inc i # to discard the first "test" mode
@ -143,6 +155,7 @@ proc buildTest(lines: seq[string], i: var int, name: string, path: string): Test
proc buildTestFile(path: string): seq[Test] = proc buildTestFile(path: string): seq[Test] =
## Builds a test file consisting of multiple tests
log(LogLevel.Debug, &"Checking {path} for tests") log(LogLevel.Debug, &"Checking {path} for tests")
let lines = path.readFile().split('\n') let lines = path.readFile().split('\n')
var i = 0 var i = 0
@ -161,6 +174,7 @@ proc buildTestFile(path: string): seq[Test] =
proc buildTests*(testDir: string): seq[Test] = proc buildTests*(testDir: string): seq[Test] =
## Builds all test within the directory testDir
for candidateObj in walkDir(testDir): for candidateObj in walkDir(testDir):
let candidate = candidateObj.path let candidate = candidateObj.path
if dirExists(candidate): if dirExists(candidate):

View File

@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# Test runner supervisor/manager ## Test runner supervisor/manager
import testobject import testobject
import logutils import logutils
@ -22,10 +22,13 @@ import strformat
import os import os
proc runTest(test: Test) = proc runTest(test: Test) =
## Starts running a test
log(LogLevel.Debug, &"Starting test {test.path}.") log(LogLevel.Debug, &"Starting test {test.path}.")
test.start() test.start()
proc tryFinishTest(test: Test): bool = proc tryFinishTest(test: Test): bool =
## Attempts to finish a test and returns true if it finished.
## False otherwise.
if test.running(): if test.running():
return false return false
test.finish() test.finish()
@ -33,16 +36,21 @@ proc tryFinishTest(test: Test): bool =
return true return true
proc killTest(test: Test) = proc killTest(test: Test) =
## Kills the test, logs kill reason as taking too long
if test.running(): if test.running():
test.kill() test.kill()
log(LogLevel.Error, &"Test {test.path} was killed for taking too long.") log(LogLevel.Error, &"Test {test.path} was killed for taking too long.")
proc killTests*(tests: seq[Test]) = proc killTests*(tests: seq[Test]) =
## kills all running tests in tests sequence
for test in tests: for test in tests:
if test.running(): if test.running():
test.kill() test.kill()
proc runTests*(tests: seq[Test], runner: string) = proc runTests*(tests: seq[Test]) =
## Runs all tests tests in tests, manages the maximum alive tests
## and launching of tests parallel. Also writes progress to the
## screen
var var
aliveTests = 0 aliveTests = 0
currentTest = 0 currentTest = 0