Skip to content

Commit

Permalink
test case refs #10441
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheecour committed Jan 24, 2019
1 parent ce5e8b9 commit 1ce81f5
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tests/misc/nimcachetest/fun1.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// we include a file that gets modified in the test before the 1st and 2nd compilation
#include "D20190123T230907.h"
6 changes: 6 additions & 0 deletions tests/misc/nimcachetest/fun2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "fun1.h"

int foo(){
int a = MYVAR;
return a;
}
3 changes: 3 additions & 0 deletions tests/misc/nimcachetest/fun2.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include <stdio.h>

int foo();
36 changes: 36 additions & 0 deletions tests/misc/nimcachetest/tmain.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
discard """
disabled: true
"""

# issue #10441

when defined(case_D20190123T230907): # child process
{.compile: ("fun2.c").}
proc foo(): cint {.importc, header:"fun1.h".}
echo foo()
else:
# main process
import os, osproc, strformat, strutils
import compiler/unittest_light
import stdtest/specialpaths

proc main() =
const nim = getCurrentCompilerExe()
const input = currentSourcePath()
const headerGen = buildDir / "D20190123T230907.h"
defer: removeFile headerGen
#[
* the command line doesn't change across 2 subsequent invocations
* we pass --forceBuild:off just to make sure it's not overridden in config file
* the only thing that changes across the 2 `nim` invocations is `headerGen`, included by `fun2.c`
]#
let cmd = fmt"{nim} c --forceBuild:off -r --passC:-I{buildDir.quoteShell} -d:case_D20190123T230907 {input}"
for a in [123, 124]:
writeFile headerGen, fmt"""
#define MYVAR {a}
"""
var (output, exitCode) = execCmdEx(cmd, options = {})
doAssert exitCode == 0
output.stripLineEnd
assertEquals output, $a
main()

0 comments on commit 1ce81f5

Please sign in to comment.