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

@ -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()