diff --git a/koch.nim b/koch.nim index 3ec40534ba718..4403a6d6e7707 100644 --- a/koch.nim +++ b/koch.nim @@ -528,38 +528,39 @@ proc runCI(cmd: string) = echo hostInfo() # boot without -d:nimHasLibFFI to make sure this still works kochExecFold("Boot in release mode", "boot -d:release") - - ## build nimble early on to enable remainder to depend on it if needed - kochExecFold("Build Nimble", "nimble") - - if getEnv("NIM_TEST_PACKAGES", "0") == "1": - execFold("Test selected Nimble packages (1)", "nim c -r testament/testament cat nimble-packages-1") - elif getEnv("NIM_TEST_PACKAGES", "0") == "2": - execFold("Test selected Nimble packages (2)", "nim c -r testament/testament cat nimble-packages-2") - else: - buildTools() - - ## run tests - execFold("Test nimscript", "nim e tests/test_nimscript.nims") - when defined(windows): - # note: will be over-written below - execFold("Compile tester", "nim c -d:nimCoroutines --os:genode -d:posix --compileOnly testament/testament") - - # main bottleneck here - execFold("Run tester", "nim c -r -d:nimCoroutines testament/testament --pedantic all -d:nimCoroutines") - block CT_FFI: - when defined(posix): # windows can be handled in future PR's - execFold("nimble install -y libffi", "nimble install -y libffi") - const nimFFI = "./bin/nim.ctffi" - # no need to bootstrap with koch boot (would be slower) - let backend = if doUseCpp(): "cpp" else: "c" - execFold("build with -d:nimHasLibFFI", "nim $1 -d:release -d:nimHasLibFFI -o:$2 compiler/nim.nim" % [backend, nimFFI]) - execFold("test with -d:nimHasLibFFI", "$1 $2 -r testament/testament --nim:$1 r tests/trunner.nim" % [nimFFI, backend]) - - execFold("Run nimdoc tests", "nim c -r nimdoc/tester") - execFold("Run nimpretty tests", "nim c -r nimpretty/tester.nim") - when defined(posix): - execFold("Run nimsuggest tests", "nim c -r nimsuggest/tester") + execFold("test with -d:nimHasLibFFI", "$1 $2 -r testament/testament --nim:$1 r tests/trunner.nim" % [getCurrentCompilerExe(), "c"]) + + # ## build nimble early on to enable remainder to depend on it if needed + # kochExecFold("Build Nimble", "nimble") + + # if getEnv("NIM_TEST_PACKAGES", "0") == "1": + # execFold("Test selected Nimble packages (1)", "nim c -r testament/testament cat nimble-packages-1") + # elif getEnv("NIM_TEST_PACKAGES", "0") == "2": + # execFold("Test selected Nimble packages (2)", "nim c -r testament/testament cat nimble-packages-2") + # else: + # buildTools() + + # ## run tests + # execFold("Test nimscript", "nim e tests/test_nimscript.nims") + # when defined(windows): + # # note: will be over-written below + # execFold("Compile tester", "nim c -d:nimCoroutines --os:genode -d:posix --compileOnly testament/testament") + + # # main bottleneck here + # execFold("Run tester", "nim c -r -d:nimCoroutines testament/testament --pedantic all -d:nimCoroutines") + # block CT_FFI: + # when defined(posix): # windows can be handled in future PR's + # execFold("nimble install -y libffi", "nimble install -y libffi") + # const nimFFI = "./bin/nim.ctffi" + # # no need to bootstrap with koch boot (would be slower) + # let backend = if doUseCpp(): "cpp" else: "c" + # execFold("build with -d:nimHasLibFFI", "nim $1 -d:release -d:nimHasLibFFI -o:$2 compiler/nim.nim" % [backend, nimFFI]) + # execFold("test with -d:nimHasLibFFI", "$1 $2 -r testament/testament --nim:$1 r tests/trunner.nim" % [nimFFI, backend]) + + # execFold("Run nimdoc tests", "nim c -r nimdoc/tester") + # execFold("Run nimpretty tests", "nim c -r nimpretty/tester.nim") + # when defined(posix): + # execFold("Run nimsuggest tests", "nim c -r nimsuggest/tester") proc pushCsources() = if not dirExists("../csources/.git"): diff --git a/tests/stdlib/tfdleak.nim b/tests/stdlib/tfdleak.nim index 08ef06da3d77f..f7cae2be89299 100644 --- a/tests/stdlib/tfdleak.nim +++ b/tests/stdlib/tfdleak.nim @@ -9,13 +9,16 @@ when defined(windows): import winlean else: import posix +from stdtest/specialpaths import buildDir proc leakCheck(f: int | FileHandle | SocketHandle, msg: string, expectLeak = defined(nimInheritHandles)) = - discard startProcess( + let p = startProcess( getAppFilename(), args = @[$f.int, msg, $expectLeak], options = {poParentStreams} - ).waitForExit -1 + ) + doAssert p.waitForExit == 0 + close p proc isValidHandle(f: int): bool = ## Check if a handle is valid. Requires OS-native handles. @@ -28,12 +31,12 @@ proc isValidHandle(f: int): bool = proc main() = if paramCount() == 0: # Parent process - let f = system.open("__test_fdleak", fmReadWrite) + let f = system.open(buildDir / "__test_fdleak", fmReadWrite) defer: close f leakCheck(f.getOsFileHandle, "system.open()") - doAssert f.reopen("__test_fdleak2", fmReadWrite), "reopen failed" + doAssert f.reopen(buildDir / "__test_fdleak2", fmReadWrite), "reopen failed" leakCheck(f.getOsFileHandle, "reopen") @@ -67,7 +70,7 @@ proc main() = let selector = newSelector[int]() leakCheck(selector.getFd, "selector()", false) - var mf = memfiles.open("__test_fdleak3", fmReadWrite, newFileSize = 1) + var mf = memfiles.open(buildDir / "__test_fdleak3", fmReadWrite, newFileSize = 1) defer: close mf when defined(windows): leakCheck(mf.fHandle, "memfiles.open().fHandle", false) @@ -80,6 +83,7 @@ proc main() = expectLeak = parseBool(paramStr 3) msg = (if expectLeak: "not " else: "") & "leaked " & paramStr 2 if expectLeak xor fd.isValidHandle: - echo msg + echo (msg, expectLeak, fd.isValidHandle, fd) + # echo msg when isMainModule: main() diff --git a/tests/trunner.nim b/tests/trunner.nim index bd74a8405e602..0ed1f256a1ef2 100644 --- a/tests/trunner.nim +++ b/tests/trunner.nim @@ -59,72 +59,82 @@ ret=[s1:foobar s2:foobar age:25 pi:3.14] doAssert exitCode == 0 else: # don't run twice the same test - import std/[strutils] - template check2(msg) = doAssert msg in output, output - - block: # mstatic_assert - let (output, exitCode) = runCmd("ccgbugs/mstatic_assert.nim", "-d:caseBad") - check2 "sizeof(bool) == 2" - doAssert exitCode != 0 - - block: # ABI checks - let file = "misc/msizeof5.nim" - block: - let (output, exitCode) = runCmd(file, "-d:checkAbi") - doAssert exitCode == 0, output - block: - let (output, exitCode) = runCmd(file, "-d:checkAbi -d:caseBad") - # on platforms that support _StaticAssert natively, errors will show full context, eg: - # error: static_assert failed due to requirement 'sizeof(unsigned char) == 8' - # "backend & Nim disagree on size for: BadImportcType{int64} [declared in mabi_check.nim(1, 6)]" - check2 "sizeof(unsigned char) == 8" - check2 "sizeof(struct Foo2) == 1" - check2 "sizeof(Foo5) == 16" - check2 "sizeof(Foo5) == 3" - check2 "sizeof(struct Foo6) == " - doAssert exitCode != 0 - - import streams - block: # stdin input - let nimcmd = fmt"{nim} r --hints:off - -firstparam '-second param'" - let inputcmd = "import os; echo commandLineParams()" - let expected = """@["-firstparam", "-second param"]""" - block: - let p = startProcess(nimcmd, options = {poEvalCommand}) - p.inputStream.write("import os; echo commandLineParams()") - p.inputStream.close - var output = p.outputStream.readAll - let error = p.errorStream.readAll - doAssert p.waitForExit == 0 - doAssert error.len == 0, $error - output.stripLineEnd - doAssert output == expected - p.errorStream.close - p.outputStream.close - - block: - when defined(posix): - let cmd = fmt"echo 'import os; echo commandLineParams()' | {nimcmd}" - var (output, exitCode) = execCmdEx(cmd) - output.stripLineEnd - doAssert output == expected - - block: # nim doc --backend:$backend --doccmd:$cmd - # test for https://github.com/nim-lang/Nim/issues/13129 - # test for https://github.com/nim-lang/Nim/issues/13891 - let file = testsDir / "nimdoc/m13129.nim" - for backend in fmt"{mode} js".split: - let cmd = fmt"{nim} doc -b:{backend} --nimcache:{nimcache} -d:m13129Foo1 --doccmd:'-d:m13129Foo2 --hints:off' --usenimcache --hints:off {file}" - check execCmdEx(cmd) == (&"ok1:{backend}\nok2: backend: {backend}\n", 0) - # checks that --usenimcache works with `nim doc` - check fileExists(nimcache / "m13129.html") - - block: # mak sure --backend works with `nim r` - let cmd = fmt"{nim} r --backend:{mode} --hints:off --nimcache:{nimcache} {file}" - check execCmdEx(cmd) == ("ok3\n", 0) - - block: # some importc tests - # issue #14314 - let file = testsDir / "misc/mimportc.nim" - let cmd = fmt"{nim} r -b:cpp --hints:off --nimcache:{nimcache} --warningAsError:ProveInit {file}" - check execCmdEx(cmd) == ("witness\n", 0) + # import std/[strutils] + # template check2(msg) = doAssert msg in output, output + + # block: # mstatic_assert + # let (output, exitCode) = runCmd("ccgbugs/mstatic_assert.nim", "-d:caseBad") + # check2 "sizeof(bool) == 2" + # doAssert exitCode != 0 + + # block: # ABI checks + # let file = "misc/msizeof5.nim" + # block: + # let (output, exitCode) = runCmd(file, "-d:checkAbi") + # doAssert exitCode == 0, output + # block: + # let (output, exitCode) = runCmd(file, "-d:checkAbi -d:caseBad") + # # on platforms that support _StaticAssert natively, errors will show full context, eg: + # # error: static_assert failed due to requirement 'sizeof(unsigned char) == 8' + # # "backend & Nim disagree on size for: BadImportcType{int64} [declared in mabi_check.nim(1, 6)]" + # check2 "sizeof(unsigned char) == 8" + # check2 "sizeof(struct Foo2) == 1" + # check2 "sizeof(Foo5) == 16" + # check2 "sizeof(Foo5) == 3" + # check2 "sizeof(struct Foo6) == " + # doAssert exitCode != 0 + + # import streams + # block: # stdin input + # let nimcmd = fmt"{nim} r --hints:off - -firstparam '-second param'" + # let inputcmd = "import os; echo commandLineParams()" + # let expected = """@["-firstparam", "-second param"]""" + # block: + # let p = startProcess(nimcmd, options = {poEvalCommand}) + # p.inputStream.write("import os; echo commandLineParams()") + # p.inputStream.close + # var output = p.outputStream.readAll + # let error = p.errorStream.readAll + # doAssert p.waitForExit == 0 + # doAssert error.len == 0, $error + # output.stripLineEnd + # doAssert output == expected + # p.errorStream.close + # p.outputStream.close + + # block: + # when defined(posix): + # let cmd = fmt"echo 'import os; echo commandLineParams()' | {nimcmd}" + # var (output, exitCode) = execCmdEx(cmd) + # output.stripLineEnd + # doAssert output == expected + + # block: # nim doc --backend:$backend --doccmd:$cmd + # # test for https://github.com/nim-lang/Nim/issues/13129 + # # test for https://github.com/nim-lang/Nim/issues/13891 + # let file = testsDir / "nimdoc/m13129.nim" + # for backend in fmt"{mode} js".split: + # let cmd = fmt"{nim} doc -b:{backend} --nimcache:{nimcache} -d:m13129Foo1 --doccmd:'-d:m13129Foo2 --hints:off' --usenimcache --hints:off {file}" + # check execCmdEx(cmd) == (&"ok1:{backend}\nok2: backend: {backend}\n", 0) + # # checks that --usenimcache works with `nim doc` + # check fileExists(nimcache / "m13129.html") + + # block: # mak sure --backend works with `nim r` + # let cmd = fmt"{nim} r --backend:{mode} --hints:off --nimcache:{nimcache} {file}" + # check execCmdEx(cmd) == ("ok3\n", 0) + + # block: # some importc tests + # # issue #14314 + # let file = testsDir / "misc/mimportc.nim" + # let cmd = fmt"{nim} r -b:cpp --hints:off --nimcache:{nimcache} --warningAsError:ProveInit {file}" + # check execCmdEx(cmd) == ("witness\n", 0) + + block: # PRTEMP + # D20200513T213820 + let file = testsDir / "stdlib/tfdleak.nim" + let cmd = fmt"{nim} r --hints:off --nimcache:{nimcache} {file}" + echo cmd + doAssert false # PRTEMP + for i in 0..<1000 + let ret = execCmdEx(cmd) + echo ret