summary refs log tree commit diff stats
path: root/tests/pragmas
diff options
context:
space:
mode:
Diffstat (limited to 'tests/pragmas')
-rw-r--r--tests/pragmas/monoff1.nim1
-rw-r--r--tests/pragmas/mqualifiedmacro.nim10
-rw-r--r--tests/pragmas/mused2a.nim23
-rw-r--r--tests/pragmas/mused2b.nim3
-rw-r--r--tests/pragmas/mused2c.nim1
-rw-r--r--tests/pragmas/mused3.nim76
-rw-r--r--tests/pragmas/mused3a.nim41
-rw-r--r--tests/pragmas/mused3b.nim12
-rw-r--r--tests/pragmas/t22713.nim12
-rw-r--r--tests/pragmas/t8741.nim2
-rw-r--r--tests/pragmas/tcompile_missing_file.nim5
-rw-r--r--tests/pragmas/tcustom_pragma.nim36
-rw-r--r--tests/pragmas/tinvalid_user_pragma.nim9
-rw-r--r--tests/pragmas/tinvalidcustompragma.nim23
-rw-r--r--tests/pragmas/tonoff1.nim8
-rw-r--r--tests/pragmas/tonoff2.nim14
-rw-r--r--tests/pragmas/tpragmas_misc.nim5
-rw-r--r--tests/pragmas/tpragmas_reorder.nim19
-rw-r--r--tests/pragmas/tpush.nim129
-rw-r--r--tests/pragmas/tpushnotes.nim13
-rw-r--r--tests/pragmas/tqualifiedmacro.nim14
-rw-r--r--tests/pragmas/tused2.nim46
-rw-r--r--tests/pragmas/tuserpragmaargs.nim5
23 files changed, 303 insertions, 204 deletions
diff --git a/tests/pragmas/monoff1.nim b/tests/pragmas/monoff1.nim
new file mode 100644
index 000000000..85d6c57b3
--- /dev/null
+++ b/tests/pragmas/monoff1.nim
@@ -0,0 +1 @@
+proc on*() = discard
diff --git a/tests/pragmas/mqualifiedmacro.nim b/tests/pragmas/mqualifiedmacro.nim
new file mode 100644
index 000000000..908973206
--- /dev/null
+++ b/tests/pragmas/mqualifiedmacro.nim
@@ -0,0 +1,10 @@
+template t*(x:untyped): untyped = 
+  echo "template t"
+
+import macros
+macro m*(name: static string, x: untyped): untyped =
+  let newName = ident(name)
+  result = quote do:
+    type `newName` = object
+  if result.kind == nnkStmtList:
+    result = result[^1]
diff --git a/tests/pragmas/mused2a.nim b/tests/pragmas/mused2a.nim
deleted file mode 100644
index d9b2bb9bf..000000000
--- a/tests/pragmas/mused2a.nim
+++ /dev/null
@@ -1,23 +0,0 @@
-import std/strutils
-
-from std/os import fileExists
-
-import std/typetraits as typetraits2
-from std/setutils import complement
-
-
-
-
-
-proc fn1() = discard
-proc fn2*() = discard
-
-
-let fn4 = 0
-let fn5* = 0
-
-
-const fn7 = 0
-const fn8* = 0
-
-type T1 = object
diff --git a/tests/pragmas/mused2b.nim b/tests/pragmas/mused2b.nim
deleted file mode 100644
index 39c92b964..000000000
--- a/tests/pragmas/mused2b.nim
+++ /dev/null
@@ -1,3 +0,0 @@
-import mused2c
-export mused2c
-
diff --git a/tests/pragmas/mused2c.nim b/tests/pragmas/mused2c.nim
deleted file mode 100644
index a374e634e..000000000
--- a/tests/pragmas/mused2c.nim
+++ /dev/null
@@ -1 +0,0 @@
-proc baz*() = discard
\ No newline at end of file
diff --git a/tests/pragmas/mused3.nim b/tests/pragmas/mused3.nim
deleted file mode 100644
index 0beec1d44..000000000
--- a/tests/pragmas/mused3.nim
+++ /dev/null
@@ -1,76 +0,0 @@
-#[
-ran from trunner
-]#
-
-
-
-
-
-
-# line 10
-when defined case1:
-  from mused3a import nil
-  from mused3b import nil
-  mused3a.fn1()
-
-when defined case2:
-  from mused3a as m1 import nil
-  m1.fn1()
-
-when defined case3:
-  from mused3a import fn1
-  fn1()
-
-when defined case4:
-  from mused3a as m1 import fn1
-  m1.fn1()
-
-when defined case5:
-  import mused3a as m1
-  fn1()
-
-when defined case6:
-  import mused3a except nonexistent
-  fn1()
-
-when defined case7:
-  import mused3a
-  mused3a.fn1()
-
-when defined case8:
-  # re-export test
-  import mused3a except nonexistent
-  gn1()
-
-when defined case9:
-  # re-export test
-  import mused3a
-  gn1()
-
-when defined case10:
-  #[
-  edge case which happens a lot in compiler code:
-  don't report UnusedImport for mused3b here even though it works without `import mused3b`,
-  because `a.b0.f0` is accessible from both mused3a and mused3b (fields are given implicit access)
-  ]#
-  import mused3a
-  import mused3b
-  var a: Bar
-  discard a.b0.f0
-
-when false:
-  when defined case11:
-    #[
-    xxx minor bug: this should give:
-    Warning: imported and not used: 'm2' [UnusedImport]
-    but doesn't, because currently implementation in `markOwnerModuleAsUsed`
-    only looks at `fn1`, not fully qualified call `m1.fn1()
-    ]#
-    from mused3a as m1 import nil
-    from mused3a as m2 import nil
-    m1.fn1()
-
-when defined case12:
-  import mused3a
-  import mused3a
-  fn1()
diff --git a/tests/pragmas/mused3a.nim b/tests/pragmas/mused3a.nim
deleted file mode 100644
index c33d1ecb3..000000000
--- a/tests/pragmas/mused3a.nim
+++ /dev/null
@@ -1,41 +0,0 @@
-when defined case1:
-  proc fn1*() = discard
-
-when defined case2:
-  proc fn1*() = discard
-
-when defined case3:
-  proc fn1*() = discard
-  proc fn2*() = discard
-
-when defined case4:
-  proc fn1*() = discard
-  proc fn2*() = discard
-
-when defined case5:
-  proc fn1*() = discard
-
-when defined case6:
-  proc fn1*() = discard
-
-when defined case7:
-  proc fn1*() = discard
-
-when defined case8:
-  import mused3b
-  export mused3b
-
-when defined case9:
-  import mused3b
-  export mused3b
-
-when defined case10:
-  import mused3b
-  type Bar* = object
-    b0*: Foo
-
-when defined case11:
-  proc fn1*() = discard
-
-when defined case12:
-  proc fn1*() = discard
diff --git a/tests/pragmas/mused3b.nim b/tests/pragmas/mused3b.nim
deleted file mode 100644
index de288bb08..000000000
--- a/tests/pragmas/mused3b.nim
+++ /dev/null
@@ -1,12 +0,0 @@
-when defined case1:
-  proc gn1*()=discard
-
-when defined case8:
-  proc gn1*()=discard
-
-when defined case9:
-  proc gn1*()=discard
-
-when defined case10:
-  type Foo* = object
-    f0*: int
diff --git a/tests/pragmas/t22713.nim b/tests/pragmas/t22713.nim
new file mode 100644
index 000000000..3d3384632
--- /dev/null
+++ b/tests/pragmas/t22713.nim
@@ -0,0 +1,12 @@
+import std/macros
+
+
+template myPragma(x: int) {.pragma.}
+
+type
+  A = object
+    x: int64
+
+  B {.myPragma(sizeof(A)).} = object
+
+doAssert B.getCustomPragmaVal(myPragma) == 8
\ No newline at end of file
diff --git a/tests/pragmas/t8741.nim b/tests/pragmas/t8741.nim
index 221c732b0..bf97b0e29 100644
--- a/tests/pragmas/t8741.nim
+++ b/tests/pragmas/t8741.nim
@@ -1,7 +1,7 @@
 discard """
   cmd: "nim check --hint:processing:off $file"
   errormsg: "3 is not two"
-  nimout: '''t8741.nim(13, 9) Error: cannot attach a custom pragma to 'a'
+  nimout: '''t8741.nim(13, 9) Error: invalid pragma: foobar
 t8741.nim(29, 15) template/generic instantiation of `onlyTwo` from here
 t8741.nim(25, 12) Error: 3 is not two
 '''
diff --git a/tests/pragmas/tcompile_missing_file.nim b/tests/pragmas/tcompile_missing_file.nim
new file mode 100644
index 000000000..fd90bd57d
--- /dev/null
+++ b/tests/pragmas/tcompile_missing_file.nim
@@ -0,0 +1,5 @@
+discard """
+  joinable: false
+  errormsg: "cannot find: noexist.c"
+"""
+{.compile: "noexist.c".}
diff --git a/tests/pragmas/tcustom_pragma.nim b/tests/pragmas/tcustom_pragma.nim
index ad25cad98..11a6df813 100644
--- a/tests/pragmas/tcustom_pragma.nim
+++ b/tests/pragmas/tcustom_pragma.nim
@@ -399,12 +399,39 @@ block:
 
   discard Hello(a: 1.0, b: 12)
 
-# custom pragma on iterators
+# test routines
+block:
+  template prag {.pragma.}
+  proc hello {.prag.} = discard
+  iterator hello2: int {.prag.} = discard
+  template hello3(x: int): int {.prag.} = x
+  macro hello4(x: int): int {.prag.} = x
+  func hello5(x: int): int {.prag.} = x
+  doAssert hello.hasCustomPragma(prag)
+  doAssert hello2.hasCustomPragma(prag)
+  doAssert hello3.hasCustomPragma(prag)
+  doAssert hello4.hasCustomPragma(prag)
+  doAssert hello5.hasCustomPragma(prag)
+
+# test push doesn't break
 block:
   template prag {.pragma.}
   {.push prag.}
   proc hello = discard
   iterator hello2: int = discard
+  template hello3(x: int): int = x
+  macro hello4(x: int): int = x
+  func hello5(x: int): int = x
+  type
+    Foo = enum a
+    Bar[T] = ref object of RootObj
+      x: T
+      case y: bool
+      of false: discard
+      else:
+        when true: discard
+  for a in [1]: discard a
+  {.pop.}
 
 # issue #11511
 when false:
@@ -504,3 +531,10 @@ block:
 
   check(a)
   check(b)
+
+block: # https://forum.nim-lang.org/t/12522, backticks
+  template `mypragma`() {.pragma.}
+  # Error: invalid pragma: `mypragma`
+  type Test = object
+    field {.`mypragma`.}: int
+  doAssert Test().field.hasCustomPragma(mypragma)
diff --git a/tests/pragmas/tinvalid_user_pragma.nim b/tests/pragmas/tinvalid_user_pragma.nim
new file mode 100644
index 000000000..3081db842
--- /dev/null
+++ b/tests/pragmas/tinvalid_user_pragma.nim
@@ -0,0 +1,9 @@
+discard """
+cmd: "nim check $file"
+"""
+
+{.pragma test: foo.} #[tt.Error
+^ invalid pragma:  {.pragma, test: foo.} ]#
+
+{.pragma: 1.} #[tt.Error
+^ invalid pragma:  {.pragma: 1.} ]#
diff --git a/tests/pragmas/tinvalidcustompragma.nim b/tests/pragmas/tinvalidcustompragma.nim
new file mode 100644
index 000000000..a31695809
--- /dev/null
+++ b/tests/pragmas/tinvalidcustompragma.nim
@@ -0,0 +1,23 @@
+discard """
+  cmd: "nim check $file"
+"""
+
+# issue #21652
+type Foo = object
+template foo() {.tags:[Foo].} = #[tt.Error
+                     ^ invalid pragma: tags: [Foo]]#
+  discard
+
+{.foobar.} #[tt.Error
+  ^ invalid pragma: foobar]#
+type A = enum a {.foobar.} #[tt.Error
+                  ^ invalid pragma: foobar]#
+for b {.foobar.} in [1]: discard #[tt.Error
+        ^ invalid pragma: foobar]#
+template foobar {.pragma.}
+{.foobar.} #[tt.Error
+  ^ cannot attach a custom pragma to 'tinvalidcustompragma'; custom pragmas are not supported for modules]#
+type A = enum a {.foobar.} #[tt.Error
+                  ^ cannot attach a custom pragma to 'a'; custom pragmas are not supported for enum fields]#
+for b {.foobar.} in [1]: discard #[tt.Error
+        ^ cannot attach a custom pragma to 'b'; custom pragmas are not supported for `for` loop variables]#
diff --git a/tests/pragmas/tonoff1.nim b/tests/pragmas/tonoff1.nim
new file mode 100644
index 000000000..20ba7def2
--- /dev/null
+++ b/tests/pragmas/tonoff1.nim
@@ -0,0 +1,8 @@
+# issue #23002
+
+import monoff1
+
+proc test() =
+  {.warning[ProveInit]: on.}
+
+test()
diff --git a/tests/pragmas/tonoff2.nim b/tests/pragmas/tonoff2.nim
new file mode 100644
index 000000000..9dff5ef11
--- /dev/null
+++ b/tests/pragmas/tonoff2.nim
@@ -0,0 +1,14 @@
+discard """
+    action: compile
+"""
+
+# issue #22841
+
+import unittest
+
+proc on() =
+    discard
+
+suite "some suite":
+    test "some test":
+        discard
diff --git a/tests/pragmas/tpragmas_misc.nim b/tests/pragmas/tpragmas_misc.nim
index 6dc2e6b80..adb7e73c3 100644
--- a/tests/pragmas/tpragmas_misc.nim
+++ b/tests/pragmas/tpragmas_misc.nim
@@ -68,3 +68,8 @@ block: # issue #10994
 
   proc a {.bar.} = discard # works
   proc b {.bar, foo.} = discard # doesn't
+
+block: # issue #22525
+  macro catch(x: typed) = x
+  proc thing {.catch.} = discard
+  thing()
diff --git a/tests/pragmas/tpragmas_reorder.nim b/tests/pragmas/tpragmas_reorder.nim
new file mode 100644
index 000000000..c4b1a6b0a
--- /dev/null
+++ b/tests/pragmas/tpragmas_reorder.nim
@@ -0,0 +1,19 @@
+discard """
+  matrix: "--experimental:codeReordering"
+"""
+
+runnableExamples:
+  import strtabs
+  var t = newStringTable()
+  t["name"] = "John"
+  t["city"] = "Monaco"
+  doAssert t.len == 2
+  doAssert t.hasKey "name"
+  doAssert "name" in t
+
+include "system/inclrtl"
+
+{.pragma: rtlFunc, rtl.}
+
+proc hasKey*(): bool {.rtlFunc.} =
+  discard
\ No newline at end of file
diff --git a/tests/pragmas/tpush.nim b/tests/pragmas/tpush.nim
index 5ecfe9704..9c6b85c4e 100644
--- a/tests/pragmas/tpush.nim
+++ b/tests/pragmas/tpush.nim
@@ -1,3 +1,7 @@
+discard """
+  targets: "c js"
+"""
+
 # test the new pragmas
 
 {.push warnings: off, hints: off.}
@@ -13,3 +17,128 @@ proc WarnMe() =
     x: int
   echo(x)
 
+# bug #11852
+proc foo(x: string, y: int, res: int) =
+  {.push checks: off}
+  var a: ptr char = unsafeAddr(x[y])
+  {.pop.}
+  if x.len > y:
+    doAssert ord(a[]) == 51
+  else:
+    doAssert x.len + 48 == res
+
+foo("", 0, 48)
+foo("abc", 40, 51)
+
+# bug #22362
+{.push staticBoundChecks: on.}
+proc main(): void =
+  {.pop.}
+  discard
+  {.push staticBoundChecks: on.}
+
+main()
+
+
+proc timnFoo[T](obj: T) {.noSideEffect.} = discard # BUG
+
+{.push exportc.}
+proc foo1() =
+  var s1 = "bar"
+  timnFoo(s1)
+  var s2 = @[1]
+  timnFoo(s2)
+{.pop.}
+
+
+block: # bug #22913
+  block:
+    type r = object
+
+    template std[T](x: T) =
+      let ttt {.used.} = x
+      result = $ttt
+
+    proc bar[T](x: T): string =
+      std(x)
+
+    {.push exportc: "$1".}
+    proc foo(): r =
+      let s = bar(123)
+    {.pop.}
+
+    discard foo()
+
+  block:
+    type r = object
+    {.push exportc: "$1".}
+    proc foo2(): r =
+      let s = $result
+    {.pop.}
+
+    discard foo2()
+
+block: # bug #23019
+  proc f(x: bool)
+
+  proc a(x: int) =
+    if false: f(true)
+
+  proc f(x: bool) =
+    if false: a(0)
+
+  proc k(r: int|int) {.inline.} =  # seems to require being generic and inline
+    if false: a(0)
+
+
+  # {.push tags: [].}
+  {.push raises: [].}
+
+  {.push warning[ObservableStores]:off.}  # can be any warning, off or on
+  let w = 0
+  k(w)
+  {.pop.}
+  {.pop.}
+
+{.push exportC.}
+
+block:
+  proc foo11() =
+    const factor = [1, 2, 3, 4]
+    doAssert factor[0] == 1
+  proc foo21() =
+    const factor = [1, 2, 3, 4]
+    doAssert factor[0] == 1
+
+  foo11()
+  foo21()
+
+template foo31() =
+  let factor = [1, 2, 3, 4]
+  doAssert factor[0] == 1
+template foo41() =
+  let factor = [1, 2, 3, 4]
+  doAssert factor[0] == 1
+
+foo31()
+foo41()
+
+{.pop.}
+
+import macros
+
+block:
+  {.push deprecated.}
+  template test() = discard
+  test()
+  {.pop.}
+  macro foo(): bool =
+    let ast = getImpl(bindSym"test")
+    var found = false
+    if ast[4].kind == nnkPragma:
+      for x in ast[4]:
+        if x.eqIdent"deprecated":
+          found = true
+          break
+    result = newLit(found)
+  doAssert foo()
diff --git a/tests/pragmas/tpushnotes.nim b/tests/pragmas/tpushnotes.nim
new file mode 100644
index 000000000..27ba0bec4
--- /dev/null
+++ b/tests/pragmas/tpushnotes.nim
@@ -0,0 +1,13 @@
+discard """
+  matrix: "--warningAsError:HoleEnumConv"
+"""
+
+type
+  e = enum
+    a = 0
+    b = 2
+
+var i: int
+{.push warning[HoleEnumConv]:off.}
+discard i.e
+{.pop.}
diff --git a/tests/pragmas/tqualifiedmacro.nim b/tests/pragmas/tqualifiedmacro.nim
new file mode 100644
index 000000000..bc95ec1ea
--- /dev/null
+++ b/tests/pragmas/tqualifiedmacro.nim
@@ -0,0 +1,14 @@
+discard """
+  output: '''
+template t
+'''
+"""
+
+# issue #12696
+
+import mqualifiedmacro
+proc p() {. mqualifiedmacro.t .} = # errors with identifier expected but a.t found
+  echo "proc p"
+
+type Foo {. mqualifiedmacro.m("Bar") .} = object
+doAssert Bar is object
diff --git a/tests/pragmas/tused2.nim b/tests/pragmas/tused2.nim
deleted file mode 100644
index f80c198d8..000000000
--- a/tests/pragmas/tused2.nim
+++ /dev/null
@@ -1,46 +0,0 @@
-discard """
-  matrix: "--hint:all:off --hint:XDeclaredButNotUsed --path:."
-  joinable: false
-  nimoutFull: true
-  nimout: '''
-mused2a.nim(12, 6) Hint: 'fn1' is declared but not used [XDeclaredButNotUsed]
-mused2a.nim(16, 5) Hint: 'fn4' is declared but not used [XDeclaredButNotUsed]
-mused2a.nim(20, 7) Hint: 'fn7' is declared but not used [XDeclaredButNotUsed]
-mused2a.nim(23, 6) Hint: 'T1' is declared but not used [XDeclaredButNotUsed]
-mused2a.nim(1, 11) Warning: imported and not used: 'strutils' [UnusedImport]
-mused2a.nim(3, 9) Warning: imported and not used: 'os' [UnusedImport]
-mused2a.nim(5, 23) Warning: imported and not used: 'typetraits2' [UnusedImport]
-mused2a.nim(6, 9) Warning: imported and not used: 'setutils' [UnusedImport]
-tused2.nim(42, 8) Warning: imported and not used: 'mused2a' [UnusedImport]
-tused2.nim(45, 11) Warning: imported and not used: 'strutils' [UnusedImport]
-'''
-"""
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-# line 40
-
-import mused2a
-import mused2b
-
-import std/strutils
-baz()
diff --git a/tests/pragmas/tuserpragmaargs.nim b/tests/pragmas/tuserpragmaargs.nim
new file mode 100644
index 000000000..791d703ac
--- /dev/null
+++ b/tests/pragmas/tuserpragmaargs.nim
@@ -0,0 +1,5 @@
+var foo {.exportc: "abc".} = 123
+{.pragma: importc2, importc.}
+var bar {.importc2: "abc".}: int #[tt.Error
+                  ^ user pragma cannot have arguments]#
+echo bar