summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2014-03-22 02:52:33 +0100
committerAraq <rumpf_a@web.de>2014-03-22 02:52:33 +0100
commit5aac789e0e183a1a2193bd7615de0b4a29f4708c (patch)
tree6bf8e890cabd98705eabb6d5dfc48b928adc106c /tests
parente53fc91282bc8a5dabc4f12e041fa6ce5400c007 (diff)
parent13d26dc53db455ef07feb315871a7fceee5f7a01 (diff)
downloadNim-5aac789e0e183a1a2193bd7615de0b4a29f4708c.tar.gz
Merge branch 'devel' of https://github.com/Araq/Nimrod into devel
Diffstat (limited to 'tests')
-rw-r--r--tests/array/tarrayplus.nim2
-rw-r--r--tests/async/tasyncawait.nim28
-rw-r--r--tests/bind/tinvalidbindtypedesc.nim (renamed from tests/bind/tbindtypedesc.nim)3
-rw-r--r--tests/effects/teffects1.nim2
-rw-r--r--tests/generics/tbadgenericlambda.nim7
-rw-r--r--tests/generics/tgenericlambda.nim7
-rw-r--r--tests/generics/tlateboundstatic.nim16
-rw-r--r--tests/generics/tmetafield.nim6
-rw-r--r--tests/generics/tsigtypeop.nim9
-rw-r--r--tests/matrix/issue1013.nim23
-rw-r--r--tests/metatype/swizzle.nim79
-rw-r--r--tests/metatype/tstaticparams.nim13
-rw-r--r--tests/metatype/tusertypeclasses.nim5
-rw-r--r--tests/metatype/tusertypeclasses2.nim24
-rw-r--r--tests/metatype/typeclassinference.nim10
-rw-r--r--tests/metatype/udtcmanual.nim2
-rw-r--r--tests/objects/tobjpragma.nim49
-rw-r--r--tests/overload/tissue966.nim2
-rw-r--r--tests/stdlib/tpegs.nim2
-rw-r--r--tests/testament/specs.nim6
-rw-r--r--tests/testament/tester.nim8
-rw-r--r--tests/vm/twrongconst.nim7
-rw-r--r--tests/vm/twrongwhen.nim4
23 files changed, 279 insertions, 35 deletions
diff --git a/tests/array/tarrayplus.nim b/tests/array/tarrayplus.nim
index 8c7452e85..9e08bbb0a 100644
--- a/tests/array/tarrayplus.nim
+++ b/tests/array/tarrayplus.nim
@@ -1,5 +1,5 @@
 discard """
-  msg: "type mismatch: got (array[0..2, float], array[0..1, float])"
+  errmsg: "type mismatch: got (array[0..2, float], array[0..1, float])"
 """
 
 proc `+`*[R, T] (v1, v2: array[R, T]): array[R, T] =
diff --git a/tests/async/tasyncawait.nim b/tests/async/tasyncawait.nim
index fea0783a0..91dfb7932 100644
--- a/tests/async/tasyncawait.nim
+++ b/tests/async/tasyncawait.nim
@@ -14,31 +14,31 @@ const
 
 var clientCount = 0
 
-proc sendMessages(disp: PDispatcher, client: TSocketHandle): PFuture[int] {.async.} =
+proc sendMessages(disp: PDispatcher, client: TSocketHandle) {.async.} =
   for i in 0 .. <messagesToSend:
-    discard await disp.send(client, "Message " & $i & "\c\L")
+    await disp.send(client, "Message " & $i & "\c\L")
 
-proc launchSwarm(disp: PDispatcher, port: TPort): PFuture[int] {.async.} =
+proc launchSwarm(disp: PDispatcher, port: TPort) {.async.} =
   for i in 0 .. <swarmSize:
     var sock = disp.socket()
 
     #disp.register(sock)
-    discard await disp.connect(sock, "localhost", port)
+    await disp.connect(sock, "localhost", port)
     when true:
-      discard await sendMessages(disp, sock)
-      sock.close()
+      await sendMessages(disp, sock)
+      disp.close(sock)
     else:
       # Issue #932: https://github.com/Araq/Nimrod/issues/932
       var msgFut = sendMessages(disp, sock)
       msgFut.callback =
         proc () =
-          sock.close()
+          disp.close(sock)
 
-proc readMessages(disp: PDispatcher, client: TSocketHandle): PFuture[int] {.async.} =
+proc readMessages(disp: PDispatcher, client: TSocketHandle) {.async.} =
   while true:
     var line = await disp.recvLine(client)
     if line == "":
-      client.close()
+      disp.close(client)
       clientCount.inc
       break
     else:
@@ -47,16 +47,18 @@ proc readMessages(disp: PDispatcher, client: TSocketHandle): PFuture[int] {.asyn
       else:
         doAssert false
 
-proc createServer(disp: PDispatcher, port: TPort): PFuture[int] {.async.} =
+proc createServer(disp: PDispatcher, port: TPort) {.async.} =
   var server = disp.socket()
   #disp.register(server)
   server.bindAddr(port)
   server.listen()
   while true:
-    discard readMessages(disp, await disp.accept(server))
+    var client = await disp.accept(server)
+    readMessages(disp, client)
+    # TODO: Test: readMessages(disp, await disp.accept(server))
 
-discard disp.createServer(TPort(10335))
-discard disp.launchSwarm(TPort(10335))
+disp.createServer(TPort(10335))
+disp.launchSwarm(TPort(10335))
 while true:
   disp.poll()
   if clientCount == swarmSize: break
diff --git a/tests/bind/tbindtypedesc.nim b/tests/bind/tinvalidbindtypedesc.nim
index d6fbae537..5b2f51110 100644
--- a/tests/bind/tbindtypedesc.nim
+++ b/tests/bind/tinvalidbindtypedesc.nim
@@ -1,6 +1,5 @@
 discard """
-  line: 11
-  file: "tbindtypedesc.nim"
+  line: 10
   errormsg: "type mismatch: got (typedesc[float], string)"
 """
 
diff --git a/tests/effects/teffects1.nim b/tests/effects/teffects1.nim
index b72e8b00c..0014cff46 100644
--- a/tests/effects/teffects1.nim
+++ b/tests/effects/teffects1.nim
@@ -1,5 +1,5 @@
 discard """
-  line: 1855
+  line: 1913
   file: "system.nim"
   errormsg: "can raise an unlisted exception: ref EIO"
 """
diff --git a/tests/generics/tbadgenericlambda.nim b/tests/generics/tbadgenericlambda.nim
new file mode 100644
index 000000000..38e7f6cd7
--- /dev/null
+++ b/tests/generics/tbadgenericlambda.nim
@@ -0,0 +1,7 @@
+discard """
+  errmsg: "nested proc can have generic parameters only when"
+  line: 6
+"""
+
+let x = proc (x, y): auto = x + y
+
diff --git a/tests/generics/tgenericlambda.nim b/tests/generics/tgenericlambda.nim
index f7aafe1d9..eb6ada3e5 100644
--- a/tests/generics/tgenericlambda.nim
+++ b/tests/generics/tgenericlambda.nim
@@ -1,5 +1,5 @@
 discard """
-  output: "10\n10\n1\n2\n3"
+  output: "10\n10\n1\n2\n3\n15"
 """
 
 proc test(x: proc (a, b: int): int) =
@@ -16,3 +16,8 @@ proc foreach[T](s: seq[T], body: proc(x: T)) =
 foreach(@[1,2,3]) do (x):
   echo x
 
+proc foo =
+  let x = proc (a, b: int): auto = a + b
+  echo x(5, 10)
+
+foo()
diff --git a/tests/generics/tlateboundstatic.nim b/tests/generics/tlateboundstatic.nim
new file mode 100644
index 000000000..f68f95f8d
--- /dev/null
+++ b/tests/generics/tlateboundstatic.nim
@@ -0,0 +1,16 @@
+discard """
+  msg: "array[0..3, int]"
+"""
+
+type
+  KK[I: static[int]] = object
+   x: array[I, int]
+
+proc foo(a: static[string]): KK[a.len] =
+  result.x[0] = 12
+
+var x = foo "test"
+
+import typetraits
+static: echo x.x.type.name
+
diff --git a/tests/generics/tmetafield.nim b/tests/generics/tmetafield.nim
index 42353006d..8e7f26549 100644
--- a/tests/generics/tmetafield.nim
+++ b/tests/generics/tmetafield.nim
@@ -1,8 +1,8 @@
 discard """
   cmd: "nimrod check $# $#"
-  msg: "'proc' is not a concrete type"
-  msg: "'Foo' is not a concrete type."
-  msg: "invalid type: 'TBaseMed'"
+  errmsg: "'proc' is not a concrete type"
+  errmsg: "'Foo' is not a concrete type."
+  errmsg: "invalid type: 'TBaseMed'"
 """
 
 type
diff --git a/tests/generics/tsigtypeop.nim b/tests/generics/tsigtypeop.nim
new file mode 100644
index 000000000..4c863cba1
--- /dev/null
+++ b/tests/generics/tsigtypeop.nim
@@ -0,0 +1,9 @@
+type
+  Vec3[T] = array[3, T]
+
+proc foo(x: Vec3, y: Vec3.T, z: x.T): x.type.T =
+  return 10
+
+var y: Vec3[int] = [1, 2, 3]
+var z: int = foo(y, 3, 4)
+
diff --git a/tests/matrix/issue1013.nim b/tests/matrix/issue1013.nim
new file mode 100644
index 000000000..7d3d52f85
--- /dev/null
+++ b/tests/matrix/issue1013.nim
@@ -0,0 +1,23 @@
+import typetraits
+
+template reject(e: expr) =
+  static: assert(not compiles(e))
+
+type
+  TMatrix[T; M, N: static[int]] = array[M*N, T]
+
+proc `*`[T; R, N, C](a: TMatrix[T, R, N], b: TMatrix[T, N, C]): TMatrix[T, R, C] =
+  discard
+
+var m1: TMatrix[int, 6, 4]
+var m2: TMatrix[int, 4, 3]
+var m3: TMatrix[int, 3, 3]
+
+var m4 = m1*m2
+static: assert m4.M == 6 and m4.N == 3
+
+reject m1 * m3 # not compatible
+
+var m5 = m2 * m3
+static: assert high(m5) == 11 # 4*3 - 1
+
diff --git a/tests/metatype/swizzle.nim b/tests/metatype/swizzle.nim
new file mode 100644
index 000000000..ce18fa234
--- /dev/null
+++ b/tests/metatype/swizzle.nim
@@ -0,0 +1,79 @@
+discard """
+  output: '''3
+[1, 3]
+[2, 1, 2]
+'''
+"""
+
+import macros, strutils
+
+template accept(e: expr) =
+  static: assert(compiles(e))
+
+template reject(e: expr) =
+  static: assert(not compiles(e))
+
+proc swizzleIdx(c: char): int =
+  return case c
+    of 'x': 0
+    of 'y': 1
+    of 'z': 2
+    of 'w': 3    
+    of 'r': 0
+    of 'g': 1
+    of 'b': 2
+    of 'a': 3    
+    else: 0
+
+proc isSwizzle(s: string): bool =
+  template trySet(name, set) =
+    block search:
+      for c in s:
+        if c notin set:
+          break search
+      return true
+
+  trySet coords, {'x', 'y', 'z', 'w'}
+  trySet colors, {'r', 'g', 'b', 'a'}
+  
+  return false
+
+type 
+  StringIsSwizzle = generic value
+    value.isSwizzle
+
+  SwizzleStr = static[string] and StringIsSwizzle
+
+proc foo(x: SwizzleStr) =
+  echo "sw"
+
+accept foo("xx")
+reject foo("xe")
+
+type 
+  Vec[N: static[int]; T] = array[N, T]
+
+
+proc card(x: Vec): int = x.N
+proc `$`(x: Vec): string = x.repr.strip
+
+macro `.`(x: Vec, swizzle: SwizzleStr): expr =
+  var
+    cardinality = swizzle.len
+    values = newNimNode(nnkBracket)
+    v = genSym()
+
+  for c in swizzle:
+    values.add newNimNode(nnkBracketExpr).add(
+      v, c.swizzleIdx.newIntLitNode)
+  
+  return quote do:
+    let `v` = `x`
+    Vec[`cardinality`, `v`.T](`values`)
+
+var z = Vec([1, 2, 3])
+
+echo z.card
+echo z.xz
+echo z.yxy
+
diff --git a/tests/metatype/tstaticparams.nim b/tests/metatype/tstaticparams.nim
index e76dae23c..6d7c569e0 100644
--- a/tests/metatype/tstaticparams.nim
+++ b/tests/metatype/tstaticparams.nim
@@ -1,6 +1,6 @@
 discard """
   file: "tstaticparams.nim"
-  output: "abracadabra\ntest\n3\n15\4"
+  output: "abracadabra\ntest\n3\n15\n4\n2"
 """
 
 type 
@@ -14,6 +14,9 @@ type
   TA2[T; I: static[int]] = array[0..I, T]
   TA3[T; I: static[int]] = array[I-1, T]
 
+  TObj = object
+    x: TA3[int, 3]
+
 proc takeFoo(x: TFoo) =
   echo "abracadabra"
   echo TFoo.Val
@@ -28,6 +31,7 @@ var
   t1: TA1[float, 1]
   t2: TA2[string, 4]
   t3: TA3[int, 10]
+  t4: TObj
 
 # example from the manual:
 type
@@ -45,3 +49,10 @@ proc getRows(mtx: Matrix): int =
   result = mtx.M
 
 echo getRows(m)
+
+# issue 997
+type TTest[T: static[int], U: static[int]] = array[0..T*U, int]
+type TTestSub[N: static[int]] = TTest[1, N]
+
+var z: TTestSub[2]
+echo z.high
diff --git a/tests/metatype/tusertypeclasses.nim b/tests/metatype/tusertypeclasses.nim
index 5b04c490f..a5d575dbf 100644
--- a/tests/metatype/tusertypeclasses.nim
+++ b/tests/metatype/tusertypeclasses.nim
@@ -26,7 +26,7 @@ foo 10
 foo "test"
 foo(@[TObj(x: 10), TObj(x: 20)])
 
-proc intval(x: int) = discard
+proc intval(x: int): int = 10
 
 # check real and virtual fields
 type
@@ -34,7 +34,8 @@ type
     T.x
     y(T)
     intval T.y
-    
+    let z = intval(T.y)
+
 proc y(x: TObj): int = 10
 
 proc testFoo(x: TFoo) = discard
diff --git a/tests/metatype/tusertypeclasses2.nim b/tests/metatype/tusertypeclasses2.nim
new file mode 100644
index 000000000..77c70d7a6
--- /dev/null
+++ b/tests/metatype/tusertypeclasses2.nim
@@ -0,0 +1,24 @@
+type
+  hasFieldX = generic z
+    z.x is int
+
+  obj_x = object
+    x: int
+
+  ref_obj_x = ref object
+    x: int
+  
+  ref_to_obj_x = ref obj_x
+
+  p_o_x = ptr obj_x
+  v_o_x = var obj_x
+
+template check(x) =
+  static: assert(x)
+
+check obj_x is hasFieldX
+check ref_obj_x is hasFieldX
+check ref_to_obj_x is hasFieldX
+check p_o_x is hasFieldX
+check v_o_x is hasFieldX
+
diff --git a/tests/metatype/typeclassinference.nim b/tests/metatype/typeclassinference.nim
new file mode 100644
index 000000000..72b5aca96
--- /dev/null
+++ b/tests/metatype/typeclassinference.nim
@@ -0,0 +1,10 @@
+import typetraits
+
+type
+  Vec[N: static[int]; T] = distinct array[N, T]
+
+var x = Vec([1, 2, 3])
+
+static:
+  assert x.type.name == "Vec[static[int](3), int]"
+
diff --git a/tests/metatype/udtcmanual.nim b/tests/metatype/udtcmanual.nim
index f22bd6ac6..dd44298dc 100644
--- a/tests/metatype/udtcmanual.nim
+++ b/tests/metatype/udtcmanual.nim
@@ -25,7 +25,7 @@ type
     C.len is Ordinal
     items(c) is iterator
     for value in C:
-      value.type is T
+      type(value) is T
 
 proc takesIntContainer(c: Container[int]) =
   for e in c: echo e
diff --git a/tests/objects/tobjpragma.nim b/tests/objects/tobjpragma.nim
new file mode 100644
index 000000000..f9fbd5e40
--- /dev/null
+++ b/tests/objects/tobjpragma.nim
@@ -0,0 +1,49 @@
+discard """
+  file: "tobjpragma.nim"
+  output: '''2
+3
+9
+257
+1
+2
+3'''
+"""
+
+# Test 
+
+type
+  Foo {.packed.} = object
+    a: int8
+    b: int8
+
+  Bar {.packed.} = object
+    a: int8
+    b: int16   
+    
+  Daz {.packed.} = object
+    a: int32
+    b: int8 
+    c: int32  
+
+
+var f = Foo(a: 1, b: 1)
+var b: Bar
+var d: Daz
+
+echo sizeof(f)
+echo sizeof(b)
+echo sizeof(d)
+echo (cast[ptr int16](f.addr)[])
+
+type
+  Union {.union.} = object
+    a: int8
+    b: int8
+
+var u: Union
+u.a = 1
+echo u.b
+u.a = 2
+echo u.b
+u.b = 3
+echo u.a
diff --git a/tests/overload/tissue966.nim b/tests/overload/tissue966.nim
index 53ec2f108..2911348cf 100644
--- a/tests/overload/tissue966.nim
+++ b/tests/overload/tissue966.nim
@@ -1,5 +1,5 @@
 discard """
-  msg: 'type mismatch: got (PTest)'
+  errormsg: "type mismatch: got (PTest)"
 """
 
 type
diff --git a/tests/stdlib/tpegs.nim b/tests/stdlib/tpegs.nim
index 7775091a1..6e488bab4 100644
--- a/tests/stdlib/tpegs.nim
+++ b/tests/stdlib/tpegs.nim
@@ -72,7 +72,7 @@ type
     rule: TNode                   ## the rule that the symbol refers to
   TNode {.final, shallow.} = object
     case kind: TPegKind
-    of pkEmpty..pkWhitespace: discard
+    of pkEmpty..pkWhitespace: nil
     of pkTerminal, pkTerminalIgnoreCase, pkTerminalIgnoreStyle: term: string
     of pkChar, pkGreedyRepChar: ch: char
     of pkCharChoice, pkGreedyRepSet: charChoice: ref set[char]
diff --git a/tests/testament/specs.nim b/tests/testament/specs.nim
index f7982127f..65e17a453 100644
--- a/tests/testament/specs.nim
+++ b/tests/testament/specs.nim
@@ -114,7 +114,11 @@ proc parseSpec*(filename: string): TSpec =
       result.substr = true
     of "exitcode": 
       discard parseInt(e.value, result.exitCode)
-    of "errormsg", "msg":
+    of "msg":
+      result.msg = e.value
+      if result.action != actionRun:
+        result.action = actionCompile
+    of "errormsg":
       result.msg = e.value
       result.action = actionReject
     of "disabled":
diff --git a/tests/testament/tester.nim b/tests/testament/tester.nim
index fac97cf2a..6655b1b79 100644
--- a/tests/testament/tester.nim
+++ b/tests/testament/tester.nim
@@ -11,7 +11,7 @@
 
 import
   parseutils, strutils, pegs, os, osproc, streams, parsecfg, json,
-  marshal, backend, parseopt, specs, htmlgen, browsers
+  marshal, backend, parseopt, specs, htmlgen, browsers, terminal
 
 const
   resultsFile = "testresults.html"
@@ -109,6 +109,12 @@ proc addResult(r: var TResults, test: TTest,
                           expected = expected,
                           given = given)
   r.data.addf("$#\t$#\t$#\t$#", name, expected, given, $success)
+  if success notin {reSuccess, reIgnored}:
+    styledEcho styleBright, name, fgRed, " [", $success, "]"
+    styledEcho styleDim, "EXPECTED:"
+    echo expected
+    styledEcho styleDim, "GIVEN:"
+    echo given
 
 proc cmpMsgs(r: var TResults, expected, given: TSpec, test: TTest) =
   if strip(expected.msg) notin strip(given.msg):
diff --git a/tests/vm/twrongconst.nim b/tests/vm/twrongconst.nim
index e5b8a15bd..5c0c80f9f 100644
--- a/tests/vm/twrongconst.nim
+++ b/tests/vm/twrongconst.nim
@@ -1,10 +1,9 @@
 discard """
-  output: "Error: cannot evaluate at compile time: x"
-  line: 10
+  errormsg: "cannot evaluate at compile time: x"
+  line: 9
 """
 
-var x: array[100, char] 
+var x: array[100, char]
 template Foo : expr = x[42]
 
-
 const myConst = foo
diff --git a/tests/vm/twrongwhen.nim b/tests/vm/twrongwhen.nim
index 085bb6fb6..d67e42883 100644
--- a/tests/vm/twrongwhen.nim
+++ b/tests/vm/twrongwhen.nim
@@ -1,9 +1,9 @@
 discard """
-  output: "Error: cannot evaluate at compile time: x"
+  errormsg: "cannot evaluate at compile time: x"
   line: 7
 """
 
-proc bla(x:int) = 
+proc bla(x:int) =
   when x == 0:
     echo "oops"
   else: