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
parent 27741d6a5c
commit e909486e5c
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)
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
g.recordStmt = recordStmt
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)
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("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 nimpretty tests", "nim c -r nimpretty/tester.nim")

View File

@@ -733,7 +733,7 @@ when declared(stdout):
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:
# BUGFIX: stdin and stdout should be binary files!
proc c_setmode(handle, mode: cint) {.

View File

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

View File

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

View File

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

View File

@@ -4,7 +4,6 @@ fixed would not trigger in that case.
]#
import std/compilesettings
import std/unittest
static:
## 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
block:
type Foo6{.importc, completeStruct.} = object
type Foo6{.importc:"struct Foo6", completeStruct.} = object
a1: cint
# a2: bool # missing this should trigger assert fail
a3: cfloat

View File

@@ -71,7 +71,7 @@ else:
import osproc, os, strutils
from stdtest/specialpaths import buildDir
import "../.." / compiler/unittest_light
import stdtest/unittest_light
block: # fix #9951
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`
## 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]
@@ -15,7 +16,7 @@ const mode =
elif defined(cpp): "cpp"
else: static: doAssert false
const testsDir = currentSourcePath().parentDir
const testsDir = currentSourcePath.parentDir.parentDir
const buildDir = testsDir.parentDir / "build"
const nimcache = buildDir / "nimcacheTrunner"
# `querySetting(nimcacheDir)` would also be possible, but we thus
@@ -28,7 +29,7 @@ proc runCmd(file, options = ""): auto =
result = execCmdEx(cmd)
when false: echo result[0] & "\n" & result[1] # for debugging
when defined(nimHasLibFFIEnabled):
when defined(nimTrunnerFfi):
block: # mevalffi
when defined(openbsd):
#[
@@ -65,7 +66,7 @@ else: # don't run twice the same test
block: # mstatic_assert
let (output, exitCode) = runCmd("ccgbugs/mstatic_assert.nim", "-d:caseBad")
check2 "sizeof(bool) == 2"
doAssert exitCode != 0
check exitCode != 0
block: # ABI checks
let file = "misc/msizeof5.nim"
@@ -82,12 +83,11 @@ else: # don't run twice the same test
check2 "sizeof(Foo5) == 16"
check2 "sizeof(Foo5) == 3"
check2 "sizeof(struct Foo6) == "
doAssert exitCode != 0
check exitCode != 0
import streams
block: # stdin input
let nimcmd = fmt"{nim} r --hints:off - -firstparam '-second param'"
let inputcmd = "import os; echo commandLineParams()"
let nimcmd = fmt"""{nim} r --hints:off - -firstparam "-second param" """
let expected = """@["-firstparam", "-second param"]"""
block:
let p = startProcess(nimcmd, options = {poEvalCommand})
@@ -98,23 +98,27 @@ else: # don't run twice the same test
doAssert p.waitForExit == 0
doAssert error.len == 0, $error
output.stripLineEnd
doAssert output == expected
check output == expected
p.errorStream.close
p.outputStream.close
block:
when defined(posix):
let cmd = fmt"echo 'import os; echo commandLineParams()' | {nimcmd}"
when defined posix:
# 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)
output.stripLineEnd
doAssert output == expected
check output == expected
doAssert exitCode == 0
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}"
# 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)
# checks that --usenimcache works with `nim doc`
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``
**Note:** Tests are only compiled by default. In order to get the tester to
execute the compiled binary, you need to specify a spec with an ``action`` key
(see below for details).
**Note:** Testament is only aware of tests under a directory (eg `tests/foo/`) and will ignore
top-level tests like `tests/tbar.nim`.
# Specs
@@ -16,7 +15,7 @@ Each test can contain a spec in a ``discard """ ... """`` block.
Specifies what action this test should take.
**Default: compile**
**Default: run**
Options:
@@ -50,10 +49,8 @@ discard """
# Categories
Each folder under this directory represents a test category, which can be
tested by running `koch tests cat <category>`.
The folder ``rodfiles`` contains special tests that test incremental
compilation via symbol files.
tested by running `koch tests pcat <category>` (or `cat` to avoid parallel
testing, which is slower).
The folder ``dll`` contains simple DLL tests.

View File

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

View File

@@ -1,5 +1,5 @@
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) =
const nim = getCurrentCompilerExe()