make tests green again

This commit is contained in:
Andreas Rumpf 2018-07-05 15:51:04 +02:00
commit 0926754e68
31 changed files with 61 additions and 55 deletions

View file

@ -1060,6 +1060,8 @@ proc transformExpr*(g: ModuleGraph; module: PSym, n: PNode): PNode =
var c = openTransf(g, module, "") var c = openTransf(g, module, "")
result = processTransf(c, n, module) result = processTransf(c, n, module)
liftDefer(c, result) liftDefer(c, result)
# expressions are not to be injected with destructor calls as that
# the list of top level statements needs to be collected before.
if c.needsDestroyPass: if c.needsDestroyPass:
result = injectDestructorCalls(g, module, result) result = injectDestructorCalls(g, module, result)
incl(result.flags, nfTransf) incl(result.flags, nfTransf)

View file

@ -28,7 +28,7 @@ proc foo: bool =
return true return true
proc err = proc err =
raise newException(EArithmetic, "some exception") raise newException(ArithmeticError, "some exception")
test "final test": test "final test":
echo "inside suite-less test" echo "inside suite-less test"
@ -39,9 +39,9 @@ test "final test":
d > 10 d > 10
test "arithmetic failure": test "arithmetic failure":
expect(EArithmetic): expect(ArithmeticError):
err() err()
expect(EArithmetic, ESystem): expect(ArithmeticError, SystemError):
discard foo() discard foo()

View file

@ -11,7 +11,7 @@ proc callC() = callA()
try: try:
callC() callC()
except EAssertionFailed: except AssertionError:
write(stdout, "assertion failure!") write(stdout, "assertion failure!")
except: except:
write(stdout, "unknown exception!") write(stdout, "unknown exception!")

View file

@ -8,7 +8,7 @@ assignment test a:test b:1 c:2 haha:3
# bug #1005 # bug #1005
type type
TSomeObj = object of TObject TSomeObj = object of RootObj
a, b: int a, b: int
PSomeObj = ref object PSomeObj = ref object
a, b: int a, b: int
@ -20,7 +20,7 @@ echo a.a, " ", b.a, " ", a.b, " ", b.b
# bug #575 # bug #575
type type
Something = object of Tobject Something = object of RootObj
a: string a: string
b, c: int32 b, c: int32

View file

@ -20,7 +20,7 @@ proc processClient(fd: int) {.async.} =
var line = await recvLine(fd) var line = await recvLine(fd)
var foo = line[0] var foo = line[0]
if foo == 'g': if foo == 'g':
raise newException(EBase, "foobar") raise newException(Exception, "foobar")
proc serve() {.async.} = proc serve() {.async.} =

View file

@ -15,7 +15,7 @@ import asyncdispatch, strutils
proc foobar() {.async.} = proc foobar() {.async.} =
if 5 == 5: if 5 == 5:
raise newException(EInvalidIndex, "Test") raise newException(IndexError, "Test")
proc catch() {.async.} = proc catch() {.async.} =
# TODO: Create a test for when exceptions are not caught. # TODO: Create a test for when exceptions are not caught.
@ -26,26 +26,26 @@ proc catch() {.async.} =
try: try:
await foobar() await foobar()
except EInvalidIndex: except IndexError:
echo("Specific except") echo("Specific except")
try: try:
await foobar() await foobar()
except OSError, EInvalidField, EInvalidIndex: except OSError, FieldError, IndexError:
echo("Multiple idents in except") echo("Multiple idents in except")
try: try:
await foobar() await foobar()
except OSError, EInvalidField: except OSError, FieldError:
assert false assert false
except EInvalidIndex: except IndexError:
echo("Multiple except branches") echo("Multiple except branches")
try: try:
await foobar() await foobar()
except EInvalidIndex: except IndexError:
echo("Multiple except branches 2") echo("Multiple except branches 2")
except OSError, EInvalidField: except OSError, FieldError:
assert false assert false
waitFor catch() waitFor catch()

View file

@ -14,7 +14,7 @@ when defined(windows):
var clientCount = 0 var clientCount = 0
proc winConnect*(socket: AsyncFD, address: string, port: Port, proc winConnect*(socket: AsyncFD, address: string, port: Port,
domain = Domain.AF_INET): Future[void] = domain = Domain.AF_INET): Future[void] =
var retFuture = newFuture[void]("winConnect") var retFuture = newFuture[void]("winConnect")
proc cb(fd: AsyncFD): bool = proc cb(fd: AsyncFD): bool =
var ret = SocketHandle(fd).getSockOptInt(cint(SOL_SOCKET), cint(SO_ERROR)) var ret = SocketHandle(fd).getSockOptInt(cint(SOL_SOCKET), cint(SO_ERROR))
@ -183,7 +183,7 @@ when defined(windows):
## **Note**: This procedure is mostly used for testing. You likely want to ## **Note**: This procedure is mostly used for testing. You likely want to
## use ``asyncnet.recvLine`` instead. ## use ``asyncnet.recvLine`` instead.
template addNLIfEmpty(): stmt = template addNLIfEmpty() =
if result.len == 0: if result.len == 0:
result.add("\c\L") result.add("\c\L")

View file

@ -13,7 +13,7 @@ q[float](0.8, 0.2)
# bug #942 # bug #942
template maybeMod(x: Tinteger, module:Natural): untyped = template maybeMod(x: SomeInteger, module: Natural): untyped =
if module > 0: x mod module if module > 0: x mod module
else: x else: x

View file

@ -11,7 +11,7 @@ type
EIO2 = ref object of EIO EIO2 = ref object of EIO
proc raiser(): int {.tags: [TObj, FWriteIO].} = proc raiser(): int {.tags: [TObj, WriteIoEffect].} =
writeLine stdout, "arg" writeLine stdout, "arg"
var o: TObjB var o: TObjB

View file

@ -7,11 +7,11 @@ type
TObj = object {.pure, inheritable.} TObj = object {.pure, inheritable.}
TObjB = object of TObj TObjB = object of TObj
a, b, c: string a, b, c: string
fn: proc (): int {.tags: [FReadIO].} fn: proc (): int {.tags: [ReadIOEffect].}
EIO2 = ref object of EIO EIO2 = ref object of EIO
proc q() {.tags: [FIO].} = proc q() {.tags: [IoEffect].} =
discard discard
proc raiser(): int = proc raiser(): int =

View file

@ -11,7 +11,7 @@ createMenuItem(s, "Go to definition...",
proc (i: PMenuItem, p: pointer) {.cdecl.} = proc (i: PMenuItem, p: pointer) {.cdecl.} =
try: try:
echo(i.repr) echo(i.repr)
except EInvalidValue: except ValueError:
echo("blah") echo("blah")
) )

View file

@ -1,11 +1,11 @@
discard """ discard """
errormsg: "invalid type: 'expr' in this context: 'proc (a: varargs[expr])' for proc" errormsg: "invalid type: 'untyped' in this context: 'proc (a: varargs[untyped])' for proc"
line: 8 line: 8
""" """
import typetraits import typetraits
proc foo(a:varargs[expr]) = proc foo(a:varargs[untyped]) =
echo a[0].type.name echo a[0].type.name
foo(1) foo(1)

View file

@ -4,8 +4,8 @@ discard """
exitcode: "1" exitcode: "1"
""" """
type type
ESomething = object of E_Base ESomething = object of Exception
ESomeOtherErr = object of E_Base ESomeOtherErr = object of Exception
proc genErrors(s: string) = proc genErrors(s: string) =
if s == "error!": if s == "error!":

View file

@ -14,7 +14,7 @@ proc indexOf*(t: typedesc, name: string): int =
for n, x in fieldPairs(d): for n, x in fieldPairs(d):
if n == name: return i if n == name: return i
i.inc i.inc
raise newException(EInvalidValue, "No field " & name & " in type " & raise newException(ValueError, "No field " & name & " in type " &
astToStr(t)) astToStr(t))
echo TMyTuple.indexOf("b") echo TMyTuple.indexOf("b")

View file

@ -6,11 +6,11 @@ when defined(GC_setMaxPause):
GC_setMaxPause 2_000 GC_setMaxPause 2_000
type type
TTestObj = object of TObject TTestObj = object of RootObj
x: string x: string
s: seq[int] s: seq[int]
proc MakeObj(): TTestObj = proc makeObj(): TTestObj =
result.x = "Hello" result.x = "Hello"
result.s = @[1,2,3] result.s = @[1,2,3]
@ -19,7 +19,7 @@ proc inProc() =
when defined(gcMarkAndSweep) or defined(boehmgc): when defined(gcMarkAndSweep) or defined(boehmgc):
GC_fullcollect() GC_fullcollect()
var obj: TTestObj var obj: TTestObj
obj = MakeObj() obj = makeObj()
if getOccupiedMem() > 300_000: quit("still a leak!") if getOccupiedMem() > 300_000: quit("still a leak!")
inProc() inProc()

View file

@ -1,5 +1,5 @@
type type
Matrix*[M, N: static[int], T: SomeReal] = object Matrix*[M, N: static[int], T: SomeFloat] = object
data: ref array[N * M, T] data: ref array[N * M, T]
Matrix64*[M, N: static[int]] = Matrix[M, N, float64] Matrix64*[M, N: static[int]] = Matrix[M, N, float64]

View file

@ -4,7 +4,7 @@
## Created by Eric Doughty-Papassideris on 2011-02-16. ## Created by Eric Doughty-Papassideris on 2011-02-16.
type type
TGen[T] = object of TObject TGen[T] = object of RootObj
x, y: T x, y: T
TSpef[T] = object of TGen[T] TSpef[T] = object of TGen[T]

View file

@ -1,11 +1,11 @@
type type
TProperty[T] = object of TObject TProperty[T] = object of RootObj
getProc: proc(property: TProperty[T]): T {.nimcall.} getProc: proc(property: TProperty[T]): T {.nimcall.}
setProc: proc(property: TProperty[T], value: T) {.nimcall.} setProc: proc(property: TProperty[T], value: T) {.nimcall.}
value: T value: T
proc newProperty[T](value: TObject): TProperty[T] = proc newProperty[T](value: RootObj): TProperty[T] =
result.getProc = proc (property: TProperty[T]) = result.getProc = proc (property: TProperty[T]) =
return property.value return property.value

View file

@ -4,7 +4,7 @@ discard """
""" """
type type
Matrix[M,N: static[int]; T: SomeReal] = distinct array[0..(M*N - 1), T] Matrix[M,N: static[int]; T: SomeFloat] = distinct array[0..(M*N - 1), T]
let a = new Matrix[2,2,float] let a = new Matrix[2,2,float]
let b = new Matrix[2,1,float] let b = new Matrix[2,1,float]

View file

@ -22,7 +22,7 @@ proc p =
try: try:
z = parseInt("1233") z = parseInt("1233")
except E_Base: except Exception:
case x case x
of 34: z = 123 of 34: z = 123
of 13: z = 34 of 13: z = 34

View file

@ -1,6 +1,6 @@
type type
TIdObj* = object of TObject TIdObj* = object of RootObj
id*: int # unique id; use this for comparisons and not the pointers id*: int # unique id; use this for comparisons and not the pointers
PIdObj* = ref TIdObj PIdObj* = ref TIdObj

View file

@ -1,4 +1,4 @@
template filterIt2*(seq, pred: expr, body: stmt): stmt {.immediate, dirty.} = template filterIt2*(seq, pred: untyped, body: untyped) =
## sequtils defines a filterIt() that returns a new seq, but this one is called ## sequtils defines a filterIt() that returns a new seq, but this one is called
## with a statement body to iterate directly over it ## with a statement body to iterate directly over it
for it in items(seq): for it in items(seq):
@ -13,8 +13,8 @@ proc mapInPlace*[A](x: var seq[A], fun: proc(y: A): A {.closure.}) =
for i in 0..x.len-1: for i in 0..x.len-1:
x[i] = fun(x[i]) x[i] = fun(x[i])
template unless*(condition: expr; body: stmt): stmt {.dirty.} = template unless*(condition: untyped; body: untyped) {.dirty.} =
if not(condition): if not condition:
body body
when isMainModule: when isMainModule:

View file

@ -5,13 +5,13 @@ from strutils import countlines
type type
PGuiContainer* = ref TGuiContainer PGuiContainer* = ref TGuiContainer
TGuiContainer* = object of TObject TGuiContainer* = object of RootObj
position: TVector2f position: TVector2f
activeEntry: PTextEntry activeEntry: PTextEntry
widgets: seq[PGuiObject] widgets: seq[PGuiObject]
buttons: seq[PButton] buttons: seq[PButton]
PGuiObject* = ref TGuiObject PGuiObject* = ref TGuiObject
TGuiObject* = object of TObject TGuiObject* = object of RootObj
PButton* = ref TButton PButton* = ref TButton
TButton* = object of TGuiObject TButton* = object of TGuiObject
enabled: bool enabled: bool

View file

@ -22,10 +22,10 @@ proc runTask*(name: string) {.inline.}
proc shell*(cmd: varargs[string, `$`]): int {.discardable.} proc shell*(cmd: varargs[string, `$`]): int {.discardable.}
proc cd*(dir: string) {.inline.} proc cd*(dir: string) {.inline.}
template nakeImports*(): stmt {.immediate.} = template nakeImports*() =
import tables, parseopt, strutils, os import tables, parseopt, strutils, os
template task*(name: string; description: string; body: stmt): stmt {.dirty, immediate.} = template task*(name: string; description: string; body: untyped) {.dirty.} =
block: block:
var t = newTask(description, proc() {.closure.} = var t = newTask(description, proc() {.closure.} =
body) body)
@ -40,7 +40,7 @@ proc runTask*(name: string) = tasks[name].action()
proc shell*(cmd: varargs[string, `$`]): int = proc shell*(cmd: varargs[string, `$`]): int =
result = execShellCmd(cmd.join(" ")) result = execShellCmd(cmd.join(" "))
proc cd*(dir: string) = setCurrentDir(dir) proc cd*(dir: string) = setCurrentDir(dir)
template withDir*(dir: string; body: stmt): stmt = template withDir*(dir: string; body: untyped) =
## temporary cd ## temporary cd
## withDir "foo": ## withDir "foo":
## # inside foo ## # inside foo

View file

@ -2,6 +2,10 @@
proc printf(frmt: cstring) {.varargs, importc, header: "<stdio.h>", cdecl.} proc printf(frmt: cstring) {.varargs, importc, header: "<stdio.h>", cdecl.}
proc exit(code: int) {.importc, header: "<stdlib.h>", cdecl.} proc exit(code: int) {.importc, header: "<stdlib.h>", cdecl.}
proc nimToCStringConv(s: NimString): cstring {.compilerProc, inline.} =
if s == nil or s.len == 0: result = cstring""
else: result = cstring(addr s.data)
{.push stack_trace: off, profiler:off.} {.push stack_trace: off, profiler:off.}
proc rawoutput(s: string) = proc rawoutput(s: string) =

View file

@ -3,15 +3,15 @@ discard """
output: "hello" output: "hello"
""" """
type type
Test = object of TObject Test = object of RootObj
method doMethod(a: ref TObject) {.base, raises: [EIO].} = method doMethod(a: ref RootObj) {.base, raises: [IoError].} =
quit "override" quit "override"
method doMethod(a: ref Test) = method doMethod(a: ref Test) =
echo "hello" echo "hello"
if a == nil: if a == nil:
raise newException(EIO, "arg") raise newException(IoError, "arg")
proc doProc(a: ref Test) = proc doProc(a: ref Test) =
echo "hello" echo "hello"

View file

@ -6,7 +6,7 @@ true
# bug #1053 # bug #1053
type type
TA = object of TObject TA = object of RootObj
a: int a: int
TB = object of TA TB = object of TA
@ -32,13 +32,13 @@ test(v)
# bug #924 # bug #924
type type
MyObject = object of TObject MyObject = object of RootObj
x: int x: int
var var
asd: MyObject asd: MyObject
proc isMyObject(obj: TObject) = proc isMyObject(obj: RootObj) =
echo obj of MyObject echo obj of MyObject
if obj of MyObject: if obj of MyObject:
let a = MyObject(obj) let a = MyObject(obj)
@ -46,7 +46,7 @@ proc isMyObject(obj: TObject) =
asd.x = 5 asd.x = 5
#var asdCopy = TObject(asd) #var asdCopy = RootObj(asd)
#echo asdCopy of MyObject #echo asdCopy of MyObject
isMyObject(asd) isMyObject(asd)

View file

@ -1,7 +1,7 @@
# Covariance is not type safe: # Covariance is not type safe:
type type
TA = object of TObject TA = object of RootObj
a: int a: int
TB = object of TA TB = object of TA
b: array[0..5000_000, int] b: array[0..5000_000, int]

View file

@ -43,7 +43,7 @@ proc find*[TKey, TData](root: PElement[TKey, TData], key: TKey): TData {.raises:
if tmp_element.key == key: if tmp_element.key == key:
return tmp_element.left.data return tmp_element.left.data
else: else:
raise newException(EInvalidKey, "key does not exist: " & key) raise newException(KeyError, "key does not exist: " & key)
proc add*[TKey, TData](root: var PElement[TKey, TData], key: TKey, data: TData) : bool = proc add*[TKey, TData](root: var PElement[TKey, TData], key: TKey, data: TData) : bool =
if root.left == nil: if root.left == nil:

View file

@ -4,7 +4,7 @@ discard """
""" """
# Test the overloading resolution in connection with a qualifier # Test the overloading resolution in connection with a qualifier
proc write(t: TFile, s: string) = proc write(t: File, s: string) =
discard # a nop discard # a nop
system.write(stdout, "hello") system.write(stdout, "hello")

View file

@ -1,5 +1,5 @@
template withOpenFile(f: untyped, filename: string, mode: TFileMode, template withOpenFile(f: untyped, filename: string, mode: FileMode,
actions: untyped): untyped = actions: untyped): untyped =
block: block:
# test that 'f' is implicitly 'injecting': # test that 'f' is implicitly 'injecting':