new tester; all tests categorized
This commit is contained in:
parent
51ee524109
commit
20b5f31c03
481 changed files with 794 additions and 2506 deletions
21
tests/effects/teffects1.nim
Normal file
21
tests/effects/teffects1.nim
Normal file
|
|
@ -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")
|
||||
|
||||
20
tests/effects/teffects2.nim
Normal file
20
tests/effects/teffects2.nim
Normal file
|
|
@ -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")
|
||||
|
||||
19
tests/effects/teffects3.nim
Normal file
19
tests/effects/teffects3.nim
Normal file
|
|
@ -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
|
||||
|
||||
24
tests/effects/teffects4.nim
Normal file
24
tests/effects/teffects4.nim
Normal file
|
|
@ -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
|
||||
|
||||
14
tests/effects/teffects5.nim
Normal file
14
tests/effects/teffects5.nim
Normal file
|
|
@ -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()
|
||||
31
tests/effects/teffects6.nim
Normal file
31
tests/effects/teffects6.nim
Normal file
|
|
@ -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()
|
||||
18
tests/effects/tsidee1.nim
Normal file
18
tests/effects/tsidee1.nim
Normal file
|
|
@ -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)
|
||||
|
||||
|
||||
|
||||
17
tests/effects/tsidee2.nim
Normal file
17
tests/effects/tsidee2.nim
Normal file
|
|
@ -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
|
||||
|
||||
|
||||
|
||||
17
tests/effects/tsidee3.nim
Normal file
17
tests/effects/tsidee3.nim
Normal file
|
|
@ -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
|
||||
|
||||
|
||||
|
||||
17
tests/effects/tsidee4.nim
Normal file
17
tests/effects/tsidee4.nim
Normal file
|
|
@ -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
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue