Testament small fixes (#16788)
* ReSync with Devel * ReSync * Fix Deprecations, Convertion to itself, code style, etc * Fix Deprecations, Convertion to itself, code style, etc
This commit is contained in:
parent
3df652b90b
commit
f1d165adf2
6 changed files with 91 additions and 191 deletions
|
|
@ -10,9 +10,9 @@
|
|||
## This program verifies Nim against the testcases.
|
||||
|
||||
import
|
||||
strutils, pegs, os, osproc, streams, json,
|
||||
strutils, pegs, os, osproc, streams, json, std/exitprocs,
|
||||
backend, parseopt, specs, htmlgen, browsers, terminal,
|
||||
algorithm, times, md5, sequtils, azure, intsets
|
||||
algorithm, times, md5, sequtils, azure, intsets, macros
|
||||
from std/sugar import dup
|
||||
import compiler/nodejs
|
||||
import lib/stdtest/testutils
|
||||
|
|
@ -26,7 +26,6 @@ const
|
|||
failString* = "FAIL: " # ensures all failures can be searched with 1 keyword in CI logs
|
||||
testsDir = "tests" & DirSep
|
||||
resultsFile = "testresults.html"
|
||||
#jsonFile = "testresults.json" # not used
|
||||
Usage = """Usage:
|
||||
testament [options] command [arguments]
|
||||
|
||||
|
|
@ -89,13 +88,6 @@ proc isSuccess(input: string): bool =
|
|||
# not clear how to do the equivalent of pkg/regex's: re"FOO(.*?)BAR" in pegs
|
||||
input.startsWith("Hint: ") and input.endsWith("[SuccessX]")
|
||||
|
||||
when false: # deadcode
|
||||
proc normalizeMsg(s: string): string =
|
||||
result = newStringOfCap(s.len+1)
|
||||
for x in splitLines(s):
|
||||
if result.len > 0: result.add '\L'
|
||||
result.add x.strip
|
||||
|
||||
proc getFileDir(filename: string): string =
|
||||
result = filename.splitFile().dir
|
||||
if not result.isAbsolute():
|
||||
|
|
@ -111,8 +103,8 @@ proc execCmdEx2(command: string, args: openArray[string]; workingDir, input: str
|
|||
for arg in args:
|
||||
result.cmdLine.add ' '
|
||||
result.cmdLine.add quoteShell(arg)
|
||||
var p = startProcess(command, workingDir=workingDir, args=args,
|
||||
options={poStdErrToStdOut, poUsePath})
|
||||
var p = startProcess(command, workingDir = workingDir, args = args,
|
||||
options = {poStdErrToStdOut, poUsePath})
|
||||
var outp = outputStream(p)
|
||||
|
||||
# There is no way to provide input for the child process
|
||||
|
|
@ -122,12 +114,12 @@ proc execCmdEx2(command: string, args: openArray[string]; workingDir, input: str
|
|||
instream.write(input)
|
||||
close instream
|
||||
|
||||
result.exitCode = -1
|
||||
result.exitCode = -1
|
||||
var line = newStringOfCap(120)
|
||||
while true:
|
||||
if outp.readLine(line):
|
||||
result.output.string.add(line.string)
|
||||
result.output.string.add("\n")
|
||||
result.output.add line
|
||||
result.output.add '\n'
|
||||
else:
|
||||
result.exitCode = peekExitCode(p)
|
||||
if result.exitCode != -1: break
|
||||
|
|
@ -140,10 +132,10 @@ proc nimcacheDir(filename, options: string, target: TTarget): string =
|
|||
|
||||
proc prepareTestArgs(cmdTemplate, filename, options, nimcache: string,
|
||||
target: TTarget, extraOptions = ""): seq[string] =
|
||||
var options = target.defaultOptions & " " & options
|
||||
var options = target.defaultOptions & ' ' & options
|
||||
# improve pending https://github.com/nim-lang/Nim/issues/14343
|
||||
if nimcache.len > 0: options.add " " & ("--nimCache:" & nimcache).quoteShell
|
||||
options.add " " & extraOptions
|
||||
if nimcache.len > 0: options.add ' ' & ("--nimCache:" & nimcache).quoteShell
|
||||
options.add ' ' & extraOptions
|
||||
result = parseCmdLine(cmdTemplate % ["target", targetToCmd[target],
|
||||
"options", options, "file", filename.quoteShell,
|
||||
"filedir", filename.getFileDir(), "nim", compilerPrefix])
|
||||
|
|
@ -153,8 +145,8 @@ proc callCompiler(cmdTemplate, filename, options, nimcache: string,
|
|||
let c = prepareTestArgs(cmdTemplate, filename, options, nimcache, target,
|
||||
extraOptions)
|
||||
result.cmd = quoteShellCommand(c)
|
||||
var p = startProcess(command=c[0], args=c[1 .. ^1],
|
||||
options={poStdErrToStdOut, poUsePath})
|
||||
var p = startProcess(command = c[0], args = c[1 .. ^1],
|
||||
options = {poStdErrToStdOut, poUsePath})
|
||||
let outp = p.outputStream
|
||||
var suc = ""
|
||||
var err = ""
|
||||
|
|
@ -163,7 +155,7 @@ proc callCompiler(cmdTemplate, filename, options, nimcache: string,
|
|||
result.nimout = ""
|
||||
while true:
|
||||
if outp.readLine(x):
|
||||
result.nimout.add(x & "\n")
|
||||
result.nimout.add(x & '\n')
|
||||
if x =~ pegOfInterest:
|
||||
# `err` should contain the last error/warning message
|
||||
err = x
|
||||
|
|
@ -201,8 +193,8 @@ proc callCompiler(cmdTemplate, filename, options, nimcache: string,
|
|||
proc callCCompiler(cmdTemplate, filename, options: string,
|
||||
target: TTarget): TSpec =
|
||||
let c = prepareTestArgs(cmdTemplate, filename, options, nimcache = "", target)
|
||||
var p = startProcess(command="gcc", args=c[5 .. ^1],
|
||||
options={poStdErrToStdOut, poUsePath})
|
||||
var p = startProcess(command = "gcc", args = c[5 .. ^1],
|
||||
options = {poStdErrToStdOut, poUsePath})
|
||||
let outp = p.outputStream
|
||||
var x = newStringOfCap(120)
|
||||
result.nimout = ""
|
||||
|
|
@ -212,7 +204,7 @@ proc callCCompiler(cmdTemplate, filename, options: string,
|
|||
result.line = -1
|
||||
while true:
|
||||
if outp.readLine(x):
|
||||
result.nimout.add(x & "\n")
|
||||
result.nimout.add(x & '\n')
|
||||
elif not running(p):
|
||||
break
|
||||
close(p)
|
||||
|
|
@ -225,8 +217,6 @@ proc initResults: TResults =
|
|||
result.skipped = 0
|
||||
result.data = ""
|
||||
|
||||
import macros
|
||||
|
||||
macro ignoreStyleEcho(args: varargs[typed]): untyped =
|
||||
let typForegroundColor = bindSym"ForegroundColor".getType
|
||||
let typBackgroundColor = bindSym"BackgroundColor".getType
|
||||
|
|
@ -260,8 +250,8 @@ proc addResult(r: var TResults, test: TTest, target: TTarget,
|
|||
# test.name is easier to find than test.name.extractFilename
|
||||
# A bit hacky but simple and works with tests/testament/tshould_not_work.nim
|
||||
var name = test.name.replace(DirSep, '/')
|
||||
name.add " " & $target
|
||||
if test.options.len > 0: name.add " " & test.options
|
||||
name.add ' ' & $target
|
||||
if test.options.len > 0: name.add ' ' & test.options
|
||||
|
||||
let duration = epochTime() - test.startTime
|
||||
let success = if test.spec.timeout > 0.0 and duration > test.spec.timeout: reTimeout
|
||||
|
|
@ -278,7 +268,7 @@ proc addResult(r: var TResults, test: TTest, target: TTarget,
|
|||
given = given)
|
||||
r.data.addf("$#\t$#\t$#\t$#", name, expected, given, $success)
|
||||
template disp(msg) =
|
||||
maybeStyledEcho styleDim, fgYellow, msg & " ", styleBright, fgCyan, name
|
||||
maybeStyledEcho styleDim, fgYellow, msg & ' ', styleBright, fgCyan, name
|
||||
if success == reSuccess:
|
||||
maybeStyledEcho fgGreen, "PASS: ", fgCyan, alignLeft(name, 60), fgBlue, " (", durationStr, " sec)"
|
||||
elif success == reDisabled:
|
||||
|
|
@ -307,18 +297,18 @@ proc addResult(r: var TResults, test: TTest, target: TTarget,
|
|||
of reDisabled, reJoined:
|
||||
("Skipped", "")
|
||||
of reBuildFailed, reNimcCrash, reInstallFailed:
|
||||
("Failed", "Failure: " & $success & "\n" & given)
|
||||
("Failed", "Failure: " & $success & '\n' & given)
|
||||
else:
|
||||
("Failed", "Failure: " & $success & "\nExpected:\n" & expected & "\n\n" & "Gotten:\n" & given)
|
||||
if isAzure:
|
||||
azure.addTestResult(name, test.cat.string, int(duration * 1000), msg, success)
|
||||
else:
|
||||
var p = startProcess("appveyor", args=["AddTest", test.name.replace("\\", "/") & test.options,
|
||||
var p = startProcess("appveyor", args = ["AddTest", test.name.replace("\\", "/") & test.options,
|
||||
"-Framework", "nim-testament", "-FileName",
|
||||
test.cat.string,
|
||||
"-Outcome", outcome, "-ErrorMessage", msg,
|
||||
"-Duration", $(duration*1000).int],
|
||||
options={poStdErrToStdOut, poUsePath, poParentStreams})
|
||||
"-Duration", $(duration * 1000).int],
|
||||
options = {poStdErrToStdOut, poUsePath, poParentStreams})
|
||||
discard waitForExit(p)
|
||||
close(p)
|
||||
|
||||
|
|
@ -346,7 +336,7 @@ proc checkForInlineErrors(r: var TResults, expected, given: TSpec, test: TTest,
|
|||
for j in 0..high(expected.inlineErrors):
|
||||
if j notin covered:
|
||||
var e = test.name
|
||||
e.add "("
|
||||
e.add '('
|
||||
e.addInt expected.inlineErrors[j].line
|
||||
if expected.inlineErrors[j].col > 0:
|
||||
e.add ", "
|
||||
|
|
@ -404,7 +394,7 @@ proc codegenCheck(test: TTest, target: TTarget, spec: TSpec, expectedMsg: var st
|
|||
given: var TSpec) =
|
||||
try:
|
||||
let genFile = generatedFile(test, target)
|
||||
let contents = readFile(genFile).string
|
||||
let contents = readFile(genFile)
|
||||
for check in spec.ccodeCheck:
|
||||
if check.len > 0 and check[0] == '\\':
|
||||
# little hack to get 'match' support:
|
||||
|
|
@ -441,12 +431,12 @@ proc compilerOutputTests(test: TTest, target: TTarget, given: var TSpec,
|
|||
givenmsg = given.nimout.strip
|
||||
nimoutCheck(test, expectedmsg, given)
|
||||
else:
|
||||
givenmsg = "$ " & given.cmd & "\n" & given.nimout
|
||||
givenmsg = "$ " & given.cmd & '\n' & given.nimout
|
||||
if given.err == reSuccess: inc(r.passed)
|
||||
r.addResult(test, target, expectedmsg, givenmsg, given.err)
|
||||
|
||||
proc getTestSpecTarget(): TTarget =
|
||||
if getEnv("NIM_COMPILE_TO_CPP", "false").string == "true":
|
||||
if getEnv("NIM_COMPILE_TO_CPP", "false") == "true":
|
||||
result = targetCpp
|
||||
else:
|
||||
result = targetC
|
||||
|
|
@ -479,7 +469,7 @@ proc testSpecHelper(r: var TResults, test: var TTest, expected: TSpec,
|
|||
var given = callCompiler(expected.getCmd, test.name, test.options,
|
||||
nimcache, target, extraOptions)
|
||||
if given.err != reSuccess:
|
||||
r.addResult(test, target, "", "$ " & given.cmd & "\n" & given.nimout, given.err)
|
||||
r.addResult(test, target, "", "$ " & given.cmd & '\n' & given.nimout, given.err)
|
||||
else:
|
||||
let isJsTarget = target == targetJS
|
||||
var exeFile = changeFileExt(test.name, if isJsTarget: "js" else: ExeExt)
|
||||
|
|
@ -511,13 +501,13 @@ proc testSpecHelper(r: var TResults, test: var TTest, expected: TSpec,
|
|||
if exitCode != 0: exitCode = 1
|
||||
let bufB =
|
||||
if expected.sortoutput:
|
||||
var buf2 = buf.string
|
||||
var buf2 = buf
|
||||
buf2.stripLineEnd
|
||||
var x = splitLines(buf2)
|
||||
sort(x, system.cmp)
|
||||
join(x, "\n") & "\n"
|
||||
join(x, "\n") & '\n'
|
||||
else:
|
||||
buf.string
|
||||
buf
|
||||
if exitCode != expected.exitCode:
|
||||
r.addResult(test, target, "exitcode: " & $expected.exitCode,
|
||||
"exitcode: " & $exitCode & "\n\nOutput:\n" &
|
||||
|
|
@ -566,7 +556,7 @@ proc testSpec(r: var TResults, test: TTest, targets: set[TTarget] = {}) =
|
|||
else:
|
||||
targetHelper(r, test, expected)
|
||||
|
||||
proc testSpecWithNimcache(r: var TResults, test: TTest; nimcache: string) =
|
||||
proc testSpecWithNimcache(r: var TResults, test: TTest; nimcache: string) {.used.} =
|
||||
if not checkDisabled(r, test): return
|
||||
for target in test.spec.targets:
|
||||
inc(r.total)
|
||||
|
|
@ -600,7 +590,7 @@ proc testExec(r: var TResults, test: TTest) =
|
|||
given.err = reSuccess
|
||||
else:
|
||||
given.err = reExitcodesDiffer
|
||||
given.msg = outp.string
|
||||
given.msg = outp
|
||||
|
||||
if given.err == reSuccess: inc(r.passed)
|
||||
r.addResult(test, targetC, "", given.msg, given.err)
|
||||
|
|
@ -612,7 +602,7 @@ proc makeTest(test, options: string, cat: Category): TTest =
|
|||
result.spec = parseSpec(addFileExt(test, ".nim"))
|
||||
result.startTime = epochTime()
|
||||
|
||||
proc makeRawTest(test, options: string, cat: Category): TTest =
|
||||
proc makeRawTest(test, options: string, cat: Category): TTest {.used.} =
|
||||
result.cat = cat
|
||||
result.name = test
|
||||
result.options = options
|
||||
|
|
@ -659,7 +649,7 @@ proc loadSkipFrom(name: string): seq[string] =
|
|||
# used by `nlvm` (at least)
|
||||
for line in lines(name):
|
||||
let sline = line.strip()
|
||||
if sline.len > 0 and not sline.startsWith("#"):
|
||||
if sline.len > 0 and not sline.startsWith('#'):
|
||||
result.add sline
|
||||
|
||||
proc main() =
|
||||
|
|
@ -675,20 +665,20 @@ proc main() =
|
|||
var p = initOptParser()
|
||||
p.next()
|
||||
while p.kind in {cmdLongOption, cmdShortOption}:
|
||||
case p.key.string.normalize
|
||||
case p.key.normalize
|
||||
of "print", "verbose": optPrintResults = true
|
||||
of "failing": optFailing = true
|
||||
of "pedantic": discard "now always enabled"
|
||||
of "targets":
|
||||
targetsStr = p.val.string
|
||||
targetsStr = p.val
|
||||
gTargets = parseTargets(targetsStr)
|
||||
targetsSet = true
|
||||
of "nim":
|
||||
compilerPrefix = addFileExt(p.val.string.absolutePath, ExeExt)
|
||||
compilerPrefix = addFileExt(p.val.absolutePath, ExeExt)
|
||||
of "directory":
|
||||
setCurrentDir(p.val.string)
|
||||
setCurrentDir(p.val)
|
||||
of "colors":
|
||||
case p.val.string:
|
||||
case p.val:
|
||||
of "on":
|
||||
useColors = true
|
||||
of "off":
|
||||
|
|
@ -707,7 +697,7 @@ proc main() =
|
|||
of "simulate":
|
||||
simulate = true
|
||||
of "megatest":
|
||||
case p.val.string:
|
||||
case p.val:
|
||||
of "on":
|
||||
useMegatest = true
|
||||
of "off":
|
||||
|
|
@ -715,7 +705,7 @@ proc main() =
|
|||
else:
|
||||
quit Usage
|
||||
of "backendlogging":
|
||||
case p.val.string:
|
||||
case p.val:
|
||||
of "on":
|
||||
backendLogging = true
|
||||
of "off":
|
||||
|
|
@ -723,13 +713,13 @@ proc main() =
|
|||
else:
|
||||
quit Usage
|
||||
of "skipfrom":
|
||||
skipFrom = p.val.string
|
||||
skipFrom = p.val
|
||||
else:
|
||||
quit Usage
|
||||
p.next()
|
||||
if p.kind != cmdArgument:
|
||||
quit Usage
|
||||
var action = p.key.string.normalize
|
||||
var action = p.key.normalize
|
||||
p.next()
|
||||
var r = initResults()
|
||||
case action
|
||||
|
|
@ -748,7 +738,7 @@ proc main() =
|
|||
myself &= " " & quoteShell("--skipFrom:" & skipFrom)
|
||||
|
||||
var cats: seq[string]
|
||||
let rest = if p.cmdLineRest.string.len > 0: " " & p.cmdLineRest.string else: ""
|
||||
let rest = if p.cmdLineRest.len > 0: " " & p.cmdLineRest else: ""
|
||||
for kind, dir in walkDir(testsDir):
|
||||
assert testsDir.startsWith(testsDir)
|
||||
let cat = dir[testsDir.len .. ^1]
|
||||
|
|
@ -769,14 +759,14 @@ proc main() =
|
|||
skips = loadSkipFrom(skipFrom)
|
||||
for i, cati in cats:
|
||||
progressStatus(i)
|
||||
processCategory(r, Category(cati), p.cmdLineRest.string, testsDir, runJoinableTests = false)
|
||||
processCategory(r, Category(cati), p.cmdLineRest, testsDir, runJoinableTests = false)
|
||||
else:
|
||||
addQuitProc azure.finalize
|
||||
addExitProc azure.finalize
|
||||
quit osproc.execProcesses(cmds, {poEchoCmd, poStdErrToStdOut, poUsePath, poParentStreams}, beforeRunEvent = progressStatus)
|
||||
of "c", "cat", "category":
|
||||
skips = loadSkipFrom(skipFrom)
|
||||
var cat = Category(p.key)
|
||||
processCategory(r, cat, p.cmdLineRest.string, testsDir, runJoinableTests = true)
|
||||
processCategory(r, cat, p.cmdLineRest, testsDir, runJoinableTests = true)
|
||||
of "pcat":
|
||||
skips = loadSkipFrom(skipFrom)
|
||||
# 'pcat' is used for running a category in parallel. Currently the only
|
||||
|
|
@ -785,12 +775,12 @@ proc main() =
|
|||
isMainProcess = false
|
||||
var cat = Category(p.key)
|
||||
p.next
|
||||
processCategory(r, cat, p.cmdLineRest.string, testsDir, runJoinableTests = false)
|
||||
processCategory(r, cat, p.cmdLineRest, testsDir, runJoinableTests = false)
|
||||
of "p", "pat", "pattern":
|
||||
skips = loadSkipFrom(skipFrom)
|
||||
let pattern = p.key
|
||||
p.next
|
||||
processPattern(r, pattern, p.cmdLineRest.string, simulate)
|
||||
processPattern(r, pattern, p.cmdLineRest, simulate)
|
||||
of "r", "run":
|
||||
var subPath = p.key
|
||||
let (cat, path) = splitTestFile(subPath)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue