summary refs log tree commit diff stats
path: root/tests/dll
diff options
context:
space:
mode:
Diffstat (limited to 'tests/dll')
-rw-r--r--tests/dll/client.nim8
-rw-r--r--tests/dll/nimhcr_0_3.nim1
-rw-r--r--tests/dll/nimhcr_2_1.nim17
-rw-r--r--tests/dll/nimhcr_basic.nim8
-rw-r--r--tests/dll/nimhcr_integration.nim22
-rw-r--r--tests/dll/nimhcr_unit.nim8
-rw-r--r--tests/dll/server.nim1
-rw-r--r--tests/dll/visibility.nim43
8 files changed, 100 insertions, 8 deletions
diff --git a/tests/dll/client.nim b/tests/dll/client.nim
index 150af3a17..62697569f 100644
--- a/tests/dll/client.nim
+++ b/tests/dll/client.nim
@@ -1,5 +1,4 @@
 discard """
-  output: "Done"
   cmd: "nim $target --debuginfo --hints:on --define:useNimRtl $options $file"
 """
 
@@ -37,5 +36,8 @@ proc eval(n: PNode): int =
 for i in 0..100_000:
   discard eval(buildTree(2))
 
-echo "Done"
-
+# bug https://forum.nim-lang.org/t/8176; Error: ambiguous identifier: 'nimrtl'
+import std/strutils
+doAssert join(@[1, 2]) == "12"
+doAssert join(@[1.5, 2.5]) == "1.52.5"
+doAssert join(@["a", "bc"]) == "abc"
diff --git a/tests/dll/nimhcr_0_3.nim b/tests/dll/nimhcr_0_3.nim
index 56f66e08c..183424e11 100644
--- a/tests/dll/nimhcr_0_3.nim
+++ b/tests/dll/nimhcr_0_3.nim
@@ -14,5 +14,6 @@ let c = makeCounter()
 afterCodeReload:
   echo "   0: after - closure iterator: ", c()
   echo "   0: after - closure iterator: ", c()
+  echo "   0: after - c_2 = ", c_2
 
 proc getInt*(): int = return g_1 + g_2.len
diff --git a/tests/dll/nimhcr_2_1.nim b/tests/dll/nimhcr_2_1.nim
index a13b4c681..705ed6d5a 100644
--- a/tests/dll/nimhcr_2_1.nim
+++ b/tests/dll/nimhcr_2_1.nim
@@ -7,9 +7,26 @@ type
 
 let g_2* = @[Type2(data: 2), Type2(data: 3)][1..^1] # should have a length of 1
 
+const c_2* = [1, 2, 3] # testing that a complext const object is properly exported
+
 var a: tuple[str: string, i: int]
 a.str = "   2: random string"
 echo a.str
 
 beforeCodeReload:
   echo "   2: before!"
+
+# testing a construct of 2 functions in the same module which reference each other
+# https://github.com/nim-lang/Nim/issues/11608
+proc rec_1(depth: int)
+proc rec_2(depth: int) =
+  rec_1(depth + 1)
+proc rec_1(depth: int) =
+  if depth < 3:
+    rec_2(depth)
+  else:
+    echo("max mutual recursion reached!")
+
+# https://github.com/nim-lang/Nim/issues/11996
+let rec_2_func_ref = rec_2
+rec_2_func_ref(0)
diff --git a/tests/dll/nimhcr_basic.nim b/tests/dll/nimhcr_basic.nim
new file mode 100644
index 000000000..2e1f39ae0
--- /dev/null
+++ b/tests/dll/nimhcr_basic.nim
@@ -0,0 +1,8 @@
+discard """
+  output: '''
+Hello world
+'''
+"""
+# for now orc only tests successful compilation
+
+echo "Hello world"
diff --git a/tests/dll/nimhcr_integration.nim b/tests/dll/nimhcr_integration.nim
index 40ba90f72..ac34f1f85 100644
--- a/tests/dll/nimhcr_integration.nim
+++ b/tests/dll/nimhcr_integration.nim
@@ -1,5 +1,6 @@
 discard """
-output: '''
+  disabled: "true"
+  output: '''
 main: HELLO!
 main: hasAnyModuleChanged? true
 main: before
@@ -29,10 +30,12 @@ main: hasAnyModuleChanged? true
    0: before - improved!
 main: before
    2: random string
+max mutual recursion reached!
 1
 bar
    0: after - closure iterator: 0
    0: after - closure iterator: 1
+   0: after - c_2 = [1, 2, 3]
 main: after
               The answer is: 9
 main: hasAnyModuleChanged? true
@@ -51,6 +54,20 @@ done
 '''
 """
 
+#[
+xxx disabled: "openbsd" because it would otherwise give:
+/home/build/Nim/lib/nimhcr.nim(532) hcrInit
+/home/build/Nim/lib/nimhcr.nim(503) initModules
+/home/build/Nim/lib/nimhcr.nim(463) initPointerData
+/home/build/Nim/lib/nimhcr.nim(346) hcrRegisterProc
+/home/build/Nim/lib/pure/reservedmem.nim(223) setLen
+/home/build/Nim/lib/pure/reservedmem.nim(97) setLen
+/home/build/Nim/lib/pure/includes/oserr.nim(94) raiseOSError
+Error: unhandled exception: Not supported [OSError]
+
+After instrumenting code, the stacktrace actually points to the call to `check mprotect`
+]#
+
 ## This is perhaps the most complex test in the nim test suite - calling the
 ## compiler on the file itself with the same set or arguments and reloading
 ## parts of the program at runtime! In the same folder there are a few modules
@@ -95,6 +112,7 @@ proc compileReloadExecute() =
   #   binary triggers rebuilding itself here it shouldn't rebuild the main module -
   #   that would lead to replacing the main binary executable which is running!
   let cmd = commandLineParams()[0..^1].join(" ").replace(" --forceBuild")
+  doAssert cmd.len > 0
   let (stdout, exitcode) = execCmdEx(cmd)
   if exitcode != 0:
     echo "COMPILATION ERROR!"
@@ -149,4 +167,4 @@ update 0
 update 1
 update 2
 
-echo "done"
+echo "done"
\ No newline at end of file
diff --git a/tests/dll/nimhcr_unit.nim b/tests/dll/nimhcr_unit.nim
index f539a53c8..249f3f9f1 100644
--- a/tests/dll/nimhcr_unit.nim
+++ b/tests/dll/nimhcr_unit.nim
@@ -1,4 +1,6 @@
 discard """
+disabled: "openbsd"
+disabled: "netbsd"
 output: '''
 fastcall_proc implementation #1 10
 11
@@ -104,14 +106,14 @@ macro carryOutTests(callingConv: untyped): untyped =
       echo `procName`, " implementation #1 ", x
       return x + 1
 
-    let fp1 = cast[F](hcrRegisterProc("dummy_module", `procName`, `p1`))
+    let fp1 = cast[F](hcrRegisterProc("dummy_module", `procName`, cast[pointer](`p1`)))
     echo fp1(10)
 
     proc `p2`(x: int): int {.placeholder.} =
       echo `procName`, " implementation #2 ", x
       return x + 2
 
-    let fp2 = cast[F](hcrRegisterProc("dummy_module", `procName`, `p2`))
+    let fp2 = cast[F](hcrRegisterProc("dummy_module", `procName`, cast[pointer](`p2`)))
     echo fp1(20)
     echo fp2(20)
 
@@ -119,7 +121,7 @@ macro carryOutTests(callingConv: untyped): untyped =
       echo `procName`, " implementation #3 ", x
       return x + 3
 
-    let fp3 = cast[F](hcrRegisterProc("dummy_module", `procName`, `p3`))
+    let fp3 = cast[F](hcrRegisterProc("dummy_module", `procName`, cast[pointer](`p3`)))
     echo fp1(30)
     echo fp2(30)
     echo fp3(30)
diff --git a/tests/dll/server.nim b/tests/dll/server.nim
index 2b7791d4b..dd4606298 100644
--- a/tests/dll/server.nim
+++ b/tests/dll/server.nim
@@ -1,6 +1,7 @@
 discard """
 action: compile
   cmd: "nim $target --debuginfo --hints:on --define:useNimRtl --app:lib $options $file"
+batchable: false
 """
 
 type
diff --git a/tests/dll/visibility.nim b/tests/dll/visibility.nim
new file mode 100644
index 000000000..ec15dad29
--- /dev/null
+++ b/tests/dll/visibility.nim
@@ -0,0 +1,43 @@
+discard """
+  output: ""
+"""
+
+const LibName {.used.} =
+  when defined(windows):
+    "visibility.dll"
+  elif defined(macosx):
+    "libvisibility.dylib"
+  else:
+    "libvisibility.so"
+
+when compileOption("app", "lib"):
+  var
+    bar {.exportc.}: int
+    thr {.exportc, threadvar.}: int
+  proc foo() {.exportc.} = discard
+
+  var
+    exported {.exportc, dynlib.}: int
+    exported_thr {.exportc, threadvar, dynlib.}: int
+  proc exported_func() {.exportc, dynlib.} = discard
+elif isMainModule:
+  import dynlib
+
+  let handle = loadLib(LibName)
+
+  template check(sym: untyped) =
+    const s = astToStr(sym)
+    if handle.symAddr(s) != nil:
+      echo s, " is exported"
+  template checkE(sym: untyped) =
+    const s = astToStr(sym)
+    if handle.symAddr(s) == nil:
+      echo s, " is not exported"
+
+  check foo
+  check bar
+  check thr
+
+  checkE exported
+  checkE exported_thr
+  checkE exported_func