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:
Timothee Cour
2021-08-08 10:28:49 -07:00
committed by GitHub
parent 9269a72f6f
commit 24445d31b3
7 changed files with 38 additions and 39 deletions

View File

@@ -588,7 +588,7 @@ proc runJoinedTest(r: var TResults, cat: Category, testsDir: string, options: st
except ValueError:
# e.g. for `tests/navigator/tincludefile.nim` which have multiple
# 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
if isJoinableSpec(spec):
specs.add spec

View File

@@ -28,6 +28,7 @@ hint("Processing", off)
# switch("define", "nimTestsEnableFlaky")
# 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
# sync with `kochdocs.docDefines` or refactor.

View File

@@ -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
x: int
proc foo*(b: any) =
proc foo*(b: auto) =
var o: MyObj
echo b.baz, " ", o.x.baz, " ", b.baz()

View File

@@ -1,17 +1,15 @@
discard """
targets: "c"
output: "ok"
targets: "c cpp"
"""
var closureIterResult = newSeq[int]()
# XXX Investigate why this fails now for 'nim cpp'
var closureIterResult = newSeq[int]()
proc checkpoint(arg: int) =
closureIterResult.add(arg)
type
TestException = object of Exception
AnotherException = object of Exception
TestError = object of CatchableError
AnotherError = object of CatchableError
proc testClosureIterAux(it: iterator(): int, exceptionExpected: bool, expectedResults: varargs[int]) =
closureIterResult.setLen(0)
@@ -21,7 +19,7 @@ proc testClosureIterAux(it: iterator(): int, exceptionExpected: bool, expectedRe
try:
for i in it():
closureIterResult.add(i)
except TestException:
except TestError:
exceptionCaught = true
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]) =
testClosureIterAux(it, true, expectedResults)
proc raiseException() =
raise newException(TestException, "Test exception!")
proc raiseTestError() =
raise newException(TestError, "Test exception!")
block:
iterator it(): int {.closure.} =
@@ -58,8 +56,8 @@ block:
yield 0
try:
checkpoint(1)
raiseException()
except TestException:
raiseTestError()
except TestError:
checkpoint(2)
yield 3
checkpoint(4)
@@ -89,7 +87,7 @@ block:
yield 0
try:
yield 1
raiseException()
raiseTestError()
yield 2
finally:
checkpoint(3)
@@ -103,8 +101,8 @@ block:
iterator it(): int {.closure.} =
try:
try:
raiseException()
except AnotherException:
raiseTestError()
except AnotherError:
yield 123
finally:
checkpoint(3)
@@ -117,8 +115,8 @@ block:
iterator it(): int {.closure.} =
try:
yield 1
raiseException()
except AnotherException:
raiseTestError()
except AnotherError:
checkpoint(123)
finally:
checkpoint(2)
@@ -134,12 +132,12 @@ block:
yield 1
try:
yield 2
raiseException()
except AnotherException:
raiseTestError()
except AnotherError:
yield 123
finally:
yield 3
except AnotherException:
except AnotherError:
yield 124
finally:
yield 4
@@ -170,10 +168,10 @@ block:
try:
try:
yield 0
raiseException()
raiseTestError()
finally:
checkpoint(1)
except TestException:
except TestError:
yield 2
return
finally:
@@ -188,10 +186,10 @@ block:
try:
try:
yield 0
raiseException()
raiseTestError()
finally:
return # Return in finally should stop exception propagation
except AnotherException:
except AnotherError:
yield 2
return
finally:
@@ -228,9 +226,9 @@ block:
var foo = 123
let i = try:
yield 0
raiseException()
raiseTestError()
1
except TestException as e:
except TestError as e:
assert(e.msg == "Test exception!")
case foo
of 1:
@@ -262,9 +260,9 @@ block:
template tryexcept: int =
try:
yield 1
raiseException()
raiseTestError()
123
except TestException:
except TestError:
yield 2
checkpoint(3)
4
@@ -323,11 +321,11 @@ block:
for i in 0 .. 1:
try:
yield 1
raiseException()
except TestException as e:
raiseTestError()
except TestError as e:
doAssert(e.msg == "Test exception!")
yield 2
except AnotherException:
except AnotherError:
yield 123
except:
yield 1234
@@ -497,5 +495,3 @@ block: #17849 - yield in case subject
yield 5
test(it, 1, 2, 13, 5)
echo "ok"

View File

@@ -395,7 +395,7 @@ block:
template bar2[F,T](x: FooUn[F,T]): int = 1
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(foo2(x) == n)
doAssert(bar1(x) == n)

View File

@@ -94,7 +94,7 @@ block generic_templates:
var i3: int = t1[int]("xx")
from strutils import contains
block tgetast_typeliar:
proc error(s: string) = quit s
@@ -111,7 +111,9 @@ block tgetast_typeliar:
var message : NimNode = newLit(condition.repr)
# echo 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] =
# returns random point in square area with given `size`

View File

@@ -72,7 +72,7 @@ proc concreteProc(x: int) =
forStatic i, 0..3:
echo i
proc genericProc(x: any) =
proc genericProc(x: auto) =
forStatic i, 0..3:
echo i