make tests/stdlib tests joinable (#14626)

* make tests/stdlib tests joinable

* fixup
This commit is contained in:
Timothee Cour
2020-06-15 04:27:33 -07:00
committed by GitHub
parent d51beb7b20
commit 49033eb531
9 changed files with 64 additions and 20 deletions

View File

@@ -35,7 +35,6 @@ const
"niminaction",
"threads",
"untestable",
"stdlib",
"testdata",
"nimcache",
"coroutines",
@@ -573,6 +572,9 @@ proc isJoinableSpec(spec: TSpec): bool =
spec.outputCheck != ocSubstr and
spec.ccodeCheck.len == 0 and
(spec.targets == {} or spec.targets == {targetC})
if result:
if spec.file.readFile.contains "when isMainModule":
result = false
proc norm(s: var string) =
while true:
@@ -585,6 +587,13 @@ proc quoted(a: string): string =
# todo: consider moving to system.nim
result.addQuoted(a)
proc normalizeExe(file: string): string =
# xxx common pattern, should be exposed in std/os, even if simple (error prone)
when defined(posix):
if file.len == 0: ""
elif DirSep in file: file else: "./" & file
else: file
proc runJoinedTest(r: var TResults, cat: Category, testsDir: string) =
## returns a list of tests that have problems
var specs: seq[TSpec] = @[]
@@ -620,26 +629,24 @@ proc runJoinedTest(r: var TResults, cat: Category, testsDir: string) =
for i, runSpec in specs:
let file = runSpec.file
let file2 = outDir / ("megatest_" & $i & ".nim")
let file2 = outDir / ("megatest_$1.nim" % $i)
# `include` didn't work with `trecmod2.nim`, so using `import`
let code = "echo \"" & marker & "\", " & quoted(file) & "\n"
let code = "echo \"$1\", $2\n" % [marker, quoted(file)]
createDir(file2.parentDir)
writeFile(file2, code)
megatest.add "import " & quoted(file2) & "\n"
megatest.add "import " & quoted(file) & "\n"
megatest.add "import $1\nimport $2\n" % [quoted(file2), quoted(file)]
writeFile("megatest.nim", megatest)
let args = ["c", "--nimCache:" & outDir, "-d:testing", "--listCmd",
"--listFullPaths:off", "--excessiveStackTrace:off", "megatest.nim"]
let megatestFile = testsDir / "megatest.nim" # so it uses testsDir / "config.nims"
writeFile(megatestFile, megatest)
let root = getCurrentDir()
let args = ["c", "--nimCache:" & outDir, "-d:testing", "--listCmd", "--path:" & root, megatestFile]
var (cmdLine, buf, exitCode) = execCmdEx2(command = compilerPrefix, args = args, input = "")
if exitCode != 0:
echo "$ ", cmdLine
echo buf.string
echo "$ " & cmdLine & "\n" & buf.string
quit("megatest compilation failed")
(buf, exitCode) = execCmdEx("./megatest")
(buf, exitCode) = execCmdEx(megatestFile.changeFileExt(ExeExt).normalizeExe)
if exitCode != 0:
echo buf.string
quit("megatest execution failed")
@@ -662,7 +669,7 @@ proc runJoinedTest(r: var TResults, cat: Category, testsDir: string) =
else:
echo "output OK"
removeFile("outputGotten.txt")
removeFile("megatest.nim")
removeFile(megatestFile)
#testSpec r, makeTest("megatest", options, cat)
# ---------------------------------------------------------------------------