summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/assert/tuserassert.nim2
-rw-r--r--tests/async/tasyncexceptions.nim40
-rw-r--r--tests/async/tasynciossl.nim3
-rw-r--r--tests/ccgbugs/tmissinginit.nim30
-rw-r--r--tests/closure/tforum.nim44
-rw-r--r--tests/controlflow/tbreak.nim44
-rw-r--r--tests/converter/tconvert.nim34
-rw-r--r--tests/destructor/tdestructor.nim6
-rw-r--r--tests/destructor/tdestructor2.nim2
-rw-r--r--tests/effects/teffects1.nim2
-rw-r--r--tests/effects/tgcsafe.nim16
-rw-r--r--tests/enum/tenumitems.nim2
-rw-r--r--tests/init/tuninit1.nim2
-rw-r--r--tests/misc/tissue710.nim10
-rw-r--r--tests/misc/tstrange.nim9
-rw-r--r--tests/misc/tunsignedcmp.nim15
-rw-r--r--tests/misc/tvarious1.nim9
-rw-r--r--tests/objvariant/tcheckedfield1.nim2
-rw-r--r--tests/overload/toverl4.nim77
-rw-r--r--tests/parallel/tdeepcopy.nim18
-rw-r--r--tests/range/tmatrix3.nim4
-rw-r--r--tests/stdlib/testequivalence.nim1
-rw-r--r--tests/system/toString.nim8
-rw-r--r--tests/table/ptables.nim9
-rw-r--r--tests/testament/specs.nim2
-rw-r--r--tests/threads/tthreadanalysis.nim4
-rw-r--r--tests/threads/tthreadheapviolation1.nim4
-rw-r--r--tests/vm/twrongarray.nim17
-rw-r--r--tests/vm/twrongconst.nim2
29 files changed, 361 insertions, 57 deletions
diff --git a/tests/assert/tuserassert.nim b/tests/assert/tuserassert.nim
index 8710ee486..57b229ca9 100644
--- a/tests/assert/tuserassert.nim
+++ b/tests/assert/tuserassert.nim
@@ -3,7 +3,7 @@ discard """
 """
 
 template myAssert(cond: expr) = 
-  when rand(3) < 3:
+  when 3 <= 3:
     let c = cond.astToStr
     if not cond:
       echo c, "ugh"
diff --git a/tests/async/tasyncexceptions.nim b/tests/async/tasyncexceptions.nim
new file mode 100644
index 000000000..ca73c6a3d
--- /dev/null
+++ b/tests/async/tasyncexceptions.nim
@@ -0,0 +1,40 @@
+discard """
+  file: "tasyncexceptions.nim"
+  exitcode: 1
+  outputsub: "Error: unhandled exception: foobar [E_Base]"
+"""
+import asyncdispatch
+
+proc accept(): PFuture[int] {.async.} =
+  await sleepAsync(100)
+  result = 4
+
+proc recvLine(fd: int): PFuture[string] {.async.} =
+  await sleepAsync(100)
+  return "get"
+
+proc processClient(fd: int) {.async.} =
+  # these finish synchronously, we need some async delay to emulate this bug.
+  var line = await recvLine(fd)
+  var foo = line[0]
+  if foo == 'g':
+    raise newException(EBase, "foobar")
+  
+
+proc serve() {.async.} =
+
+  while true:
+    var fut = await accept()
+    await processClient(fut)
+
+when isMainModule:
+  proc main =
+    var fut = serve()
+    fut.callback =
+      proc () =
+        if fut.failed:
+          # This test ensures that this exception crashes the application
+          # as it is not handled.
+          raise fut.error
+    runForever()
+  main()
diff --git a/tests/async/tasynciossl.nim b/tests/async/tasynciossl.nim
index 26c4c587c..6b38fcf7b 100644
--- a/tests/async/tasynciossl.nim
+++ b/tests/async/tasynciossl.nim
@@ -5,7 +5,8 @@ discard """
 """
 import sockets, asyncio, strutils, times
 
-var disp = newDispatcher()
+var disp {.threadvar.}: PDispatcher
+disp = newDispatcher()
 var msgCount = 0
 
 when defined(ssl):
diff --git a/tests/ccgbugs/tmissinginit.nim b/tests/ccgbugs/tmissinginit.nim
new file mode 100644
index 000000000..d440608e6
--- /dev/null
+++ b/tests/ccgbugs/tmissinginit.nim
@@ -0,0 +1,30 @@
+discard """
+  output: '''0
+0
+0
+0
+[[a = nil,
+b = nil]]'''
+"""
+
+# bug #1475
+type
+  Crash = object
+    a: string
+    b: seq[string]
+
+proc initCrash(): Crash = discard
+
+proc test() =
+  var blongname = [initCrash()]
+  echo repr(blongname)
+
+# bug #1434
+proc bug: array[1, int] = discard
+
+echo bug()[0]
+echo bug()[0]
+echo bug()[0]
+echo bug()[0]
+
+when isMainModule: test()
diff --git a/tests/closure/tforum.nim b/tests/closure/tforum.nim
new file mode 100644
index 000000000..4f6a16ff7
--- /dev/null
+++ b/tests/closure/tforum.nim
@@ -0,0 +1,44 @@
+discard """
+  output: '''asdas
+processClient end
+false
+'''
+"""
+
+type
+  PAsyncHttpServer = ref object
+    value: string
+  PFutureBase = ref object
+    callback: proc () {.closure.}
+    value: string
+    failed: bool
+
+proc accept(server: PAsyncHttpServer): PFutureBase =
+  new(result)
+  result.callback = proc () =
+    discard
+  server.value = "hahaha"
+
+proc processClient(): PFutureBase =
+  new(result)
+
+proc serve(server: PAsyncHttpServer): PFutureBase =
+  iterator serveIter(): PFutureBase {.closure.} =
+    echo server.value
+    while true:
+      var acceptAddrFut = server.accept()
+      yield acceptAddrFut
+      var fut = acceptAddrFut.value
+
+      var f = processClient()
+      f.callback =
+        proc () =
+          echo("processClient end")
+          echo(f.failed)
+      yield f
+  var x = serveIter
+  for i in 0 .. 1:
+    result = x()
+    result.callback()
+
+discard serve(PAsyncHttpServer(value: "asdas"))
diff --git a/tests/controlflow/tbreak.nim b/tests/controlflow/tbreak.nim
new file mode 100644
index 000000000..7deab4caf
--- /dev/null
+++ b/tests/controlflow/tbreak.nim
@@ -0,0 +1,44 @@
+discard """
+  output: '''10
+true true
+true false
+false true
+false false'''
+"""
+
+var
+  x = false
+  run = true
+
+while run:
+  run = false
+  block myblock:
+    if true:
+      break
+    echo "leaving myblock"
+  x = true
+doAssert(x)
+
+# bug #1418
+iterator foo: int =
+  for x in 0 .. 9:
+    for y in [10,20,30,40,50,60,70,80,90]:
+      yield x + y
+
+for p in foo():
+  echo p
+  break
+
+iterator permutations: int =
+  yield 10
+
+for p in permutations():
+  break
+
+# regression:
+proc main =
+  for x in [true, false]:
+    for y in [true, false]:
+      echo x, " ", y
+
+main()
diff --git a/tests/converter/tconvert.nim b/tests/converter/tconvert.nim
index a8ddcf119..a37140234 100644
--- a/tests/converter/tconvert.nim
+++ b/tests/converter/tconvert.nim
@@ -1,5 +1,3 @@
-import
-  Cairo
 
 converter FloatConversion64(x: int): float64 = return toFloat(x)
 converter FloatConversion32(x: int): float32 = return toFloat(x)
@@ -7,34 +5,10 @@ converter FloatConversionPlain(x: int): float = return toFloat(x)
 
 const width = 500
 const height = 500
-const outFile = "CairoTest.png"
-
-var surface = Cairo.ImageSurfaceCreate(CAIRO.FORMAT_RGB24, width, height)
-var ç = Cairo.Create(surface)
-
-ç.SetSourceRGB(1, 1, 1)
-ç.Paint()
-
-ç.SetLineWidth(10)
-ç.SetLineCap(CAIRO.LINE_CAP_ROUND)
-
-const count = 12
-var winc = width / count
-var hinc = width / count
-for i in 1 .. count-1:
-  var amount = i / count
-  ç.SetSourceRGB(0, 1 - amount, amount)
-  ç.MoveTo(i * winc, hinc)
-  ç.LineTo(width - i * winc, height - hinc)
-  ç.Stroke()
-
-  ç.SetSourceRGB(1 - amount, 0, amount)
-  ç.MoveTo(winc, i * hinc)
-  ç.LineTo(width - winc, height - i * hinc)
-  ç.Stroke()
-
-echo(surface.WriteToPNG(outFile))
-surface.Destroy()
+
+proc ImageSurfaceCreate(w, h: float) = discard
+
+ImageSurfaceCreate(width, height)
 
 type TFoo = object
 
diff --git a/tests/destructor/tdestructor.nim b/tests/destructor/tdestructor.nim
index e5236aaab..f0ea3c5c6 100644
--- a/tests/destructor/tdestructor.nim
+++ b/tests/destructor/tdestructor.nim
@@ -55,14 +55,14 @@ type
         q: TMyGeneric3[TMyObj, int, int]
       r: string
 
-proc destruct(o: var TMyObj) {.destructor.} =
+proc destroy(o: var TMyObj) {.override.} =
   if o.p != nil: dealloc o.p
   echo "myobj destroyed"
 
-proc destroy(o: var TMyGeneric1) {.destructor.} =
+proc destroy(o: var TMyGeneric1) {.override.} =
   echo "mygeneric1 destroyed"
 
-proc destroy[A, B](o: var TMyGeneric2[A, B]) {.destructor.} =
+proc destroy[A, B](o: var TMyGeneric2[A, B]) {.override.} =
   echo "mygeneric2 destroyed"
 
 proc open: TMyObj =
diff --git a/tests/destructor/tdestructor2.nim b/tests/destructor/tdestructor2.nim
index da9192a3f..a5b62860c 100644
--- a/tests/destructor/tdestructor2.nim
+++ b/tests/destructor/tdestructor2.nim
@@ -8,7 +8,7 @@ type
     x, y: int
     p: pointer
     
-proc destruct(o: var TMyObj) {.destructor.} =
+proc destroy(o: var TMyObj) {.override.} =
   if o.p != nil: dealloc o.p
   
 proc open: TMyObj =
diff --git a/tests/effects/teffects1.nim b/tests/effects/teffects1.nim
index 0014cff46..f73230ff9 100644
--- a/tests/effects/teffects1.nim
+++ b/tests/effects/teffects1.nim
@@ -1,5 +1,5 @@
 discard """
-  line: 1913
+  line: 2136
   file: "system.nim"
   errormsg: "can raise an unlisted exception: ref EIO"
 """
diff --git a/tests/effects/tgcsafe.nim b/tests/effects/tgcsafe.nim
new file mode 100644
index 000000000..87388238a
--- /dev/null
+++ b/tests/effects/tgcsafe.nim
@@ -0,0 +1,16 @@
+discard """
+  line: 15
+  errormsg: "'mainUnsafe' is not GC-safe"
+"""
+
+proc mymap(x: proc ()) =
+  x()
+
+var
+  myglob: string
+
+proc mainSafe() {.gcsafe.} =
+  mymap(proc () = echo "foo")
+
+proc mainUnsafe() {.gcsafe.} =
+  mymap(proc () = myglob = "bar"; echo "foo", myglob)
diff --git a/tests/enum/tenumitems.nim b/tests/enum/tenumitems.nim
index b6eee5ba8..b92cff6bf 100644
--- a/tests/enum/tenumitems.nim
+++ b/tests/enum/tenumitems.nim
@@ -1,6 +1,6 @@
 discard """
   line: 7
-  errormsg: "type mismatch"
+  errormsg: "expression 'items' cannot be called"
 """
 
 type a = enum b,c,d
diff --git a/tests/init/tuninit1.nim b/tests/init/tuninit1.nim
index 2a994b187..57443a7d3 100644
--- a/tests/init/tuninit1.nim
+++ b/tests/init/tuninit1.nim
@@ -1,5 +1,5 @@
 discard """
-  errormsg: "'y' might not have been initialized"
+  msg: "Warning: 'y' might not have been initialized [Uninit]"
   line:34
 """
 
diff --git a/tests/misc/tissue710.nim b/tests/misc/tissue710.nim
new file mode 100644
index 000000000..9e8735eb3
--- /dev/null
+++ b/tests/misc/tissue710.nim
@@ -0,0 +1,10 @@
+discard """
+  file: "tissue710.nim"
+  line: 8
+  errorMsg: "expression '||' cannot be called"
+"""
+var sum = 0
+for x in 3..1000:
+  if (x mod 3 == 0) || (x mod 5 == 0):
+    sum += x
+echo(sum)
diff --git a/tests/misc/tstrange.nim b/tests/misc/tstrange.nim
index 3947755fc..8742011bb 100644
--- a/tests/misc/tstrange.nim
+++ b/tests/misc/tstrange.nim
@@ -1,6 +1,8 @@
 discard """
   file: "tstrange.nim"
-  output: "hallo4"
+  output: '''hallo40
+1
+2'''
 """
 # test for extremely strange bug

 

@@ -19,5 +21,8 @@ gen("hallo")
 write(stdout, ack(5, 4))

 #OUT hallo4

 

-
+# bug #1442
+let h=3
+for x in 0.. <h.int:
+  echo x
 
diff --git a/tests/misc/tunsignedcmp.nim b/tests/misc/tunsignedcmp.nim
new file mode 100644
index 000000000..a66fbaae1
--- /dev/null
+++ b/tests/misc/tunsignedcmp.nim
@@ -0,0 +1,15 @@
+discard """
+  output: '''true
+true
+true'''
+"""
+
+# bug 1420
+import unsigned
+
+var x = 40'u32
+var y = 30'u32
+echo x > y # works
+
+echo((40'i32) > (30'i32))
+echo((40'u32) > (30'u32)) # Error: ordinal type expected
diff --git a/tests/misc/tvarious1.nim b/tests/misc/tvarious1.nim
index 6e4612ae3..1f2da2ae5 100644
--- a/tests/misc/tvarious1.nim
+++ b/tests/misc/tvarious1.nim
@@ -3,7 +3,8 @@ discard """
   output: '''1
 0
 Whopie
-12'''
+12
+1.7'''
 """
 
 echo len([1_000_000]) #OUT 1
@@ -39,3 +40,9 @@ var val12 = TSomeRange(hour: 12)
 
 value = $(if val12.hour > 12: val12.hour - 12 else: val12.hour)
 echo value
+
+# bug #1334
+
+var ys = @[4.1, 5.6, 7.2, 1.7, 9.3, 4.4, 3.2] 
+#var x = int(ys.high / 2) #echo ys[x] # Works 
+echo ys[int(ys.high / 2)] # Doesn't work
diff --git a/tests/objvariant/tcheckedfield1.nim b/tests/objvariant/tcheckedfield1.nim
index 5ade3a13a..1963ceb8d 100644
--- a/tests/objvariant/tcheckedfield1.nim
+++ b/tests/objvariant/tcheckedfield1.nim
@@ -1,5 +1,5 @@
 discard """
-  errormsg: "cannot prove that field 'x.s' is accessible"
+  msg: "Warning: cannot prove that field 'x.s' is accessible [ProveField]"
   line:51
 """
 
diff --git a/tests/overload/toverl4.nim b/tests/overload/toverl4.nim
new file mode 100644
index 000000000..6bb3a53d1
--- /dev/null
+++ b/tests/overload/toverl4.nim
@@ -0,0 +1,77 @@
+discard """
+  output: '''true'''
+"""
+
+#bug #592
+
+type
+  ElementKind = enum inner, leaf
+  TElement[TKey, TData] = object
+    case kind: ElementKind
+    of inner:
+      key: TKey
+      left, right: ref TElement[Tkey, TData]
+    of leaf:
+      data: TData
+  PElement[TKey, TData] = ref TElement[TKey, TData]
+
+proc newElement[Tkey, TData](other: PElement[TKey, TData]): PElement[Tkey, TData] =
+  case other.kind:
+  of inner:
+    PElement[TKey, TData](kind: ElementKind.inner, key: other.key, left: other.left, right: other.right)
+  of leaf:
+    PElement[TKey, TData](kind: ElementKind.leaf, data: other.data)
+
+proc newElement[TKey, TData](key: TKey, left: PElement[TKey, TData] = nil, right: PElement[TKey, TData] = nil) : PElement[TKey, TData] =
+  PElement[TKey, TData](kind: ElementKind.inner, key: key, left: left, right: right)
+
+proc newElement[Tkey, TData](key: Tkey, data: TData) : PElement[Tkey, TData] =
+  PElement[TKey, TData](kind: ElementKind.leaf, data: data)
+
+proc find*[TKey, TData](root: PElement[TKey, TData], key: TKey): TData {.raises: [EInvalidKey].} =
+  if root.left == nil:
+    raise newException(EInvalidKey, "key does not exist: " & key)
+
+  var tmp_element = addr(root)
+
+  while tmp_element.kind == inner and tmp_element.right != nil:
+    tmp_element = if tmp_element.key > key:
+                    addr(tmp_element.left)
+                  else:
+                    addr(tmp_element.right)
+
+  if tmp_element.key == key:
+    return tmp_element.left.data
+  else:
+    raise newException(EInvalidKey, "key does not exist: " & key)
+
+proc add*[TKey, TData](root: var PElement[TKey, TData], key: TKey, data: TData) : bool =
+  if root.left == nil:
+    root.key = key
+    root.left = newElement[TKey, TData](key, data)
+    return true
+
+  var tmp_element = addr(root)
+
+  while tmp_element.kind == ElementKind.inner and tmp_element.right != nil:
+    tmp_element = if tmp_element.key > key:
+                    addr(tmp_element.left)
+                  else:
+                    addr(tmp_element.right)
+
+  if tmp_element.key == key:
+    return false
+
+  var old_element = newElement[TKey, TData](tmp_element[])
+  var new_element = newElement[TKey, TData](key, data)
+
+  tmp_element[] = if tmp_element.key < key:
+                    newElement(key, old_element, new_element)
+                  else:
+                    newElement(tmp_element.key, new_element, old_element)
+
+  return true
+
+var tree = PElement[int, int](kind: ElementKind.inner, key: 0, left: nil, right: nil)
+let result = add(tree, 1, 1)
+echo(result)
\ No newline at end of file
diff --git a/tests/parallel/tdeepcopy.nim b/tests/parallel/tdeepcopy.nim
new file mode 100644
index 000000000..84e2edf3f
--- /dev/null
+++ b/tests/parallel/tdeepcopy.nim
@@ -0,0 +1,18 @@
+discard """
+  output: '''13 abc'''
+"""
+
+type
+  PBinaryTree = ref object
+    le, ri: PBinaryTree
+    value: int
+
+
+proc main =
+  var x: PBinaryTree
+  deepCopy(x, PBinaryTree(ri: PBinaryTree(le: PBinaryTree(value: 13))))
+  var y: string
+  deepCopy y, "abc"
+  echo x.ri.le.value, " ", y
+
+main()
diff --git a/tests/range/tmatrix3.nim b/tests/range/tmatrix3.nim
index 900404524..80d38d63d 100644
--- a/tests/range/tmatrix3.nim
+++ b/tests/range/tmatrix3.nim
@@ -1,6 +1,6 @@
 discard """
-  output: '''0.0000000000000000e+00
-0.0000000000000000e+00
+  output: '''0.0
+0.0
 0
 0
 0
diff --git a/tests/stdlib/testequivalence.nim b/tests/stdlib/testequivalence.nim
index 7c5d9e3e9..7acaad340 100644
--- a/tests/stdlib/testequivalence.nim
+++ b/tests/stdlib/testequivalence.nim
@@ -1,7 +1,6 @@
 discard """
   output: ''''''
 """
-import unittest
 import sets
 
 doAssert(toSet(@[1,2,3]) <= toSet(@[1,2,3,4]), "equivalent or subset")
diff --git a/tests/system/toString.nim b/tests/system/toString.nim
index 17dcb3cb4..52e7a4b92 100644
--- a/tests/system/toString.nim
+++ b/tests/system/toString.nim
@@ -1,11 +1,9 @@
 discard """
   output:'''@[23, 45]
-@[, foo, bar]
-[, foo, bar]
-[23, 45]'''
+@[, foo, bar]'''
 """
 
 echo($(@[23, 45]))
 echo($(@["", "foo", "bar"]))
-echo($(["", "foo", "bar"]))
-echo($([23, 45]))
+#echo($(["", "foo", "bar"]))
+#echo($([23, 45]))
diff --git a/tests/table/ptables.nim b/tests/table/ptables.nim
index ec52d08c3..79a9aab17 100644
--- a/tests/table/ptables.nim
+++ b/tests/table/ptables.nim
@@ -104,6 +104,15 @@ block countTableTest1:
 block SyntaxTest:
   var x = newTable[int, string]({:})
 
+block nilTest:
+  var i, j: PTable[int, int] = nil
+  assert i == j
+  j = newTable[int, int]()
+  assert i != j
+  assert j != i
+  i = newTable[int, int]()
+  assert i == j
+
 proc orderedTableSortTest() =
   var t = newOrderedTable[string, int](2)
   for key, val in items(data): t[key] = val
diff --git a/tests/testament/specs.nim b/tests/testament/specs.nim
index 6e72f4b5e..184f07c51 100644
--- a/tests/testament/specs.nim
+++ b/tests/testament/specs.nim
@@ -53,7 +53,7 @@ const
   targetToExt*: array[TTarget, string] = ["c", "cpp", "m", "js"]
   targetToCmd*: array[TTarget, string] = ["c", "cpp", "objc", "js"]
 
-when not defined(parseCfgBool):
+when not declared(parseCfgBool):
   # candidate for the stdlib:
   proc parseCfgBool(s: string): bool =
     case normalize(s)
diff --git a/tests/threads/tthreadanalysis.nim b/tests/threads/tthreadanalysis.nim
index 383680d81..37369b79c 100644
--- a/tests/threads/tthreadanalysis.nim
+++ b/tests/threads/tthreadanalysis.nim
@@ -1,7 +1,7 @@
 discard """
   outputsub: "101"
-  msg: "Warning: write to foreign heap"
-  line: 37
+  errormsg: "'threadFunc' is not GC-safe"
+  line: 39
   cmd: "nimrod $target --hints:on --threads:on $options $file"
 """
 
diff --git a/tests/threads/tthreadheapviolation1.nim b/tests/threads/tthreadheapviolation1.nim
index f3a36e036..e0629ed08 100644
--- a/tests/threads/tthreadheapviolation1.nim
+++ b/tests/threads/tthreadheapviolation1.nim
@@ -1,6 +1,6 @@
 discard """
-  line: 12
-  errormsg: "write to foreign heap"
+  line: 11
+  errormsg: "'horrible' is not GC-safe"
   cmd: "nimrod $target --hints:on --threads:on $options $file"
 """
 
diff --git a/tests/vm/twrongarray.nim b/tests/vm/twrongarray.nim
new file mode 100644
index 000000000..c1514d0e9
--- /dev/null
+++ b/tests/vm/twrongarray.nim
@@ -0,0 +1,17 @@
+discard """
+  errormsg: "cannot evaluate at compile time: size"
+  line: 16
+"""
+
+#bug #1343
+
+when false:
+  proc one(dummy: int, size: int) =
+    var x: array[size, int] # compile error: constant expression expected
+
+  proc three(size: int) =
+    var x: array[size * 1, int] # compile error: cannot evaluate at compile time: size
+
+proc two(dummy: int, size: int) =
+  var x: array[size * 1, int] # compiles, but shouldn't?
+  #assert(x.len == size) # just for fun
diff --git a/tests/vm/twrongconst.nim b/tests/vm/twrongconst.nim
index 5c0c80f9f..68ab2757c 100644
--- a/tests/vm/twrongconst.nim
+++ b/tests/vm/twrongconst.nim
@@ -4,6 +4,6 @@ discard """
 """
 
 var x: array[100, char]
-template Foo : expr = x[42]
+template foo : expr = x[42]
 
 const myConst = foo