improve several tests in testament (#18635)
* silence error output from template_various.nim * any => auto in tests * avoid showing failed for parseSpec since this is expected behavior in 2 cases: tincludefile.nim, tnav1.nim * enforce InheritFromException * fixup
This commit is contained in:
parent
9269a72f6f
commit
24445d31b3
7 changed files with 38 additions and 39 deletions
|
|
@ -588,7 +588,7 @@ proc runJoinedTest(r: var TResults, cat: Category, testsDir: string, options: st
|
||||||
except ValueError:
|
except ValueError:
|
||||||
# e.g. for `tests/navigator/tincludefile.nim` which have multiple
|
# e.g. for `tests/navigator/tincludefile.nim` which have multiple
|
||||||
# specs; this will be handled elsewhere
|
# specs; this will be handled elsewhere
|
||||||
echo "parseSpec failed for: '$1', assuming this will be handled outside of megatest" % file
|
echo "parseSpec raised ValueError for: '$1', assuming this will be handled outside of megatest" % file
|
||||||
continue
|
continue
|
||||||
if isJoinableSpec(spec):
|
if isJoinableSpec(spec):
|
||||||
specs.add spec
|
specs.add spec
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ hint("Processing", off)
|
||||||
# switch("define", "nimTestsEnableFlaky")
|
# switch("define", "nimTestsEnableFlaky")
|
||||||
|
|
||||||
# switch("hint", "ConvFromXtoItselfNotNeeded")
|
# switch("hint", "ConvFromXtoItselfNotNeeded")
|
||||||
|
# switch("warningAsError", "InheritFromException") # would require fixing a few tests
|
||||||
|
|
||||||
# experimental API's are enabled in testament, refs https://github.com/timotheecour/Nim/issues/575
|
# experimental API's are enabled in testament, refs https://github.com/timotheecour/Nim/issues/575
|
||||||
# sync with `kochdocs.docDefines` or refactor.
|
# sync with `kochdocs.docDefines` or refactor.
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
proc baz(o: any): int = 5 # if bar is exported, it works
|
proc baz(o: auto): int = 5 # if bar is exported, it works
|
||||||
|
|
||||||
type MyObj = object
|
type MyObj = object
|
||||||
x: int
|
x: int
|
||||||
|
|
||||||
proc foo*(b: any) =
|
proc foo*(b: auto) =
|
||||||
var o: MyObj
|
var o: MyObj
|
||||||
echo b.baz, " ", o.x.baz, " ", b.baz()
|
echo b.baz, " ", o.x.baz, " ", b.baz()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,15 @@
|
||||||
discard """
|
discard """
|
||||||
targets: "c"
|
targets: "c cpp"
|
||||||
output: "ok"
|
|
||||||
"""
|
"""
|
||||||
var closureIterResult = newSeq[int]()
|
|
||||||
|
|
||||||
# XXX Investigate why this fails now for 'nim cpp'
|
var closureIterResult = newSeq[int]()
|
||||||
|
|
||||||
proc checkpoint(arg: int) =
|
proc checkpoint(arg: int) =
|
||||||
closureIterResult.add(arg)
|
closureIterResult.add(arg)
|
||||||
|
|
||||||
type
|
type
|
||||||
TestException = object of Exception
|
TestError = object of CatchableError
|
||||||
AnotherException = object of Exception
|
AnotherError = object of CatchableError
|
||||||
|
|
||||||
proc testClosureIterAux(it: iterator(): int, exceptionExpected: bool, expectedResults: varargs[int]) =
|
proc testClosureIterAux(it: iterator(): int, exceptionExpected: bool, expectedResults: varargs[int]) =
|
||||||
closureIterResult.setLen(0)
|
closureIterResult.setLen(0)
|
||||||
|
|
@ -21,7 +19,7 @@ proc testClosureIterAux(it: iterator(): int, exceptionExpected: bool, expectedRe
|
||||||
try:
|
try:
|
||||||
for i in it():
|
for i in it():
|
||||||
closureIterResult.add(i)
|
closureIterResult.add(i)
|
||||||
except TestException:
|
except TestError:
|
||||||
exceptionCaught = true
|
exceptionCaught = true
|
||||||
|
|
||||||
if closureIterResult != @expectedResults or exceptionCaught != exceptionExpected:
|
if closureIterResult != @expectedResults or exceptionCaught != exceptionExpected:
|
||||||
|
|
@ -39,8 +37,8 @@ proc test(it: iterator(): int, expectedResults: varargs[int]) =
|
||||||
proc testExc(it: iterator(): int, expectedResults: varargs[int]) =
|
proc testExc(it: iterator(): int, expectedResults: varargs[int]) =
|
||||||
testClosureIterAux(it, true, expectedResults)
|
testClosureIterAux(it, true, expectedResults)
|
||||||
|
|
||||||
proc raiseException() =
|
proc raiseTestError() =
|
||||||
raise newException(TestException, "Test exception!")
|
raise newException(TestError, "Test exception!")
|
||||||
|
|
||||||
block:
|
block:
|
||||||
iterator it(): int {.closure.} =
|
iterator it(): int {.closure.} =
|
||||||
|
|
@ -58,8 +56,8 @@ block:
|
||||||
yield 0
|
yield 0
|
||||||
try:
|
try:
|
||||||
checkpoint(1)
|
checkpoint(1)
|
||||||
raiseException()
|
raiseTestError()
|
||||||
except TestException:
|
except TestError:
|
||||||
checkpoint(2)
|
checkpoint(2)
|
||||||
yield 3
|
yield 3
|
||||||
checkpoint(4)
|
checkpoint(4)
|
||||||
|
|
@ -89,7 +87,7 @@ block:
|
||||||
yield 0
|
yield 0
|
||||||
try:
|
try:
|
||||||
yield 1
|
yield 1
|
||||||
raiseException()
|
raiseTestError()
|
||||||
yield 2
|
yield 2
|
||||||
finally:
|
finally:
|
||||||
checkpoint(3)
|
checkpoint(3)
|
||||||
|
|
@ -103,8 +101,8 @@ block:
|
||||||
iterator it(): int {.closure.} =
|
iterator it(): int {.closure.} =
|
||||||
try:
|
try:
|
||||||
try:
|
try:
|
||||||
raiseException()
|
raiseTestError()
|
||||||
except AnotherException:
|
except AnotherError:
|
||||||
yield 123
|
yield 123
|
||||||
finally:
|
finally:
|
||||||
checkpoint(3)
|
checkpoint(3)
|
||||||
|
|
@ -117,8 +115,8 @@ block:
|
||||||
iterator it(): int {.closure.} =
|
iterator it(): int {.closure.} =
|
||||||
try:
|
try:
|
||||||
yield 1
|
yield 1
|
||||||
raiseException()
|
raiseTestError()
|
||||||
except AnotherException:
|
except AnotherError:
|
||||||
checkpoint(123)
|
checkpoint(123)
|
||||||
finally:
|
finally:
|
||||||
checkpoint(2)
|
checkpoint(2)
|
||||||
|
|
@ -134,12 +132,12 @@ block:
|
||||||
yield 1
|
yield 1
|
||||||
try:
|
try:
|
||||||
yield 2
|
yield 2
|
||||||
raiseException()
|
raiseTestError()
|
||||||
except AnotherException:
|
except AnotherError:
|
||||||
yield 123
|
yield 123
|
||||||
finally:
|
finally:
|
||||||
yield 3
|
yield 3
|
||||||
except AnotherException:
|
except AnotherError:
|
||||||
yield 124
|
yield 124
|
||||||
finally:
|
finally:
|
||||||
yield 4
|
yield 4
|
||||||
|
|
@ -170,10 +168,10 @@ block:
|
||||||
try:
|
try:
|
||||||
try:
|
try:
|
||||||
yield 0
|
yield 0
|
||||||
raiseException()
|
raiseTestError()
|
||||||
finally:
|
finally:
|
||||||
checkpoint(1)
|
checkpoint(1)
|
||||||
except TestException:
|
except TestError:
|
||||||
yield 2
|
yield 2
|
||||||
return
|
return
|
||||||
finally:
|
finally:
|
||||||
|
|
@ -188,10 +186,10 @@ block:
|
||||||
try:
|
try:
|
||||||
try:
|
try:
|
||||||
yield 0
|
yield 0
|
||||||
raiseException()
|
raiseTestError()
|
||||||
finally:
|
finally:
|
||||||
return # Return in finally should stop exception propagation
|
return # Return in finally should stop exception propagation
|
||||||
except AnotherException:
|
except AnotherError:
|
||||||
yield 2
|
yield 2
|
||||||
return
|
return
|
||||||
finally:
|
finally:
|
||||||
|
|
@ -228,9 +226,9 @@ block:
|
||||||
var foo = 123
|
var foo = 123
|
||||||
let i = try:
|
let i = try:
|
||||||
yield 0
|
yield 0
|
||||||
raiseException()
|
raiseTestError()
|
||||||
1
|
1
|
||||||
except TestException as e:
|
except TestError as e:
|
||||||
assert(e.msg == "Test exception!")
|
assert(e.msg == "Test exception!")
|
||||||
case foo
|
case foo
|
||||||
of 1:
|
of 1:
|
||||||
|
|
@ -262,9 +260,9 @@ block:
|
||||||
template tryexcept: int =
|
template tryexcept: int =
|
||||||
try:
|
try:
|
||||||
yield 1
|
yield 1
|
||||||
raiseException()
|
raiseTestError()
|
||||||
123
|
123
|
||||||
except TestException:
|
except TestError:
|
||||||
yield 2
|
yield 2
|
||||||
checkpoint(3)
|
checkpoint(3)
|
||||||
4
|
4
|
||||||
|
|
@ -323,11 +321,11 @@ block:
|
||||||
for i in 0 .. 1:
|
for i in 0 .. 1:
|
||||||
try:
|
try:
|
||||||
yield 1
|
yield 1
|
||||||
raiseException()
|
raiseTestError()
|
||||||
except TestException as e:
|
except TestError as e:
|
||||||
doAssert(e.msg == "Test exception!")
|
doAssert(e.msg == "Test exception!")
|
||||||
yield 2
|
yield 2
|
||||||
except AnotherException:
|
except AnotherError:
|
||||||
yield 123
|
yield 123
|
||||||
except:
|
except:
|
||||||
yield 1234
|
yield 1234
|
||||||
|
|
@ -497,5 +495,3 @@ block: #17849 - yield in case subject
|
||||||
yield 5
|
yield 5
|
||||||
|
|
||||||
test(it, 1, 2, 13, 5)
|
test(it, 1, 2, 13, 5)
|
||||||
|
|
||||||
echo "ok"
|
|
||||||
|
|
|
||||||
|
|
@ -395,7 +395,7 @@ block:
|
||||||
template bar2[F,T](x: FooUn[F,T]): int = 1
|
template bar2[F,T](x: FooUn[F,T]): int = 1
|
||||||
template bar2[F,T1,T2](x: FooBi[F,T1,T2]): int = 2
|
template bar2[F,T1,T2](x: FooBi[F,T1,T2]): int = 2
|
||||||
|
|
||||||
proc test(x: any, n: int) =
|
proc test(x: auto, n: int) =
|
||||||
doAssert(foo1(x) == n)
|
doAssert(foo1(x) == n)
|
||||||
doAssert(foo2(x) == n)
|
doAssert(foo2(x) == n)
|
||||||
doAssert(bar1(x) == n)
|
doAssert(bar1(x) == n)
|
||||||
|
|
|
||||||
|
|
@ -94,7 +94,7 @@ block generic_templates:
|
||||||
|
|
||||||
var i3: int = t1[int]("xx")
|
var i3: int = t1[int]("xx")
|
||||||
|
|
||||||
|
from strutils import contains
|
||||||
|
|
||||||
block tgetast_typeliar:
|
block tgetast_typeliar:
|
||||||
proc error(s: string) = quit s
|
proc error(s: string) = quit s
|
||||||
|
|
@ -111,7 +111,9 @@ block tgetast_typeliar:
|
||||||
var message : NimNode = newLit(condition.repr)
|
var message : NimNode = newLit(condition.repr)
|
||||||
# echo message
|
# echo message
|
||||||
result = getAst assertOrReturn2(condition, message)
|
result = getAst assertOrReturn2(condition, message)
|
||||||
echo result.repr
|
# echo result.repr
|
||||||
|
let s = result.repr
|
||||||
|
doAssert """error("Assertion failed:""" in s
|
||||||
|
|
||||||
proc point(size: int16): tuple[x, y: int16] =
|
proc point(size: int16): tuple[x, y: int16] =
|
||||||
# returns random point in square area with given `size`
|
# returns random point in square area with given `size`
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,7 @@ proc concreteProc(x: int) =
|
||||||
forStatic i, 0..3:
|
forStatic i, 0..3:
|
||||||
echo i
|
echo i
|
||||||
|
|
||||||
proc genericProc(x: any) =
|
proc genericProc(x: auto) =
|
||||||
forStatic i, 0..3:
|
forStatic i, 0..3:
|
||||||
echo i
|
echo i
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue