diff options
author | Araq <rumpf_a@web.de> | 2014-01-13 02:10:03 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2014-01-13 02:10:03 +0100 |
commit | 20b5f31c03fb556ec0aa2428a40adbac004d8987 (patch) | |
tree | 58086941e7d6bb8f480ca1173a95722ada9435b2 /tests/effects | |
parent | 51ee524109cf7e3e86c676bc1676063a01bfd979 (diff) | |
download | Nim-20b5f31c03fb556ec0aa2428a40adbac004d8987.tar.gz |
new tester; all tests categorized
Diffstat (limited to 'tests/effects')
-rw-r--r-- | tests/effects/teffects1.nim | 21 | ||||
-rw-r--r-- | tests/effects/teffects2.nim | 20 | ||||
-rw-r--r-- | tests/effects/teffects3.nim | 19 | ||||
-rw-r--r-- | tests/effects/teffects4.nim | 24 | ||||
-rw-r--r-- | tests/effects/teffects5.nim | 14 | ||||
-rw-r--r-- | tests/effects/teffects6.nim | 31 | ||||
-rw-r--r-- | tests/effects/tsidee1.nim | 18 | ||||
-rw-r--r-- | tests/effects/tsidee2.nim | 17 | ||||
-rw-r--r-- | tests/effects/tsidee3.nim | 17 | ||||
-rw-r--r-- | tests/effects/tsidee4.nim | 17 |
10 files changed, 198 insertions, 0 deletions
diff --git a/tests/effects/teffects1.nim b/tests/effects/teffects1.nim new file mode 100644 index 000000000..b72e8b00c --- /dev/null +++ b/tests/effects/teffects1.nim @@ -0,0 +1,21 @@ +discard """ + line: 1855 + file: "system.nim" + errormsg: "can raise an unlisted exception: ref EIO" +""" + +type + TObj = object {.pure, inheritable.} + TObjB = object of TObj + a, b, c: string + + EIO2 = ref object of EIO + +proc forw: int {. .} + +proc lier(): int {.raises: [EIO2].} = + writeln stdout, "arg" + +proc forw: int = + raise newException(EIO, "arg") + diff --git a/tests/effects/teffects2.nim b/tests/effects/teffects2.nim new file mode 100644 index 000000000..7e6b17c36 --- /dev/null +++ b/tests/effects/teffects2.nim @@ -0,0 +1,20 @@ +discard """ + line: 19 + errormsg: "can raise an unlisted exception: ref EIO" +""" + +type + TObj = object {.pure, inheritable.} + TObjB = object of TObj + a, b, c: string + + EIO2 = ref object of EIO + +proc forw: int {.raises: [].} + +proc lier(): int {.raises: [EIO].} = + writeln stdout, "arg" + +proc forw: int = + raise newException(EIO, "arg") + diff --git a/tests/effects/teffects3.nim b/tests/effects/teffects3.nim new file mode 100644 index 000000000..78543a929 --- /dev/null +++ b/tests/effects/teffects3.nim @@ -0,0 +1,19 @@ +discard """ + line: 18 + errormsg: "type mismatch" +""" + +type + TObj = object {.pure, inheritable.} + TObjB = object of TObj + a, b, c: string + fn: proc (): int {.tags: [].} + + EIO2 = ref object of EIO + +proc raiser(): int {.tags: [TObj, FWriteIO].} = + writeln stdout, "arg" + +var o: TObjB +o.fn = raiser + diff --git a/tests/effects/teffects4.nim b/tests/effects/teffects4.nim new file mode 100644 index 000000000..4584e6dc8 --- /dev/null +++ b/tests/effects/teffects4.nim @@ -0,0 +1,24 @@ +discard """ + line: 23 + errormsg: "type mismatch" +""" + +type + TObj = object {.pure, inheritable.} + TObjB = object of TObj + a, b, c: string + fn: proc (): int {.tags: [FReadIO].} + + EIO2 = ref object of EIO + +proc q() {.tags: [FIO].} = + nil + +proc raiser(): int = + writeln stdout, "arg" + if true: + q() + +var o: TObjB +o.fn = raiser + diff --git a/tests/effects/teffects5.nim b/tests/effects/teffects5.nim new file mode 100644 index 000000000..d630a6fc4 --- /dev/null +++ b/tests/effects/teffects5.nim @@ -0,0 +1,14 @@ +discard """ + errormsg: "type mismatch" + line: 7 +""" + +proc p(q: proc() ): proc() {.tags: [], raises: [], closure.} = + return proc () = + q() + +let yay = p(proc () = raise newException(EIO, "IO")) + +proc main() {.raises: [], tags: [].} = yay() + +main() diff --git a/tests/effects/teffects6.nim b/tests/effects/teffects6.nim new file mode 100644 index 000000000..54200f2c3 --- /dev/null +++ b/tests/effects/teffects6.nim @@ -0,0 +1,31 @@ + +type + PMenu = ref object + PMenuItem = ref object + +proc createMenuItem*(menu: PMenu, label: string, + action: proc (i: PMenuItem, p: pointer) {.cdecl.}) = nil + +var s: PMenu +createMenuItem(s, "Go to definition...", + proc (i: PMenuItem, p: pointer) {.cdecl.} = + try: + echo(i.repr) + except EInvalidValue: + echo("blah") +) + + +proc noRaise(x: proc()) {.raises: [].} = + # unknown call that might raise anything, but valid: + x() + +proc doRaise() {.raises: [EIO].} = + raise newException(EIO, "IO") + +proc use*() = + noRaise(doRaise) + # Here the compiler inferes that EIO can be raised. + + +use() diff --git a/tests/effects/tsidee1.nim b/tests/effects/tsidee1.nim new file mode 100644 index 000000000..bd5b32dd7 --- /dev/null +++ b/tests/effects/tsidee1.nim @@ -0,0 +1,18 @@ +discard """ + file: "tsidee1.nim" + line: 12 + errormsg: "\'SideEffectLyer\' can have side effects" +""" + +var + global: int + +proc dontcare(x: int): int = return x + global + +proc SideEffectLyer(x, y: int): int {.noSideEffect.} = #ERROR_MSG 'SideEffectLyer' can have side effects + return x + y + dontcare(x) + +echo SideEffectLyer(1, 3) + + + diff --git a/tests/effects/tsidee2.nim b/tests/effects/tsidee2.nim new file mode 100644 index 000000000..e73c89608 --- /dev/null +++ b/tests/effects/tsidee2.nim @@ -0,0 +1,17 @@ +discard """ + file: "tsidee2.nim" + output: "5" +""" + +var + global: int + +proc dontcare(x: int): int = return x + +proc SideEffectLyer(x, y: int): int {.noSideEffect.} = + return x + y + dontcare(x) + +echo SideEffectLyer(1, 3) #OUT 5 + + + diff --git a/tests/effects/tsidee3.nim b/tests/effects/tsidee3.nim new file mode 100644 index 000000000..e0c427ab6 --- /dev/null +++ b/tests/effects/tsidee3.nim @@ -0,0 +1,17 @@ +discard """ + file: "tsidee3.nim" + output: "5" +""" + +var + global: int + +proc dontcare(x: int): int {.noSideEffect.} = return x + +proc noSideEffect(x, y: int, p: proc (a: int): int {.noSideEffect.}): int {.noSideEffect.} = + return x + y + dontcare(x) + +echo noSideEffect(1, 3, dontcare) #OUT 5 + + + diff --git a/tests/effects/tsidee4.nim b/tests/effects/tsidee4.nim new file mode 100644 index 000000000..cbebfbd36 --- /dev/null +++ b/tests/effects/tsidee4.nim @@ -0,0 +1,17 @@ +discard """ + file: "tsidee4.nim" + line: 15 + errormsg: "type mismatch" +""" + +var + global: int + +proc dontcare(x: int): int = return x + +proc noSideEffect(x, y: int, p: proc (a: int): int {.noSideEffect.}): int {.noSideEffect.} = + return x + y + dontcare(x) + +echo noSideEffect(1, 3, dontcare) #ERROR_MSG type mismatch + + |