trunner was not actually being tested in non-CTFFI mode; minor testament cleanups (#14377)

* use check
* trunner now works with cpp
* cleanup: move compiler/unittest_light => stdtest/unittest_light
* fix tests/readme.md
* remove deadcode references to rodfiles
* fix for windows
This commit is contained in:
Timothee Cour 2020-05-19 00:41:31 -07:00 • committed by GitHub
commit e909486e5c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 30 additions and 34 deletions

View file

@ -916,6 +916,8 @@ proc loadNode*(g: ModuleGraph; module: PSym): PNode =
replay(g, module, result) replay(g, module, result)
proc setupModuleCache*(g: ModuleGraph) = proc setupModuleCache*(g: ModuleGraph) =
## historical note: there used to be a `rodfiles` dir with special tests
## for incremental compilation via symbol files. This was likely replaced by ic.
if g.config.symbolFiles == disabledSf: return if g.config.symbolFiles == disabledSf: return
g.recordStmt = recordStmt g.recordStmt = recordStmt
let dbfile = getNimcacheDir(g.config) / RelativeFile"rodfiles.db" let dbfile = getNimcacheDir(g.config) / RelativeFile"rodfiles.db"

View file

@ -554,7 +554,7 @@ proc runCI(cmd: string) =
# no need to bootstrap with koch boot (would be slower) # no need to bootstrap with koch boot (would be slower)
let backend = if doUseCpp(): "cpp" else: "c" 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("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("test with -d:nimHasLibFFI", "$1 $2 -r testament/testament --nim:$1 r tests/misc/trunner.nim -d:nimTrunnerFfi" % [nimFFI, backend])
execFold("Run nimdoc tests", "nim c -r nimdoc/tester") execFold("Run nimdoc tests", "nim c -r nimdoc/tester")
execFold("Run nimpretty tests", "nim c -r nimpretty/tester.nim") execFold("Run nimpretty tests", "nim c -r nimpretty/tester.nim")

View file

@ -733,7 +733,7 @@ when declared(stdout):
releaseSys echoLock releaseSys echoLock
when defined(windows) and not defined(nimscript): when defined(windows) and not defined(nimscript) and not defined(js):
# work-around C's sucking abstraction: # work-around C's sucking abstraction:
# BUGFIX: stdin and stdout should be binary files! # BUGFIX: stdin and stdout should be binary files!
proc c_setmode(handle, mode: cint) {. proc c_setmode(handle, mode: cint) {.

View file

@ -32,7 +32,6 @@ const
"nimble-packages-1", "nimble-packages-1",
"nimble-packages-2", "nimble-packages-2",
"niminaction", "niminaction",
"rodfiles",
"threads", "threads",
"untestable", "untestable",
"stdlib", "stdlib",
@ -671,10 +670,6 @@ proc processCategory(r: var TResults, cat: Category,
options, testsDir: string, options, testsDir: string,
runJoinableTests: bool) = runJoinableTests: bool) =
case cat.string.normalize case cat.string.normalize
of "rodfiles":
when false:
compileRodFiles(r, cat, options)
runRodFiles(r, cat, options)
of "ic": of "ic":
when false: when false:
icTests(r, testsDir, cat, options) icTests(r, testsDir, cat, options)

View file

@ -1,4 +1,4 @@
import compiler/unittest_light import stdtest/unittest_light
import compiler/asciitables import compiler/asciitables
import strformat import strformat

View file

@ -1,4 +1,4 @@
import compiler/unittest_light import stdtest/unittest_light
proc testAssertEquals() = proc testAssertEquals() =
assertEquals("foo", "foo") assertEquals("foo", "foo")

View file

@ -4,7 +4,6 @@ fixed would not trigger in that case.
]# ]#
import std/compilesettings import std/compilesettings
import std/unittest
static: static:
## bugfix 1: this used to CT error with: Error: unhandled exception: mimportcpp.nim(6, 18) `defined(cpp)` ## bugfix 1: this used to CT error with: Error: unhandled exception: mimportcpp.nim(6, 18) `defined(cpp)`

View file

@ -116,7 +116,7 @@ when defined caseBad:
ensureCgen Foo5 ensureCgen Foo5
block: block:
type Foo6{.importc, completeStruct.} = object type Foo6{.importc:"struct Foo6", completeStruct.} = object
a1: cint a1: cint
# a2: bool # missing this should trigger assert fail # a2: bool # missing this should trigger assert fail
a3: cfloat a3: cfloat

View file

@ -71,7 +71,7 @@ else:
import osproc, os, strutils import osproc, os, strutils
from stdtest/specialpaths import buildDir from stdtest/specialpaths import buildDir
import "../.." / compiler/unittest_light import stdtest/unittest_light
block: # fix #9951 block: # fix #9951
template runTest(parseoptCustom) = template runTest(parseoptCustom) =

View file

@ -5,6 +5,7 @@ discard """
## tests that don't quite fit the mold and are easier to handle via `execCmdEx` ## tests that don't quite fit the mold and are easier to handle via `execCmdEx`
## A few others could be added to here to simplify code. ## A few others could be added to here to simplify code.
## Note: this test is a bit slow but tests a lot of things; please don't disable.
import std/[strformat,os,osproc,unittest] import std/[strformat,os,osproc,unittest]
@ -15,7 +16,7 @@ const mode =
elif defined(cpp): "cpp" elif defined(cpp): "cpp"
else: static: doAssert false else: static: doAssert false
const testsDir = currentSourcePath().parentDir const testsDir = currentSourcePath.parentDir.parentDir
const buildDir = testsDir.parentDir / "build" const buildDir = testsDir.parentDir / "build"
const nimcache = buildDir / "nimcacheTrunner" const nimcache = buildDir / "nimcacheTrunner"
# `querySetting(nimcacheDir)` would also be possible, but we thus # `querySetting(nimcacheDir)` would also be possible, but we thus
@ -28,7 +29,7 @@ proc runCmd(file, options = ""): auto =
result = execCmdEx(cmd) result = execCmdEx(cmd)
when false: echo result[0] & "\n" & result[1] # for debugging when false: echo result[0] & "\n" & result[1] # for debugging
when defined(nimHasLibFFIEnabled): when defined(nimTrunnerFfi):
block: # mevalffi block: # mevalffi
when defined(openbsd): when defined(openbsd):
#[ #[
@ -65,7 +66,7 @@ else: # don't run twice the same test
block: # mstatic_assert block: # mstatic_assert
let (output, exitCode) = runCmd("ccgbugs/mstatic_assert.nim", "-d:caseBad") let (output, exitCode) = runCmd("ccgbugs/mstatic_assert.nim", "-d:caseBad")
check2 "sizeof(bool) == 2" check2 "sizeof(bool) == 2"
doAssert exitCode != 0 check exitCode != 0
block: # ABI checks block: # ABI checks
let file = "misc/msizeof5.nim" let file = "misc/msizeof5.nim"
@ -82,12 +83,11 @@ else: # don't run twice the same test
check2 "sizeof(Foo5) == 16" check2 "sizeof(Foo5) == 16"
check2 "sizeof(Foo5) == 3" check2 "sizeof(Foo5) == 3"
check2 "sizeof(struct Foo6) == " check2 "sizeof(struct Foo6) == "
doAssert exitCode != 0 check exitCode != 0
import streams import streams
block: # stdin input block: # stdin input
let nimcmd = fmt"{nim} r --hints:off - -firstparam '-second param'" let nimcmd = fmt"""{nim} r --hints:off - -firstparam "-second param" """
let inputcmd = "import os; echo commandLineParams()"
let expected = """@["-firstparam", "-second param"]""" let expected = """@["-firstparam", "-second param"]"""
block: block:
let p = startProcess(nimcmd, options = {poEvalCommand}) let p = startProcess(nimcmd, options = {poEvalCommand})
@ -98,23 +98,27 @@ else: # don't run twice the same test
doAssert p.waitForExit == 0 doAssert p.waitForExit == 0
doAssert error.len == 0, $error doAssert error.len == 0, $error
output.stripLineEnd output.stripLineEnd
doAssert output == expected check output == expected
p.errorStream.close p.errorStream.close
p.outputStream.close p.outputStream.close
block: block:
when defined(posix): when defined posix:
let cmd = fmt"echo 'import os; echo commandLineParams()' | {nimcmd}" # xxx on windows, `poEvalCommand` should imply `/cmd`, (which should
# make this work), but currently doesn't
let cmd = fmt"""echo "import os; echo commandLineParams()" | {nimcmd}"""
var (output, exitCode) = execCmdEx(cmd) var (output, exitCode) = execCmdEx(cmd)
output.stripLineEnd output.stripLineEnd
doAssert output == expected check output == expected
doAssert exitCode == 0
block: # nim doc --backend:$backend --doccmd:$cmd 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/13129
# test for https://github.com/nim-lang/Nim/issues/13891 # test for https://github.com/nim-lang/Nim/issues/13891
let file = testsDir / "nimdoc/m13129.nim" let file = testsDir / "nimdoc/m13129.nim"
for backend in fmt"{mode} js".split: 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}" # pending #14343 this fails on windows: --doccmd:"-d:m13129Foo2 --hints:off"
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) check execCmdEx(cmd) == (&"ok1:{backend}\nok2: backend: {backend}\n", 0)
# checks that --usenimcache works with `nim doc` # checks that --usenimcache works with `nim doc`
check fileExists(nimcache / "m13129.html") check fileExists(nimcache / "m13129.html")

View file

@ -2,9 +2,8 @@ This directory contains the test cases.
Each test must have a filename of the form: ``t*.nim`` Each test must have a filename of the form: ``t*.nim``
**Note:** Tests are only compiled by default. In order to get the tester to **Note:** Testament is only aware of tests under a directory (eg `tests/foo/`) and will ignore
execute the compiled binary, you need to specify a spec with an ``action`` key top-level tests like `tests/tbar.nim`.
(see below for details).
# Specs # Specs
@ -16,7 +15,7 @@ Each test can contain a spec in a ``discard """ ... """`` block.
Specifies what action this test should take. Specifies what action this test should take.
**Default: compile** **Default: run**
Options: Options:
@ -50,10 +49,8 @@ discard """
# Categories # Categories
Each folder under this directory represents a test category, which can be Each folder under this directory represents a test category, which can be
tested by running `koch tests cat <category>`. tested by running `koch tests pcat <category>` (or `cat` to avoid parallel
testing, which is slower).
The folder ``rodfiles`` contains special tests that test incremental
compilation via symbol files.
The folder ``dll`` contains simple DLL tests. The folder ``dll`` contains simple DLL tests.

View file

@ -1,7 +1,6 @@
# test the osproc module # test the osproc module
import stdtest/specialpaths import stdtest/[specialpaths, unittest_light]
import "$nim" / compiler/unittest_light
when defined(case_testfile): # compiled test file for child process when defined(case_testfile): # compiled test file for child process
from posix import exitnow from posix import exitnow

View file

@ -1,5 +1,5 @@
import std/[strformat,os,osproc] import std/[strformat,os,osproc]
import "$nim/compiler/unittest_light" # works even if moved by megatest import stdtest/unittest_light
proc main(opt: string, expected: string) = proc main(opt: string, expected: string) =
const nim = getCurrentCompilerExe() const nim = getCurrentCompilerExe()