Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

D20200513T213820 #193

Draft
wants to merge 5 commits into
base: devel
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 33 additions & 32 deletions koch.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down
16 changes: 10 additions & 6 deletions tests/stdlib/tfdleak.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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")

Expand Down Expand Up @@ -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)
Expand All @@ -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()
148 changes: 79 additions & 69 deletions tests/trunner.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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