Skip to content

Commit 0b2bbca

Browse files
authored
fix #18077 testament now parses cmd properly (#18086)
1 parent 8df55d0 commit 0b2bbca

File tree

3 files changed

+61
-16
lines changed

3 files changed

+61
-16
lines changed

testament/categories.nim

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,9 @@ proc runBasicDLLTest(c, r: var TResults, cat: Category, options: string) =
8787
var hcri = makeTest("tests/dll/nimhcr_integration.nim",
8888
options & " --forceBuild --hotCodeReloading:on" & rpath, cat)
8989
let nimcache = nimcacheDir(hcri.name, hcri.options, getTestSpecTarget())
90-
hcri.args = prepareTestArgs(hcri.spec.getCmd, hcri.name,
90+
let cmd = prepareTestCmd(hcri.spec.getCmd, hcri.name,
9191
hcri.options, nimcache, getTestSpecTarget())
92+
hcri.testArgs = cmd.parseCmdLine
9293
testSpec r, hcri
9394

9495
proc dllTests(r: var TResults, cat: Category, options: string) =

testament/testament.nim

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ type
8585
name: string
8686
cat: Category
8787
options: string
88-
args: seq[string]
88+
testArgs: seq[string]
8989
spec: TSpec
9090
startTime: float
9191
debugInfo: string
@@ -154,24 +154,23 @@ proc nimcacheDir(filename, options: string, target: TTarget): string =
154154
let hashInput = options & $target
155155
result = "nimcache" / (filename & '_' & hashInput.getMD5)
156156

157-
proc prepareTestArgs(cmdTemplate, filename, options, nimcache: string,
158-
target: TTarget, extraOptions = ""): seq[string] =
157+
proc prepareTestCmd(cmdTemplate, filename, options, nimcache: string,
158+
target: TTarget, extraOptions = ""): string =
159159
var options = target.defaultOptions & ' ' & options
160-
# improve pending https://github.com/nim-lang/Nim/issues/14343
161-
if nimcache.len > 0: options.add ' ' & ("--nimCache:" & nimcache).quoteShell
160+
if nimcache.len > 0: options.add(" --nimCache:$#" % nimcache.quoteShell)
162161
options.add ' ' & extraOptions
163-
result = parseCmdLine(cmdTemplate % ["target", targetToCmd[target],
162+
# we avoid using `parseCmdLine` which is buggy, refs bug #14343
163+
result = cmdTemplate % ["target", targetToCmd[target],
164164
"options", options, "file", filename.quoteShell,
165-
"filedir", filename.getFileDir(), "nim", compilerPrefix])
165+
"filedir", filename.getFileDir(), "nim", compilerPrefix]
166166

167167
proc callNimCompiler(cmdTemplate, filename, options, nimcache: string,
168168
target: TTarget, extraOptions = ""): TSpec =
169-
let c = prepareTestArgs(cmdTemplate, filename, options, nimcache, target,
169+
result.cmd = prepareTestCmd(cmdTemplate, filename, options, nimcache, target,
170170
extraOptions)
171-
result.cmd = quoteShellCommand(c)
172-
verboseCmd(c.quoteShellCommand)
173-
var p = startProcess(command = c[0], args = c[1 .. ^1],
174-
options = {poStdErrToStdOut, poUsePath})
171+
verboseCmd(result.cmd)
172+
var p = startProcess(command = result.cmd,
173+
options = {poStdErrToStdOut, poUsePath, poEvalCommand})
175174
let outp = p.outputStream
176175
var foundSuccessMsg = false
177176
var foundErrorMsg = false
@@ -224,9 +223,33 @@ proc callNimCompiler(cmdTemplate, filename, options, nimcache: string,
224223

225224
proc callCCompiler(cmdTemplate, filename, options: string,
226225
target: TTarget): TSpec =
227-
let c = prepareTestArgs(cmdTemplate, filename, options, nimcache = "", target)
226+
let cmd = prepareTestCmd(cmdTemplate, filename, options, nimcache = "", target)
227+
doAssert false
228+
#[
229+
this code hasn't been run in a while, and should be removed which simplifies code
230+
there are better ways to do this anyways (e.g. running c code from a nim file)
231+
232+
the only place where this is called is:
233+
`testC r, makeTest("tests/realtimeGC/cmain", cOptions, cat), actionRun`
234+
which isn't run unless you call:
235+
XDG_CONFIG_HOME= nim r --lib:lib --stacktrace:on testament/testament.nim r longgc
236+
237+
and this fails since at least nim 1.0 with:
238+
testament/testament.nim(851) testament
239+
testament/testament.nim(822) main
240+
testament/categories.nim(713) processCategory
241+
testament/categories.nim(189) longGCTests
242+
testament/testament.nim(644) makeTest
243+
testament/specs.nim(251) parseSpec
244+
testament/specs.nim(184) extractSpec
245+
lib/system/io.nim(861) readFile
246+
Error: unhandled exception: cannot open: tests/realtimeGC/cmain.nim [IOError]
247+
248+
Also, `c[5 .. ^1]` is too magical.
249+
]#
250+
let c = cmd.parseCmdLine
228251
var p = startProcess(command = "gcc", args = c[5 .. ^1],
229-
options = {poStdErrToStdOut, poUsePath})
252+
options = {poStdErrToStdOut, poUsePath, poEvalCommand})
230253
let outp = p.outputStream
231254
var x = newStringOfCap(120)
232255
result.nimout = ""
@@ -525,7 +548,7 @@ proc testSpecHelper(r: var TResults, test: var TTest, expected: TSpec,
525548
reExeNotFound)
526549
else:
527550
var exeCmd: string
528-
var args = test.args
551+
var args = test.testArgs
529552
if isJsTarget:
530553
exeCmd = nodejs
531554
# see D20210217T215950

tests/misc/t18077.nim

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
discard """
2+
cmd: '''nim doc -d:nimTestsT18077b:4 --doccmd:"-d:nimTestsT18077 -d:nimTestsT18077b:3 --hints:off" $file'''
3+
action: compile
4+
"""
5+
6+
# bug #18077
7+
8+
const nimTestsT18077b {.intdefine.} = 1
9+
10+
static:
11+
when defined(nimdoc):
12+
doAssert nimTestsT18077b == 4
13+
doAssert not defined(nimTestsT18077)
14+
else:
15+
doAssert defined(nimTestsT18077)
16+
doAssert nimTestsT18077b == 3
17+
18+
runnableExamples:
19+
const nimTestsT18077b {.intdefine.} = 2
20+
doAssert nimTestsT18077b == 3
21+
doAssert defined(nimTestsT18077)

0 commit comments

Comments
 (0)