mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-03 03:32:32 +00:00
Adds $TESTNIM and $MODULE as variables to test cases.
This commit is contained in:
@@ -2,7 +2,7 @@ main.nim
|
||||
> c
|
||||
SuccessX
|
||||
# Ugh, undocumented trackDirty, how is it supposed to work? Fails in proc mode.
|
||||
> idetools --trackDirty:main_dirty.nim,main.nim,12,7 --suggest
|
||||
> idetools --trackDirty:main_dirty.nim,$TESTNIM,12,7 --suggest
|
||||
CaasRun skField\tx
|
||||
CaasRun skField\ty
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
main.nim
|
||||
> c
|
||||
SuccessX
|
||||
> idetools --track:main.nim,5,18 --def
|
||||
> idetools --track:$TESTNIM,5,18 --def
|
||||
strutils.toUpper
|
||||
! SuccessX
|
||||
> idetools --track:main.nim,5,18 --def
|
||||
> idetools --track:$TESTNIM,5,18 --def
|
||||
strutils.toUpper
|
||||
! SuccessX
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
main.nim
|
||||
> idetools --track:main.nim,5,18 --def
|
||||
> idetools --track:$TESTNIM,5,18 --def
|
||||
strutils.toUpper
|
||||
! SuccessX
|
||||
> idetools --track:main.nim,5,18 --def
|
||||
> idetools --track:$TESTNIM,5,18 --def
|
||||
strutils.toUpper
|
||||
! SuccessX
|
||||
> c
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
main.nim
|
||||
> idetools --track:main.nim,5,18 --def
|
||||
> idetools --track:$TESTNIM,5,18 --def
|
||||
strutils.toUpper
|
||||
! SuccessX
|
||||
> c
|
||||
|
||||
@@ -1,44 +1,44 @@
|
||||
idetools_api.nim
|
||||
> c
|
||||
SuccessX
|
||||
> idetools --track:idetools_api.nim,4,11 --def
|
||||
> idetools --track:$TESTNIM,4,11 --def
|
||||
def\tskType\tsystem.TFile\tTFile
|
||||
> idetools --track:idetools_api.nim,5,7 --def
|
||||
> idetools --track:$TESTNIM,5,7 --def
|
||||
def\tskProc\tsystem.Open\tproc \(var TFile, string, TFileMode, int\): bool
|
||||
> idetools --track:idetools_api.nim,5,21 --def
|
||||
> idetools --track:$TESTNIM,5,21 --def
|
||||
def\tskProc\tsystem.\&\tproc \(string, string\): string\{.noSideEffect.\}
|
||||
> idetools --track:idetools_api.nim,5,38 --def
|
||||
> idetools --track:$TESTNIM,5,38 --def
|
||||
def\tskEnumField\tsystem.TFileMode.fmWrite\tTFileMode
|
||||
> idetools --track:idetools_api.nim,7,6 --def
|
||||
> idetools --track:$TESTNIM,7,6 --def
|
||||
def\tskProc\tsystem.Close\tproc \(TFile\)
|
||||
> idetools --track:idetools_api.nim,12,23 --def
|
||||
> idetools --track:$TESTNIM,12,23 --def
|
||||
def\tskIterator\tunicode.runes\titerator \(string\): TRune
|
||||
> idetools --track:idetools_api.nim,12,15 --def
|
||||
> idetools --track:$TESTNIM,12,15 --def
|
||||
def\tskTemplate\tsequtils.toSeq\tproc \(expr\): expr
|
||||
> idetools --track:idetools_api.nim,15,7 --def
|
||||
> idetools --track:$TESTNIM,15,7 --def
|
||||
|
||||
# ProcRun mode will fail the next line, because the type is returned empty.
|
||||
def\tskConst\tidetools_api.SOME_SEQUENCE\tseq\[int\]\t
|
||||
> idetools --track:idetools_api.nim,15,23 --def
|
||||
def\tskConst\t$MODULE.SOME_SEQUENCE\tseq\[int\]\t
|
||||
> idetools --track:$TESTNIM,15,23 --def
|
||||
def\tskProc\tsystem.@\tproc \(array\[IDX, T\]\): seq\[T\]\{.noSideEffect.\}
|
||||
> idetools --track:idetools_api.nim,17,3 --def
|
||||
> idetools --track:$TESTNIM,17,3 --def
|
||||
|
||||
# ProcRun mode will fail the next line, because the type is returned empty.
|
||||
def\tskType\tidetools_api.bad_string\tbad_string\t
|
||||
> idetools --track:idetools_api.nim,11,24 --def
|
||||
def\tskParam\tidetools_api.test_iterators.filename\tstring
|
||||
> idetools --track:idetools_api.nim,6,5 --def
|
||||
def\tskVar\tidetools_api.test_enums.o\tTFile
|
||||
> idetools --track:idetools_api.nim,12,34 --def
|
||||
def\tskLet\tidetools_api.test_iterators.input\tTaintedString
|
||||
> idetools --track:idetools_api.nim,13,35 --def
|
||||
def\tskForVar\tidetools_api.test_iterators.letter\tTRune
|
||||
> idetools --track:idetools_api.nim,23,3 --def
|
||||
def\tskResult\tidetools_api.adder.result\tint
|
||||
> idetools --track:idetools_api.nim,19,6 --def
|
||||
def\tskType\t$MODULE.bad_string\tbad_string\t
|
||||
> idetools --track:$TESTNIM,11,24 --def
|
||||
def\tskParam\t$MODULE.test_iterators.filename\tstring
|
||||
> idetools --track:$TESTNIM,6,5 --def
|
||||
def\tskVar\t$MODULE.test_enums.o\tTFile
|
||||
> idetools --track:$TESTNIM,12,34 --def
|
||||
def\tskLet\t$MODULE.test_iterators.input\tTaintedString
|
||||
> idetools --track:$TESTNIM,13,35 --def
|
||||
def\tskForVar\t$MODULE.test_iterators.letter\tTRune
|
||||
> idetools --track:$TESTNIM,23,3 --def
|
||||
def\tskResult\t$MODULE.adder.result\tint
|
||||
> idetools --track:$TESTNIM,19,6 --def
|
||||
|
||||
# ProcRun mode will fail the next line, because the type is returned empty.
|
||||
def\tskField\tidetools_api.TPerson.name\tbad_string\t
|
||||
def\tskField\t$MODULE.TPerson.name\tbad_string\t
|
||||
|
||||
> idetools --track:idetools_api.nim,43,7 --def
|
||||
def\tskMethod\tidetools_api.eval\tproc \(PPlusExpr\): int\t
|
||||
> idetools --track:$TESTNIM,43,7 --def
|
||||
def\tskMethod\t$MODULE.eval\tproc \(PPlusExpr\): int\t
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
issue_416_template_shift.nim
|
||||
> c
|
||||
SuccessX
|
||||
> idetools --track:issue_416_template_shift.nim,12,28 --def
|
||||
> idetools --track:$TESTNIM,12,28 --def
|
||||
def\tskType\tsystem.string\tstring
|
||||
> idetools --track:issue_416_template_shift.nim,12,35 --def
|
||||
def\tskLet\tissue_416_template_shift.failtest.input\tTaintedString
|
||||
> idetools --track:$TESTNIM,12,35 --def
|
||||
def\tskLet\t$MODULE.failtest.input\tTaintedString
|
||||
|
||||
# The following fail because they seem shifted one colum to the right.
|
||||
> idetools --track:issue_416_template_shift.nim,12,16 --def
|
||||
> idetools --track:$TESTNIM,12,16 --def
|
||||
def\tskTemplate\tsequtils.toSeq\tproc \(expr\): expr
|
||||
> idetools --track:issue_416_template_shift.nim,12,22 --def
|
||||
> idetools --track:$TESTNIM,12,22 --def
|
||||
def\tskIterator\tunicode.runes\titerator \(string\): TRune
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
issue_452_export_shift.nim
|
||||
> c
|
||||
SuccessX
|
||||
> idetools --track:issue_452_export_shift.nim,2,2 --def
|
||||
def\tskConst\tissue_452_export_shift.VERSION_STR1\tstring
|
||||
> idetools --track:issue_452_export_shift.nim,3,2 --def
|
||||
def\tskConst\tissue_452_export_shift.VERSION_STR2\tstring
|
||||
> idetools --track:issue_452_export_shift.nim,7,5 --def
|
||||
def\tskProc\tissue_452_export_shift.forward1\tproc \(\): string\t
|
||||
> idetools --track:issue_452_export_shift.nim,8,5 --def
|
||||
def\tskProc\tissue_452_export_shift.forward2\tproc \(\): string\t
|
||||
> idetools --track:$TESTNIM,2,2 --def
|
||||
def\tskConst\t$MODULE.VERSION_STR1\tstring
|
||||
> idetools --track:$TESTNIM,3,2 --def
|
||||
def\tskConst\t$MODULE.VERSION_STR2\tstring
|
||||
> idetools --track:$TESTNIM,7,5 --def
|
||||
def\tskProc\t$MODULE.forward1\tproc \(\): string\t
|
||||
> idetools --track:$TESTNIM,8,5 --def
|
||||
def\tskProc\t$MODULE.forward2\tproc \(\): string\t
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
main.nim
|
||||
# Ugh, undocumented trackDirty, how is it supposed to work? Fails in proc mode.
|
||||
> idetools --trackDirty:main_dirty.nim,main.nim,12,7 --suggest
|
||||
> idetools --trackDirty:main_dirty.nim,$TESTNIM,12,7 --suggest
|
||||
skField\tx
|
||||
skField\ty
|
||||
> c
|
||||
|
||||
@@ -22,7 +22,12 @@ import osproc, streams, os, strutils, re
|
||||
## only in that mode.
|
||||
##
|
||||
## The rest of the line is treated as a regular expression, so be careful
|
||||
## escaping metacharacters like parenthesis.
|
||||
## escaping metacharacters like parenthesis. Before the line is processed as a
|
||||
## regular expression, some basic variables are searched for and replaced in
|
||||
## the tests. The variables which will be replaced are:
|
||||
##
|
||||
## - $TESTNIM: filename specified in the first line of the script.
|
||||
## - $MODULE: like $TESTNIM but without extension, useful for expected output.
|
||||
##
|
||||
## You can optionally pass parameters at the command line to modify the
|
||||
## behaviour of the test suite. By default only tests which fail will be echoed
|
||||
@@ -46,26 +51,35 @@ type
|
||||
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 '>'.
|
||||
filename: string # Appended to each command starting with '>'. Also a var.
|
||||
modname: string # Like filename but without extension.
|
||||
|
||||
const modes = [CaasRun, ProcRun]
|
||||
const
|
||||
modes = [CaasRun, ProcRun]
|
||||
filenameReplaceVar = "$TESTNIM"
|
||||
moduleReplaceVar = "$MODULE"
|
||||
|
||||
var
|
||||
TesterDir = getAppDir()
|
||||
NimrodBin = TesterDir / "../bin/nimrod"
|
||||
|
||||
proc replaceVars(session: var TNimrodSession, text: string): string =
|
||||
result = text.replace(filenameReplaceVar, session.filename)
|
||||
result = result.replace(moduleReplaceVar, session.modname)
|
||||
|
||||
proc startNimrodSession(project: string, mode: TRunMode): TNimrodSession =
|
||||
let (dir, name) = project.SplitPath
|
||||
let (dir, name, ext) = project.splitFile
|
||||
result.mode = mode
|
||||
result.lastOutput = ""
|
||||
result.filename = name
|
||||
result.filename = name & ext
|
||||
result.modname = name
|
||||
if mode == CaasRun:
|
||||
result.nim = startProcess(NimrodBin, workingDir = dir,
|
||||
args = ["serve", "--server.type:stdin", name])
|
||||
|
||||
proc doCaasCommand(session: var TNimrodSession, command: string): string =
|
||||
assert session.mode == CaasRun
|
||||
session.nim.inputStream.write(command & "\n")
|
||||
session.nim.inputStream.write(session.replaceVars(command) & "\n")
|
||||
session.nim.inputStream.flush
|
||||
|
||||
result = ""
|
||||
@@ -83,7 +97,7 @@ proc doProcCommand(session: var TNimrodSession, command: string): string =
|
||||
assert session.mode == ProcRun
|
||||
except: result = "FAILED TO EXECUTE: " & command & "\n" & result
|
||||
var
|
||||
process = startProcess(NimrodBin, args = command.split)
|
||||
process = startProcess(NimrodBin, args = session.replaceVars(command).split)
|
||||
stream = outputStream(process)
|
||||
line = TaintedString("")
|
||||
|
||||
@@ -141,9 +155,9 @@ proc doScenario(script: string, output: PStream, mode: TRunMode): bool =
|
||||
output.writeln line, "\n", s.lastOutput
|
||||
else:
|
||||
var expectMatch = true
|
||||
var pattern = line
|
||||
var pattern = s.replaceVars(line)
|
||||
if line.startsWith("!"):
|
||||
pattern = line.substr(1).strip
|
||||
pattern = pattern.substr(1).strip
|
||||
expectMatch = false
|
||||
|
||||
let actualMatch =
|
||||
|
||||
Reference in New Issue
Block a user