Skip to content

Commit b59dc3b

Browse files
authored
remove some custom logic in testament around flags, testExec (#18090)
* remove some custom logic in testament around flags, testExec * remove testExec, custom logic around flags from testament * fixup
1 parent 478f717 commit b59dc3b

File tree

4 files changed

+30
-48
lines changed

4 files changed

+30
-48
lines changed

testament/categories.nim

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ const
2323
"debugger",
2424
"dll",
2525
"examples",
26-
"flags",
2726
"gc",
2827
"io",
2928
"js",
@@ -48,26 +47,6 @@ proc isTestFile*(file: string): bool =
4847
let (_, name, ext) = splitFile(file)
4948
result = ext == ".nim" and name.startsWith("t")
5049

51-
# --------------------- flags tests -------------------------------------------
52-
53-
proc flagTests(r: var TResults, cat: Category, options: string) =
54-
# --genscript
55-
const filename = testsDir/"flags"/"tgenscript"
56-
const genopts = " --genscript"
57-
let nimcache = nimcacheDir(filename, genopts, targetC)
58-
testSpec r, makeTest(filename, genopts, cat)
59-
60-
when defined(windows):
61-
testExec r, makeTest(filename, " cmd /c cd " & nimcache &
62-
" && compile_tgenscript.bat", cat)
63-
64-
elif defined(posix):
65-
testExec r, makeTest(filename, " sh -c \"cd " & nimcache &
66-
" && sh compile_tgenscript.sh\"", cat)
67-
68-
# Run
69-
testExec r, makeTest(filename, " " & nimcache / "tgenscript", cat)
70-
7150
# --------------------- DLL generation tests ----------------------------------
7251

7352
proc runBasicDLLTest(c, r: var TResults, cat: Category, options: string) =
@@ -705,8 +684,6 @@ proc processCategory(r: var TResults, cat: Category,
705684
jsTests(r, cat, options)
706685
of "dll":
707686
dllTests(r, cat, options)
708-
of "flags":
709-
flagTests(r, cat, options)
710687
of "gc":
711688
gcTests(r, cat, options)
712689
of "longgc":

testament/testament.nim

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -621,22 +621,6 @@ proc testC(r: var TResults, test: TTest, action: TTestAction) =
621621
if exitCode != 0: given.err = reExitcodesDiffer
622622
if given.err == reSuccess: inc(r.passed)
623623

624-
proc testExec(r: var TResults, test: TTest) =
625-
# runs executable or script, just goes by exit code
626-
if not checkDisabled(r, test): return
627-
628-
inc(r.total)
629-
let (outp, errC) = execCmdEx(test.options.strip())
630-
var given: TSpec
631-
if errC == 0:
632-
given.err = reSuccess
633-
else:
634-
given.err = reExitcodesDiffer
635-
given.msg = outp
636-
637-
if given.err == reSuccess: inc(r.passed)
638-
r.addResult(test, targetC, "", given.msg, given.err)
639-
640624
proc makeTest(test, options: string, cat: Category): TTest =
641625
result.cat = cat
642626
result.name = test

tests/flags/tgenscript.nim

Lines changed: 0 additions & 6 deletions
This file was deleted.

tests/misc/trunner.nim

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,23 @@ const
3333

3434
proc runNimCmd(file, options = "", rtarg = ""): auto =
3535
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`
3737
let cmd = fmt"{nim} {mode} {options} --hints:off {fileabs} {rtarg}"
3838
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]
4042

4143
proc runNimCmdChk(file, options = "", rtarg = ""): string =
4244
let (ret, status) = runNimCmd(file, options, rtarg = rtarg)
4345
doAssert status == 0, $(file, options) & "\n" & ret
4446
ret
4547

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+
4653
when defined(nimTrunnerFfi):
4754
block: # mevalffi
4855
when defined(openbsd):
@@ -71,7 +78,9 @@ foo:0.03:asdf:103:105
7178
ret=[s1:foobar s2:foobar age:25 pi:3.14]
7279
""", output
7380

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
7584
import std/strutils
7685
import std/json
7786
template check2(msg) = doAssert msg in output, output
@@ -330,3 +339,21 @@ running: v2
330339
doAssert "D20210428T161003" in j["defined_symbols"].to(seq[string])
331340
doAssert j["version"].to(string) == NimVersion
332341
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

Comments
 (0)