fix some issues with --backend (#14363)

* fix some issues with --backend
* fix https://github.com/timotheecour/Nim/issues/175; improve upon #14306
This commit is contained in:
Timothee Cour 2020-05-16 04:09:18 -07:00 • committed by GitHub
commit c777f2fb60
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 125 additions and 59 deletions

31
tests/misc/mbackend.nim Normal file
View file

@ -0,0 +1,31 @@
#[
We can't merge this test inside a `when defined(cpp)` because some bug that was
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)`
doAssert defined(cpp)
doAssert querySetting(backend) == "cpp"
## checks that `--backend:c` has no side effect (ie, can be overridden by subsequent commands)
doAssert not defined(c)
doAssert not defined(js)
doAssert not defined(js)
type
std_exception {.importcpp: "std::exception", header: "<exception>".} = object
proc what(s: std_exception): cstring {.importcpp: "((char *)#.what())".}
var isThrown = false
try:
## bugfix 2: this used to CT error with: Error: only a 'ref object' can be raised
raise std_exception()
except std_exception as ex:
doAssert ex.what().len > 0
isThrown = true
doAssert isThrown

View file

@ -1,3 +1,5 @@
# issue #13129
when defined(cpp):
{.push header: "<vector>".}
type

View file

@ -123,6 +123,16 @@ else: # don't run twice the same test
let cmd = fmt"{nim} r --backend:{mode} --hints:off --nimcache:{nimcache} {file}"
check execCmdEx(cmd) == ("ok3\n", 0)
block: # further issues with `--backend`
let file = testsDir / "misc/mbackend.nim"
var cmd = fmt"{nim} doc -b:cpp --hints:off --nimcache:{nimcache} {file}"
check execCmdEx(cmd) == ("", 0)
cmd = fmt"{nim} check -b:c -b:cpp --hints:off --nimcache:{nimcache} {file}"
check execCmdEx(cmd) == ("", 0)
# issue https://github.com/timotheecour/Nim/issues/175
cmd = fmt"{nim} c -b:js -b:cpp --hints:off --nimcache:{nimcache} {file}"
check execCmdEx(cmd) == ("", 0)
block: # some importc tests
# issue #14314
let file = testsDir / "misc/mimportc.nim"