fix #18077 testament now parses cmd properly (#18086)

This commit is contained in:
Timothee Cour 2021-05-26 00:46:53 -07:00 • committed by GitHub
commit 0b2bbcaa23
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 61 additions and 16 deletions

View file

@ -87,8 +87,9 @@ proc runBasicDLLTest(c, r: var TResults, cat: Category, options: string) =
var hcri = makeTest("tests/dll/nimhcr_integration.nim", var hcri = makeTest("tests/dll/nimhcr_integration.nim",
options & " --forceBuild --hotCodeReloading:on" & rpath, cat) options & " --forceBuild --hotCodeReloading:on" & rpath, cat)
let nimcache = nimcacheDir(hcri.name, hcri.options, getTestSpecTarget()) let nimcache = nimcacheDir(hcri.name, hcri.options, getTestSpecTarget())
hcri.args = prepareTestArgs(hcri.spec.getCmd, hcri.name, let cmd = prepareTestCmd(hcri.spec.getCmd, hcri.name,
hcri.options, nimcache, getTestSpecTarget()) hcri.options, nimcache, getTestSpecTarget())
hcri.testArgs = cmd.parseCmdLine
testSpec r, hcri testSpec r, hcri
proc dllTests(r: var TResults, cat: Category, options: string) = proc dllTests(r: var TResults, cat: Category, options: string) =

View file

@ -85,7 +85,7 @@ type
name: string name: string
cat: Category cat: Category
options: string options: string
args: seq[string] testArgs: seq[string]
spec: TSpec spec: TSpec
startTime: float startTime: float
debugInfo: string debugInfo: string
@ -154,24 +154,23 @@ proc nimcacheDir(filename, options: string, target: TTarget): string =
let hashInput = options & $target let hashInput = options & $target
result = "nimcache" / (filename & '_' & hashInput.getMD5) result = "nimcache" / (filename & '_' & hashInput.getMD5)
proc prepareTestArgs(cmdTemplate, filename, options, nimcache: string, proc prepareTestCmd(cmdTemplate, filename, options, nimcache: string,
target: TTarget, extraOptions = ""): seq[string] = target: TTarget, extraOptions = ""): 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)
if nimcache.len > 0: options.add ' ' & ("--nimCache:" & nimcache).quoteShell
options.add ' ' & extraOptions options.add ' ' & extraOptions
result = parseCmdLine(cmdTemplate % ["target", targetToCmd[target], # we avoid using `parseCmdLine` which is buggy, refs bug #14343
result = cmdTemplate % ["target", targetToCmd[target],
"options", options, "file", filename.quoteShell, "options", options, "file", filename.quoteShell,
"filedir", filename.getFileDir(), "nim", compilerPrefix]) "filedir", filename.getFileDir(), "nim", compilerPrefix]
proc callNimCompiler(cmdTemplate, filename, options, nimcache: string, proc callNimCompiler(cmdTemplate, filename, options, nimcache: string,
target: TTarget, extraOptions = ""): TSpec = target: TTarget, extraOptions = ""): TSpec =
let c = prepareTestArgs(cmdTemplate, filename, options, nimcache, target, result.cmd = prepareTestCmd(cmdTemplate, filename, options, nimcache, target,
extraOptions) extraOptions)
result.cmd = quoteShellCommand(c) verboseCmd(result.cmd)
verboseCmd(c.quoteShellCommand) var p = startProcess(command = result.cmd,
var p = startProcess(command = c[0], args = c[1 .. ^1], options = {poStdErrToStdOut, poUsePath, poEvalCommand})
options = {poStdErrToStdOut, poUsePath})
let outp = p.outputStream let outp = p.outputStream
var foundSuccessMsg = false var foundSuccessMsg = false
var foundErrorMsg = false var foundErrorMsg = false
@ -224,9 +223,33 @@ proc callNimCompiler(cmdTemplate, filename, options, nimcache: string,
proc callCCompiler(cmdTemplate, filename, options: string, proc callCCompiler(cmdTemplate, filename, options: string,
target: TTarget): TSpec = target: TTarget): TSpec =
let c = prepareTestArgs(cmdTemplate, filename, options, nimcache = "", target) let cmd = prepareTestCmd(cmdTemplate, filename, options, nimcache = "", target)
doAssert false
#[
this code hasn't been run in a while, and should be removed which simplifies code
there are better ways to do this anyways (e.g. running c code from a nim file)
the only place where this is called is:
`testC r, makeTest("tests/realtimeGC/cmain", cOptions, cat), actionRun`
which isn't run unless you call:
XDG_CONFIG_HOME= nim r --lib:lib --stacktrace:on testament/testament.nim r longgc
and this fails since at least nim 1.0 with:
testament/testament.nim(851) testament
testament/testament.nim(822) main
testament/categories.nim(713) processCategory
testament/categories.nim(189) longGCTests
testament/testament.nim(644) makeTest
testament/specs.nim(251) parseSpec
testament/specs.nim(184) extractSpec
lib/system/io.nim(861) readFile
Error: unhandled exception: cannot open: tests/realtimeGC/cmain.nim [IOError]
Also, `c[5 .. ^1]` is too magical.
]#
let c = cmd.parseCmdLine
var p = startProcess(command = "gcc", args = c[5 .. ^1], var p = startProcess(command = "gcc", args = c[5 .. ^1],
options = {poStdErrToStdOut, poUsePath}) options = {poStdErrToStdOut, poUsePath, poEvalCommand})
let outp = p.outputStream let outp = p.outputStream
var x = newStringOfCap(120) var x = newStringOfCap(120)
result.nimout = "" result.nimout = ""
@ -525,7 +548,7 @@ proc testSpecHelper(r: var TResults, test: var TTest, expected: TSpec,
reExeNotFound) reExeNotFound)
else: else:
var exeCmd: string var exeCmd: string
var args = test.args var args = test.testArgs
if isJsTarget: if isJsTarget:
exeCmd = nodejs exeCmd = nodejs
# see D20210217T215950 # see D20210217T215950

21
tests/misc/t18077.nim Normal file
View file

@ -0,0 +1,21 @@
discard """
cmd: '''nim doc -d:nimTestsT18077b:4 --doccmd:"-d:nimTestsT18077 -d:nimTestsT18077b:3 --hints:off" $file'''
action: compile
"""
# bug #18077
const nimTestsT18077b {.intdefine.} = 1
static:
when defined(nimdoc):
doAssert nimTestsT18077b == 4
doAssert not defined(nimTestsT18077)
else:
doAssert defined(nimTestsT18077)
doAssert nimTestsT18077b == 3
runnableExamples:
const nimTestsT18077b {.intdefine.} = 2
doAssert nimTestsT18077b == 3
doAssert defined(nimTestsT18077)