Skip to content

Commit

Permalink
workaround for openbsd to unblock ctffi testing
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheecour committed May 6, 2020
1 parent eca114e commit 87b2e48
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
24 changes: 19 additions & 5 deletions tests/trunner.nim
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,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.

import std/[strformat,os,osproc,strutils]
import std/[strformat,os,osproc]

const nim = getCurrentCompilerExe()

Expand All @@ -25,22 +25,36 @@ proc runCmd(file, options = ""): auto =

when defined(nimHasLibFFIEnabled):
block: # mevalffi
let (output, exitCode) = runCmd("vm/mevalffi.nim", "--experimental:compiletimeFFI")
let expected = """
when defined(openbsd):
#[
openbsd defines `#define stderr (&__sF[2])` which makes it cumbersome
for dlopen'ing inside `importcSymbol`. Instead of adding special rules
inside `importcSymbol` to handle this, we disable just the part that's
not working and will provide a more general, clean fix in future PR.
]#
var opt = "-d:nimEvalffiStderrWorkaround"
let prefix = ""
else:
var opt = ""
let prefix = """
hello world stderr
hi stderr
foo
"""
let (output, exitCode) = runCmd("vm/mevalffi.nim", fmt"{opt} --experimental:compiletimeFFI")
let expected = fmt"""
{prefix}foo
foo:100
foo:101
foo:102:103
foo:102:103:104
foo:0.03:asdf:103:105
ret={s1:foobar s2:foobar age:25 pi:3.14}
ret=[s1:foobar s2:foobar age:25 pi:3.14]
"""
doAssert output == expected, output
doAssert exitCode == 0

else: # don't run twice the same test
import std/[strutils]
template check(msg) = doAssert msg in output, output

block: # mstatic_assert
Expand Down
17 changes: 9 additions & 8 deletions tests/vm/mevalffi.nim
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ proc fun() =
let num = c_snprintf(buffer2, n, "s1:%s s2:%s age:%d pi:%g", s, s, age, 3.14)
let numExp = 34
doAssert num == numExp
c_printf("ret={%s}\n", buffer2)
c_printf("ret=[%s]\n", buffer2)
c_free(buffer2)

block: # c_printf bug
Expand All @@ -61,10 +61,11 @@ static:
fun()
fun()

import system/ansi_c
block:
proc fun2()=
c_fprintf(cstderr, "hello world stderr\n")
write(stderr, "hi stderr\n")
static: fun2()
fun2()
when not defined nimEvalffiStderrWorkaround:
import system/ansi_c
block:
proc fun2()=
c_fprintf(cstderr, "hello world stderr\n")
write(stderr, "hi stderr\n")
static: fun2()
fun2()

0 comments on commit 87b2e48

Please sign in to comment.