@@ -33,16 +33,23 @@ const
33
33
34
34
proc runNimCmd(file, options = " " , rtarg = " " ): auto =
35
35
let fileabs = testsDir / file.unixToNativePath
36
- doAssert fileabs.fileExists, fileabs
36
+ # doAssert fileabs.fileExists, fileabs # disabled because this allows passing `nim r --eval:code fakefile`
37
37
let cmd = fmt" { nim} { mode} { options} --hints:off { fileabs} { rtarg} "
38
38
result = execCmdEx(cmd)
39
- when false : echo result [0 ] & " \n " & result [1 ] # for debugging
39
+ when false : # for debugging
40
+ echo cmd
41
+ echo result [0 ] & " \n " & $ result [1 ]
40
42
41
43
proc runNimCmdChk(file, options = " " , rtarg = " " ): string =
42
44
let (ret, status) = runNimCmd(file, options, rtarg = rtarg)
43
45
doAssert status == 0 , $ (file, options) & " \n " & ret
44
46
ret
45
47
48
+ proc genShellCmd(filename: string ): string =
49
+ let filename = filename.quoteShell
50
+ when defined(windows): " cmd /c " & filename # or "cmd /c " ?
51
+ else : " sh " & filename
52
+
46
53
when defined(nimTrunnerFfi):
47
54
block : # mevalffi
48
55
when defined(openbsd):
@@ -71,7 +78,9 @@ foo:0.03:asdf:103:105
71
78
ret=[s1:foobar s2:foobar age:25 pi:3.14]
72
79
""" , output
73
80
74
- else : # don't run twice the same test
81
+ elif not defined(nimTestsTrunnerDebugging):
82
+ # don't run twice the same test with `nimTrunnerFfi`
83
+ # use `-d:nimTestsTrunnerDebugging` for debugging convenience when you want to just run 1 test
75
84
import std/ strutils
76
85
import std/ json
77
86
template check2(msg) = doAssert msg in output, output
@@ -330,3 +339,21 @@ running: v2
330
339
doAssert " D20210428T161003" in j[" defined_symbols" ].to(seq [string ])
331
340
doAssert j[" version" ].to(string ) == NimVersion
332
341
doAssert j[" nimExe" ].to(string ) == getCurrentCompilerExe()
342
+
343
+ block : # genscript
344
+ const nimcache2 = buildDir / " D20210524T212851"
345
+ removeDir(nimcache2)
346
+ let input = " tgenscript_fakefile" # no need for a real file, --eval is good enough
347
+ let output = runNimCmdChk(input, fmt""" --genscript --nimcache:{ nimcache2.quoteShell} --eval:"echo(12345)" """ )
348
+ doAssert output.len == 0 , output
349
+ let ext = when defined(windows): " .bat" else : " .sh"
350
+ let filename = fmt" compile_{ input} { ext} " # synchronize with `generateScript`
351
+ doAssert fileExists(nimcache2/ filename), nimcache2/ filename
352
+ let (outp, status) = execCmdEx(genShellCmd(filename), options = {poStdErrToStdOut}, workingDir = nimcache2)
353
+ doAssert status == 0 , outp
354
+ let (outp2, status2) = execCmdEx(nimcache2 / input, options = {poStdErrToStdOut})
355
+ doAssert outp2 == " 12345\n " , outp2
356
+ doAssert status2 == 0
357
+
358
+ else :
359
+ discard # only during debugging, tests added here will run with `-d:nimTestsTrunnerDebugging` enabled
0 commit comments