Runs all caas tests also in process mode.
This requires changing a little bit the test cases to avoid specifying the filename as the last parameter. The trackDirty switch still doesn't work for process mode. Also revers some SuccessX which I think were hidden in the amount of output verbosity.
This commit is contained in:
parent
9b0e03cb2e
commit
8f76092b89
6 changed files with 67 additions and 32 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
main.nim
|
main.nim
|
||||||
> c
|
> c
|
||||||
SuccessX
|
SuccessX
|
||||||
> idetools --trackDirty:main_dirty.nim,main.nim,12,7 --suggest main.nim
|
> idetools --trackDirty:main_dirty.nim,main.nim,12,7 --suggest
|
||||||
skField\tx
|
skField\tx
|
||||||
skField\ty
|
skField\ty
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
main.nim
|
main.nim
|
||||||
> c
|
> c
|
||||||
SuccessX
|
SuccessX
|
||||||
> idetools --track:main.nim,5,18 --def main.nim
|
> idetools --track:main.nim,5,18 --def
|
||||||
strutils.toUpper
|
strutils.toUpper
|
||||||
SuccessX
|
! SuccessX
|
||||||
> idetools --track:main.nim,5,18 --def main.nim
|
> idetools --track:main.nim,5,18 --def
|
||||||
strutils.toUpper
|
strutils.toUpper
|
||||||
SuccessX
|
! SuccessX
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
main.nim
|
main.nim
|
||||||
> idetools --track:main.nim,5,18 --def main.nim
|
> idetools --track:main.nim,5,18 --def
|
||||||
strutils.toUpper
|
strutils.toUpper
|
||||||
SuccessX
|
! SuccessX
|
||||||
> idetools --track:main.nim,5,18 --def main.nim
|
> idetools --track:main.nim,5,18 --def
|
||||||
strutils.toUpper
|
strutils.toUpper
|
||||||
SuccessX
|
! SuccessX
|
||||||
> c
|
> c
|
||||||
SuccessX
|
SuccessX
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
main.nim
|
main.nim
|
||||||
> idetools --track:main.nim,5,18 --def main.nim
|
> idetools --track:main.nim,5,18 --def
|
||||||
strutils.toUpper
|
strutils.toUpper
|
||||||
SuccessX
|
! SuccessX
|
||||||
> c
|
> c
|
||||||
SuccessX
|
SuccessX
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
main.nim
|
main.nim
|
||||||
> idetools --trackDirty:main_dirty.nim,main.nim,12,7 --suggest main.nim
|
> idetools --trackDirty:main_dirty.nim,main.nim,12,7 --suggest
|
||||||
skField\tx
|
skField\tx
|
||||||
skField\ty
|
skField\ty
|
||||||
> c
|
> c
|
||||||
|
|
|
||||||
|
|
@ -23,19 +23,30 @@ import osproc, streams, os, strutils, re
|
||||||
|
|
||||||
|
|
||||||
type
|
type
|
||||||
|
TRunMode = enum
|
||||||
|
ProcRun, CaasRun
|
||||||
|
|
||||||
TNimrodSession* = object
|
TNimrodSession* = object
|
||||||
nim: PProcess
|
nim: PProcess # Holds the open process for CaasRun sessions, nil otherwise.
|
||||||
|
mode: TRunMode # Stores the type of run mode the session was started with.
|
||||||
|
lastOutput: string # Preserves the last output, needed for ProcRun mode.
|
||||||
|
filename: string # Appended to each command starting with '>'.
|
||||||
|
|
||||||
var
|
var
|
||||||
TesterDir = getAppDir()
|
TesterDir = getAppDir()
|
||||||
NimrodBin = TesterDir / "../bin/nimrod"
|
NimrodBin = TesterDir / "../bin/nimrod"
|
||||||
|
|
||||||
proc startNimrodSession*(project: string): TNimrodSession =
|
proc startNimrodSession(project: string, mode: TRunMode): TNimrodSession =
|
||||||
result.nim = startProcess(NimrodBin,
|
let (dir, name) = project.SplitPath
|
||||||
workingDir = project.parentDir,
|
result.mode = mode
|
||||||
args = ["serve", "--server.type:stdin", project])
|
result.lastOutput = ""
|
||||||
|
result.filename = name
|
||||||
|
if mode == CaasRun:
|
||||||
|
result.nim = startProcess(NimrodBin, workingDir = dir,
|
||||||
|
args = ["serve", "--server.type:stdin", name])
|
||||||
|
|
||||||
proc doCommand*(session: var TNimrodSession, command: string): string =
|
proc doCaasCommand(session: var TNimrodSession, command: string): string =
|
||||||
|
assert session.mode == CaasRun
|
||||||
session.nim.inputStream.write(command & "\n")
|
session.nim.inputStream.write(command & "\n")
|
||||||
session.nim.inputStream.flush
|
session.nim.inputStream.flush
|
||||||
|
|
||||||
|
|
@ -50,10 +61,34 @@ proc doCommand*(session: var TNimrodSession, command: string): string =
|
||||||
result = "FAILED TO EXECUTE: " & command & "\n" & result
|
result = "FAILED TO EXECUTE: " & command & "\n" & result
|
||||||
break
|
break
|
||||||
|
|
||||||
proc close(session: var TNimrodSession) {.destructor.} =
|
proc doProcCommand(session: var TNimrodSession, command: string): string =
|
||||||
session.nim.close
|
assert session.mode == ProcRun
|
||||||
|
except: result = "FAILED TO EXECUTE: " & command & "\n" & result
|
||||||
|
var
|
||||||
|
process = startProcess(NimrodBin, args = command.split)
|
||||||
|
stream = outputStream(process)
|
||||||
|
line = TaintedString("")
|
||||||
|
|
||||||
proc doScenario(script: string, output: PStream): bool =
|
result = ""
|
||||||
|
while stream.readLine(line):
|
||||||
|
if result.len > 0: result &= "\n"
|
||||||
|
result &= line.string
|
||||||
|
|
||||||
|
process.close()
|
||||||
|
|
||||||
|
proc doCommand(session: var TNimrodSession, command: string) =
|
||||||
|
if session.mode == CaasRun:
|
||||||
|
session.lastOutput = doCaasCommand(session,
|
||||||
|
command & " " & session.filename)
|
||||||
|
else:
|
||||||
|
session.lastOutput = doProcCommand(session,
|
||||||
|
command & " " & session.filename)
|
||||||
|
|
||||||
|
proc close(session: var TNimrodSession) {.destructor.} =
|
||||||
|
if session.mode == CaasRun:
|
||||||
|
session.nim.close
|
||||||
|
|
||||||
|
proc doScenario(script: string, output: PStream, mode: TRunMode): bool =
|
||||||
result = true
|
result = true
|
||||||
|
|
||||||
var f = open(script)
|
var f = open(script)
|
||||||
|
|
@ -61,9 +96,8 @@ proc doScenario(script: string, output: PStream): bool =
|
||||||
|
|
||||||
if f.readLine(project):
|
if f.readLine(project):
|
||||||
var
|
var
|
||||||
s = startNimrodSession(script.parentDir / project.string)
|
s = startNimrodSession(script.parentDir / project.string, mode)
|
||||||
tline = TaintedString("")
|
tline = TaintedString("")
|
||||||
lastOutput = ""
|
|
||||||
ln = 1
|
ln = 1
|
||||||
|
|
||||||
while f.readLine(tline):
|
while f.readLine(tline):
|
||||||
|
|
@ -72,8 +106,8 @@ proc doScenario(script: string, output: PStream): bool =
|
||||||
if line.strip.len == 0: continue
|
if line.strip.len == 0: continue
|
||||||
|
|
||||||
if line.startsWith(">"):
|
if line.startsWith(">"):
|
||||||
lastOutput = s.doCommand(line.substr(1).strip)
|
s.doCommand(line.substr(1).strip)
|
||||||
output.writeln line, "\n", lastOutput
|
output.writeln line, "\n", s.lastOutput
|
||||||
else:
|
else:
|
||||||
var expectMatch = true
|
var expectMatch = true
|
||||||
var pattern = line
|
var pattern = line
|
||||||
|
|
@ -81,7 +115,7 @@ proc doScenario(script: string, output: PStream): bool =
|
||||||
pattern = line.substr(1).strip
|
pattern = line.substr(1).strip
|
||||||
expectMatch = false
|
expectMatch = false
|
||||||
|
|
||||||
var actualMatch = lastOutput.find(re(pattern)) != -1
|
var actualMatch = s.lastOutput.find(re(pattern)) != -1
|
||||||
|
|
||||||
if expectMatch == actualMatch:
|
if expectMatch == actualMatch:
|
||||||
output.writeln "SUCCESS ", line
|
output.writeln "SUCCESS ", line
|
||||||
|
|
@ -90,12 +124,13 @@ proc doScenario(script: string, output: PStream): bool =
|
||||||
result = false
|
result = false
|
||||||
|
|
||||||
iterator caasTestsRunner*(filter = ""): tuple[test, output: string,
|
iterator caasTestsRunner*(filter = ""): tuple[test, output: string,
|
||||||
status: bool] =
|
status: bool, mode: TRunMode] =
|
||||||
for scenario in os.walkFiles(TesterDir / "caas/*.txt"):
|
for scenario in os.walkFiles(TesterDir / "caas/*.txt"):
|
||||||
if filter.len > 0 and find(scenario, filter) == -1: continue
|
if filter.len > 0 and find(scenario, filter) == -1: continue
|
||||||
var outStream = newStringStream()
|
for mode in [CaasRun, ProcRun]:
|
||||||
let r = doScenario(scenario, outStream)
|
var outStream = newStringStream()
|
||||||
yield (scenario, outStream.data, r)
|
let r = doScenario(scenario, outStream, mode)
|
||||||
|
yield (scenario, outStream.data, r, mode)
|
||||||
|
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
var
|
var
|
||||||
|
|
@ -112,9 +147,9 @@ when isMainModule:
|
||||||
if verbose and len(filter) > 0:
|
if verbose and len(filter) > 0:
|
||||||
echo "Running only test cases matching filter '$1'" % [filter]
|
echo "Running only test cases matching filter '$1'" % [filter]
|
||||||
|
|
||||||
for test, output, result in caasTestsRunner(filter):
|
for test, output, result, mode in caasTestsRunner(filter):
|
||||||
if not result or verbose:
|
if not result or verbose:
|
||||||
echo test, "\n", output, "-> ", $result, "\n-----"
|
echo test, "\n", output, "-> ", $mode, ":", $result, "\n-----"
|
||||||
if not result:
|
if not result:
|
||||||
failures += 1
|
failures += 1
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue