diff options
author | Araq <rumpf_a@web.de> | 2014-02-25 01:06:35 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2014-02-25 01:06:35 +0100 |
commit | 10768904eb65da1899d0d48cc1a2f3547af3bef0 (patch) | |
tree | 79676143be1663cacdbb5a8790451fde4e7366bc /tests | |
parent | ab72377ce64cf2b563ea90204925b793082971cb (diff) | |
parent | e6b0b7ecc9bb81d94eec19fbc4fc62e104f59253 (diff) | |
download | Nim-10768904eb65da1899d0d48cc1a2f3547af3bef0.tar.gz |
Merge branch 'devel' of https://github.com/Araq/Nimrod into devel
Conflicts: lib/system/jssys.nim
Diffstat (limited to 'tests')
-rw-r--r-- | tests/actiontable/tactiontable2.nim | 2 | ||||
-rw-r--r-- | tests/async/tasyncawait.nim | 4 | ||||
-rw-r--r-- | tests/exception/tfinally4.nim | 40 | ||||
-rw-r--r-- | tests/exception/tnestedreturn.nim | 40 | ||||
-rw-r--r-- | tests/exception/tnestedreturn2.nim | 20 | ||||
-rw-r--r-- | tests/generics/tgenericlambda.nim | 10 | ||||
-rw-r--r-- | tests/global/globalaux.nim | 15 | ||||
-rw-r--r-- | tests/global/globalaux2.nim | 4 | ||||
-rw-r--r-- | tests/metatype/tbindtypedesc.nim | 23 | ||||
-rw-r--r-- | tests/metatype/tusertypeclasses.nim | 5 | ||||
-rw-r--r-- | tests/module/trecinca.nim | 2 | ||||
-rw-r--r-- | tests/module/trecincb.nim | 2 | ||||
-rw-r--r-- | tests/stdlib/tircbot.nim | 2 | ||||
-rw-r--r-- | tests/template/sunset.tmpl (renamed from tests/sunset.tmpl) | 0 | ||||
-rw-r--r-- | tests/threads/nimrod.cfg | 1 | ||||
-rw-r--r-- | tests/typerel/tvoid.nim | 6 |
16 files changed, 153 insertions, 23 deletions
diff --git a/tests/actiontable/tactiontable2.nim b/tests/actiontable/tactiontable2.nim index 00b427603..878356321 100644 --- a/tests/actiontable/tactiontable2.nim +++ b/tests/actiontable/tactiontable2.nim @@ -1,6 +1,6 @@ discard """ line: 21 - errormsg: "invalid type: 'TTable'" + errormsg: "invalid type: 'TTable[string, proc (string)]'" """ import tables diff --git a/tests/async/tasyncawait.nim b/tests/async/tasyncawait.nim index bcaffc287..bde5bf8c8 100644 --- a/tests/async/tasyncawait.nim +++ b/tests/async/tasyncawait.nim @@ -21,7 +21,7 @@ proc sendMessages(disp: PDispatcher, client: TSocketHandle): PFuture[int] {.asyn proc launchSwarm(disp: PDispatcher, port: TPort): PFuture[int] {.async.} = for i in 0 .. <swarmSize: var sock = socket() - disp.register(sock) + #disp.register(sock) discard await disp.connect(sock, "localhost", port) when true: discard await sendMessages(disp, sock) @@ -48,7 +48,7 @@ proc readMessages(disp: PDispatcher, client: TSocketHandle): PFuture[int] {.asyn proc createServer(disp: PDispatcher, port: TPort): PFuture[int] {.async.} = var server = socket() - disp.register(server) + #disp.register(server) server.bindAddr(port) server.listen() while true: diff --git a/tests/exception/tfinally4.nim b/tests/exception/tfinally4.nim new file mode 100644 index 000000000..05c57c4f5 --- /dev/null +++ b/tests/exception/tfinally4.nim @@ -0,0 +1,40 @@ +discard """ + file: "tfinally4.nim" + output: "B1\nA1\n1\nB1\nB2\ncatch\nA1\n1\nB1\nA1\nA2\n2\nB1\nB2\ncatch\nA1\nA2\n0\nB1\nA1\n1\nB1\nB2\nA1\n1\nB1\nA1\nA2\n2\nB1\nB2\nA1\nA2\n3" +""" + +# More thorough test of return-in-finaly + +var raiseEx = true +var returnA = true +var returnB = false + +proc main: int = + try: #A + try: #B + if raiseEx: + raise newException(EOS, "") + return 3 + finally: #B + echo "B1" + if returnB: + return 2 + echo "B2" + except EOS: #A + echo "catch" + finally: #A + echo "A1" + if returnA: + return 1 + echo "A2" + +for x in [true, false]: + for y in [true, false]: + for z in [true, false]: + # echo "raiseEx: " & $x + # echo "returnA: " & $y + # echo "returnB: " & $z + raiseEx = x + returnA = y + returnB = z + echo main() diff --git a/tests/exception/tnestedreturn.nim b/tests/exception/tnestedreturn.nim new file mode 100644 index 000000000..b9f7843f6 --- /dev/null +++ b/tests/exception/tnestedreturn.nim @@ -0,0 +1,40 @@ +discard """ + file: "tnestedreturn.nim" + output: "A\nB\nC\n" +""" + +# Various tests of return nested in double try/except statements + +proc test1() = + + finally: echo "A" + + try: + raise newException(EOS, "Problem") + except EOS: + return + +test1() + + +proc test2() = + + finally: echo "B" + + try: + return + except EOS: + discard + +test2() + +proc test3() = + try: + try: + raise newException(EOS, "Problem") + except EOS: + return + finally: + echo "C" + +test3() diff --git a/tests/exception/tnestedreturn2.nim b/tests/exception/tnestedreturn2.nim new file mode 100644 index 000000000..14a2dab92 --- /dev/null +++ b/tests/exception/tnestedreturn2.nim @@ -0,0 +1,20 @@ +discard """ + file: "tnestedreturn.nim" + outputsub: "Error: unhandled exception: Problem [EOS]" + exitcode: "1" +""" + +proc test4() = + try: + try: + raise newException(EOS, "Problem") + except EOS: + return + finally: + discard + +# Should cause unhandled exception error, +# but could cause segmentation fault if +# exceptions are not handled properly. +test4() +raise newException(EOS, "Problem") diff --git a/tests/generics/tgenericlambda.nim b/tests/generics/tgenericlambda.nim index a71c592c5..f7aafe1d9 100644 --- a/tests/generics/tgenericlambda.nim +++ b/tests/generics/tgenericlambda.nim @@ -1,5 +1,5 @@ discard """ - output: "10\n10" + output: "10\n10\n1\n2\n3" """ proc test(x: proc (a, b: int): int) = @@ -8,3 +8,11 @@ proc test(x: proc (a, b: int): int) = test(proc (a, b): auto = a + b) test do (a, b) -> auto: a + b + +proc foreach[T](s: seq[T], body: proc(x: T)) = + for e in s: + body(e) + +foreach(@[1,2,3]) do (x): + echo x + diff --git a/tests/global/globalaux.nim b/tests/global/globalaux.nim new file mode 100644 index 000000000..5f6f72721 --- /dev/null +++ b/tests/global/globalaux.nim @@ -0,0 +1,15 @@ +type + TObj*[T] = object + val*: T + +var + totalGlobals* = 0 + +proc makeObj[T](x: T): TObj[T] = + totalGlobals += 1 + result.val = x + +proc globalInstance*[T]: var TObj[T] = + var g {.global.} = when T is int: makeObj(10) else: makeObj("hello") + result = g + diff --git a/tests/global/globalaux2.nim b/tests/global/globalaux2.nim new file mode 100644 index 000000000..6c77f1f48 --- /dev/null +++ b/tests/global/globalaux2.nim @@ -0,0 +1,4 @@ +import globalaux + +echo "in globalaux2: ", globalInstance[int]().val + diff --git a/tests/metatype/tbindtypedesc.nim b/tests/metatype/tbindtypedesc.nim index 5ea8cf063..84527362f 100644 --- a/tests/metatype/tbindtypedesc.nim +++ b/tests/metatype/tbindtypedesc.nim @@ -1,10 +1,10 @@ discard """ - msg: ''' -int -float -TFoo -TFoo -''' + msg: '''int int +float float +int int +TFoo TFoo +int float +TFoo TFoo''' """ import typetraits @@ -24,9 +24,8 @@ template reject(e: expr) = proc genericParamRepeated[T: typedesc](a: T, b: T) = static: - echo a.name - echo b.name - + echo a.name, " ", b.name + accept genericParamRepeated(int, int) accept genericParamRepeated(float, float) @@ -35,8 +34,7 @@ reject genericParamRepeated(int, float) proc genericParamOnce[T: typedesc](a, b: T) = static: - echo a.name - echo b.name + echo a.name, " ", b.name accept genericParamOnce(int, int) accept genericParamOnce(TFoo, TFoo) @@ -68,8 +66,7 @@ reject typePairs2(string, int, TBAR, TBAR) proc dontBind(a: typedesc, b: typedesc) = static: - echo a.name - echo b.name + echo a.name, " ", b.name accept dontBind(int, float) accept dontBind(TFoo, TFoo) diff --git a/tests/metatype/tusertypeclasses.nim b/tests/metatype/tusertypeclasses.nim index 4c8c0fc56..5b04c490f 100644 --- a/tests/metatype/tusertypeclasses.nim +++ b/tests/metatype/tusertypeclasses.nim @@ -31,9 +31,10 @@ proc intval(x: int) = discard # check real and virtual fields type TFoo = generic T - intval T.x + T.x + y(T) intval T.y - + proc y(x: TObj): int = 10 proc testFoo(x: TFoo) = discard diff --git a/tests/module/trecinca.nim b/tests/module/trecinca.nim index 73a0ec937..62d37783c 100644 --- a/tests/module/trecinca.nim +++ b/tests/module/trecinca.nim @@ -1,7 +1,7 @@ discard """ file: "tests/reject/trecincb.nim" line: 9 - errormsg: "recursive dependency: 'tests/reject/trecincb.nim'" + errormsg: "recursive dependency: 'tests/module/trecincb.nim'" """ # Test recursive includes diff --git a/tests/module/trecincb.nim b/tests/module/trecincb.nim index 9dd7d51de..a2934052f 100644 --- a/tests/module/trecincb.nim +++ b/tests/module/trecincb.nim @@ -1,7 +1,7 @@ discard """ file: "trecincb.nim" line: 9 - errormsg: "recursive dependency: 'tests/reject/trecincb.nim'" + errormsg: "recursive dependency: 'tests/module/trecincb.nim'" """ # Test recursive includes diff --git a/tests/stdlib/tircbot.nim b/tests/stdlib/tircbot.nim index 71ecb0b48..f0417c7ac 100644 --- a/tests/stdlib/tircbot.nim +++ b/tests/stdlib/tircbot.nim @@ -183,7 +183,7 @@ type channel: string timestamp: TTime case kind*: TSeenType - of PSeenJoin: discard + of PSeenJoin: nil of PSeenPart, PSeenQuit, PSeenMsg: msg: string of PSeenNick: diff --git a/tests/sunset.tmpl b/tests/template/sunset.tmpl index 6475bac4e..6475bac4e 100644 --- a/tests/sunset.tmpl +++ b/tests/template/sunset.tmpl diff --git a/tests/threads/nimrod.cfg b/tests/threads/nimrod.cfg new file mode 100644 index 000000000..b81c89721 --- /dev/null +++ b/tests/threads/nimrod.cfg @@ -0,0 +1 @@ +threads:on diff --git a/tests/typerel/tvoid.nim b/tests/typerel/tvoid.nim index bb569e7f8..d31936217 100644 --- a/tests/typerel/tvoid.nim +++ b/tests/typerel/tvoid.nim @@ -1,5 +1,9 @@ discard """ - output: "he, no return type;abc a string" + output: '''12 +empty +he, no return type; +abc a string +ha''' """ proc ReturnT[T](x: T): T = |