summary refs log tree commit diff stats
path: root/tests/template
diff options
context:
space:
mode:
Diffstat (limited to 'tests/template')
-rw-r--r--tests/template/t_otemplates.nim2
-rw-r--r--tests/template/template_issues.nim2
-rw-r--r--tests/template/tgensymregression.nim2
-rw-r--r--tests/template/thygienictempl.nim2
-rw-r--r--tests/template/tparams_gensymed.nim40
-rw-r--r--tests/template/ttempl2.nim3
-rw-r--r--tests/template/twrongopensymchoice.nim2
7 files changed, 46 insertions, 7 deletions
diff --git a/tests/template/t_otemplates.nim b/tests/template/t_otemplates.nim
index 6597bd37a..8d2ac38a6 100644
--- a/tests/template/t_otemplates.nim
+++ b/tests/template/t_otemplates.nim
@@ -340,6 +340,6 @@ macro tmpl*(body: untyped): untyped =
 
 
 # Run tests
-when isMainModule:
+when true:
     include otests
     echo "Success"
diff --git a/tests/template/template_issues.nim b/tests/template/template_issues.nim
index 8599b161a..15d6ab2b1 100644
--- a/tests/template/template_issues.nim
+++ b/tests/template/template_issues.nim
@@ -43,7 +43,7 @@ block t2629:
 
   let rst_files = concat(glob_rst(), glob_rst("docs"))
 
-  when isMainModule: echo rst_files
+  when true: echo rst_files
 
 
 block t5417:
diff --git a/tests/template/tgensymregression.nim b/tests/template/tgensymregression.nim
index 4cc64a831..4194e3e88 100644
--- a/tests/template/tgensymregression.nim
+++ b/tests/template/tgensymregression.nim
@@ -15,7 +15,7 @@ template mathPerComponent(op: untyped): untyped =
 mathPerComponent(`***`)
 # bug #5285
 when true:
-  if isMainModule:
+  if true:
     var v1: array[3, float64]
     var v2: array[3, float64]
     echo repr(v1 *** v2)
diff --git a/tests/template/thygienictempl.nim b/tests/template/thygienictempl.nim
index 506f57148..9020c3e28 100644
--- a/tests/template/thygienictempl.nim
+++ b/tests/template/thygienictempl.nim
@@ -18,5 +18,5 @@ template test_in(a, b, c: untyped): bool {.dirty.} =
   var result {.gensym.}: bool = false
   false
 
-when isMainModule:
+when true:
   assert test_in(ret2, "test", str_val)
diff --git a/tests/template/tparams_gensymed.nim b/tests/template/tparams_gensymed.nim
index da86d63dc..91fa26596 100644
--- a/tests/template/tparams_gensymed.nim
+++ b/tests/template/tparams_gensymed.nim
@@ -70,3 +70,43 @@ proc genericProc(x: any) =
 
 concreteProc(7) # This works
 genericProc(7)  # This doesn't compile
+
+import tables
+
+# bug #9476
+proc getTypeInfo*(T: typedesc): pointer =
+  var dummy: T
+  getTypeInfo(dummy)
+
+
+macro implementUnary(op: untyped): untyped =
+  result = newStmtList()
+
+  template defineTable(tableSymbol) =
+    var tableSymbol = initTable[pointer, pointer]()
+  let tableSymbol = genSym(nskVar, "registeredProcs")
+  result.add(getAst(defineTable(tableSymbol)))
+
+  template defineRegisterInstantiation(tableSym, regTemplSym, instSym, op) =
+    template regTemplSym*(T: typedesc) =
+      let ti = getTypeInfo(T)
+
+      proc instSym(xOrig: int): int {.gensym, cdecl.} =
+        let x {.inject.} = xOrig
+        op
+
+      tableSym[ti] = cast[pointer](instSym)
+
+  let regTemplSymbol = ident("registerInstantiation")
+  let instSymbol = ident("instantiation")
+  result.add(getAst(defineRegisterInstantiation(
+    tableSymbol, regTemplSymbol, instSymbol, op
+  )))
+
+  echo result.repr
+
+
+implementUnary(): x*x
+
+registerInstantiation(int)
+registerInstantiation(float)
diff --git a/tests/template/ttempl2.nim b/tests/template/ttempl2.nim
index aaa2f1344..eb67bea0c 100644
--- a/tests/template/ttempl2.nim
+++ b/tests/template/ttempl2.nim
@@ -1,7 +1,7 @@
 discard """
+  errormsg: "undeclared identifier: \'b\'"
   file: "ttempl2.nim"
   line: 18
-  errormsg: "undeclared identifier: \'b\'"
 """
 template declareInScope(x: untyped, t: typeDesc): untyped {.immediate.} =
   var x: t
@@ -16,4 +16,3 @@ a = 42  # works, `a` is known here
 
 declareInNewScope(b, int)
 b = 42  #ERROR_MSG undeclared identifier: 'b'
-
diff --git a/tests/template/twrongopensymchoice.nim b/tests/template/twrongopensymchoice.nim
index 360c92037..7a2bb48d3 100644
--- a/tests/template/twrongopensymchoice.nim
+++ b/tests/template/twrongopensymchoice.nim
@@ -20,5 +20,5 @@ proc main =
   var f = Foo.new()
   echo f.b
 
-when isMainModule:
+when true:
   main()