Skip to content

Commit

Permalink
use doAssert in tests (#16486)
Browse files Browse the repository at this point in the history
  • Loading branch information
ringabout authored Dec 28, 2020
1 parent f9a15db commit 6d442a4
Show file tree
Hide file tree
Showing 78 changed files with 1,075 additions and 1,075 deletions.
4 changes: 2 additions & 2 deletions tests/arc/tarcmisc.nim
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ let
n = @["c", "b"]
q = @[("c", "2"), ("b", "1")]

assert n.sortedByIt(it) == @["b", "c"], "fine"
assert q.sortedByIt(it[0]) == @[("b", "1"), ("c", "2")], "fails under arc"
doAssert n.sortedByIt(it) == @["b", "c"], "fine"
doAssert q.sortedByIt(it[0]) == @[("b", "1"), ("c", "2")], "fails under arc"


#------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion tests/arc/tasyncawait.nim
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ proc main =
let mem = getOccupiedMem()
main()

assert msgCount == swarmSize * messagesToSend
doAssert msgCount == swarmSize * messagesToSend
echo "result: ", msgCount
GC_fullCollect()
echo "memory: ", formatSize(getOccupiedMem() - mem)
2 changes: 1 addition & 1 deletion tests/arc/tasyncleak2.nim
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,5 @@ proc main(): Future[void] =
for i in 0..9:
waitFor main()
GC_fullCollect()
assert getOccupiedMem() < 1024
doAssert getOccupiedMem() < 1024
echo "success"
4 changes: 2 additions & 2 deletions tests/assign/tassign.nim
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ block tgenericassign:
var ret: seq[tuple[name: string, a: TAny]] = @[]
for i in 0 .. 8000:
var tup = ($name, newAny(nil, nil))
assert(tup[0] == "example")
doAssert(tup[0] == "example")
ret.add(tup)
assert(ret[ret.len()-1][0] == "example")
doAssert(ret[ret.len()-1][0] == "example")



Expand Down
4 changes: 2 additions & 2 deletions tests/async/t12221.nim
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ proc doubleSleep(hardSleep: int) {.async.} =
sleep(hardSleep)

template assertTime(target, timeTook: float): untyped {.dirty.} =
assert(timeTook*1000 > target - 1000, "Took too short, should've taken " &
doAssert(timeTook*1000 > target - 1000, "Took too short, should've taken " &
$target & "ms, but took " & $(timeTook*1000) & "ms")
assert(timeTook*1000 < target + 1000, "Took too long, should've taken " &
doAssert(timeTook*1000 < target + 1000, "Took too long, should've taken " &
$target & "ms, but took " & $(timeTook*1000) & "ms")

var
Expand Down
2 changes: 1 addition & 1 deletion tests/async/tasync_gcsafe.nim
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ discard """
'''
"""

assert compileOption("threads"), "this test will not do anything useful without --threads:on"
doAssert compileOption("threads"), "this test will not do anything useful without --threads:on"

import asyncdispatch

Expand Down
2 changes: 1 addition & 1 deletion tests/async/tasync_gcunsafe.nim
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ discard """
file: "asyncmacro.nim"
"""

assert compileOption("threads"), "this test will not do anything useful without --threads:on"
doAssert compileOption("threads"), "this test will not do anything useful without --threads:on"

import asyncdispatch

Expand Down
2 changes: 1 addition & 1 deletion tests/async/tasyncawait.nim
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@ while true:
poll()
if clientCount == swarmSize: break

assert msgCount == swarmSize * messagesToSend
doAssert msgCount == swarmSize * messagesToSend
doAssert msgCount == 2000
4 changes: 2 additions & 2 deletions tests/async/tasynceagain.nim
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ proc runServer() {.async.} =
var lastN = 0
while true:
let frame = await client.recv(FrameSize)
assert frame.len == FrameSize
doAssert frame.len == FrameSize
let n = frame[0..<6].parseInt()
echo "RCVD #", n, ": ", frame[0..80], "..."
if n != lastN + 1:
echo &"******** ERROR: Server received #{n}, but last was #{lastN}!"
assert n == lastN + 1
doAssert n == lastN + 1
lastN = n
await sleepAsync 100

Expand Down
4 changes: 2 additions & 2 deletions tests/async/tasyncnetudp.nim
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ while true:
if recvCount == swarmSize * messagesToSend:
break

assert msgCount == swarmSize * messagesToSend
assert sendports == recvports
doAssert msgCount == swarmSize * messagesToSend
doAssert sendports == recvports

echo msgCount
4 changes: 2 additions & 2 deletions tests/async/tasyncssl.nim
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,5 @@ when defined(ssl):
elif defined(linux) and int.sizeof == 8:
# currently: msgCount == 10
flakyAssert cond()
assert msgCount > 0
else: assert cond(), $msgCount
doAssert msgCount > 0
else: doAssert cond(), $msgCount
4 changes: 2 additions & 2 deletions tests/ccgbugs/t9286.nim
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ type Foo = ref object
i: int

proc next(foo: Foo): Option[Foo] =
try: assert(foo.i == 0)
try: doAssert(foo.i == 0)
except: return # 2º: none
return some(foo) # 1º: some

Expand All @@ -17,6 +17,6 @@ proc test =
while isSome(opt) and foo.i < 10:
inc(foo.i)
opt = next(foo) # 2º None
assert foo.i == 1, $foo.i
doAssert foo.i == 1, $foo.i

test()
2 changes: 1 addition & 1 deletion tests/ccgbugs/twrong_tupleconv.nim
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ iterator myitems*[T](a: var seq[T]): var T {.inline.} =
while i < L:
yield a[i]
inc(i)
assert(len(a) == L, "the length of the seq changed while iterating over it")
doAssert(len(a) == L, "the length of the seq changed while iterating over it")

# Works fine
var xs = @[1,2,3]
Expand Down
2 changes: 1 addition & 1 deletion tests/collections/tseq.nim
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ block tseq2:
# multiply two int sequences:
for i in 0..len(a)-1: result[i] = a[i] * b[i]

assert(@[1, 2, 3] * @[1, 2, 3] == @[1, 4, 9])
doAssert(@[1, 2, 3] * @[1, 2, 3] == @[1, 4, 9])



Expand Down
94 changes: 47 additions & 47 deletions tests/collections/ttables.nim
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,20 @@ block thashes:
var t = initTable[int,int]()
t[0] = 42
t[1] = t[0] + 1
assert(t[0] == 42)
assert(t[1] == 43)
doAssert(t[0] == 42)
doAssert(t[1] == 43)
let t2 = {1: 1, 2: 2}.toTable
assert(t2[2] == 2)
doAssert(t2[2] == 2)

# Test with char
block:
var t = initTable[char,int]()
t['0'] = 42
t['1'] = t['0'] + 1
assert(t['0'] == 42)
assert(t['1'] == 43)
doAssert(t['0'] == 42)
doAssert(t['1'] == 43)
let t2 = {'1': 1, '2': 2}.toTable
assert(t2['2'] == 2)
doAssert(t2['2'] == 2)

# Test with enum
block:
Expand All @@ -72,10 +72,10 @@ block thashes:
var t = initTable[E,int]()
t[eA] = 42
t[eB] = t[eA] + 1
assert(t[eA] == 42)
assert(t[eB] == 43)
doAssert(t[eA] == 42)
doAssert(t[eB] == 43)
let t2 = {eA: 1, eB: 2}.toTable
assert(t2[eB] == 2)
doAssert(t2[eB] == 2)

# Test with range
block:
Expand All @@ -84,10 +84,10 @@ block thashes:
var t = initTable[R,int]() # causes warning, why?
t[1] = 42 # causes warning, why?
t[2] = t[1] + 1
assert(t[1] == 42)
assert(t[2] == 43)
doAssert(t[1] == 42)
doAssert(t[2] == 43)
let t2 = {1.R: 1, 2.R: 2}.toTable
assert(t2[2.R] == 2)
doAssert(t2[2.R] == 2)

# Test which combines the generics for tuples + ordinals
block:
Expand All @@ -96,10 +96,10 @@ block thashes:
var t = initTable[(string, E, int, char), int]()
t[("a", eA, 0, '0')] = 42
t[("b", eB, 1, '1')] = t[("a", eA, 0, '0')] + 1
assert(t[("a", eA, 0, '0')] == 42)
assert(t[("b", eB, 1, '1')] == 43)
doAssert(t[("a", eA, 0, '0')] == 42)
doAssert(t[("b", eB, 1, '1')] == 43)
let t2 = {("a", eA, 0, '0'): 1, ("b", eB, 1, '1'): 2}.toTable
assert(t2[("b", eB, 1, '1')] == 2)
doAssert(t2[("b", eB, 1, '1')] == 2)

# Test to check if overloading is possible
# Unfortunately, this does not seem to work for int
Expand Down Expand Up @@ -165,9 +165,9 @@ block tableconstr:
ignoreExpr({2: 3, "key": "value"})

# NEW:
assert 56 in 50..100
doAssert 56 in 50..100

assert 56 in ..60
doAssert 56 in ..60


block ttables2:
Expand Down Expand Up @@ -239,8 +239,8 @@ block tablesref:
t[(1,1)] = "11"
for x in 0..1:
for y in 0..1:
assert t[(x,y)] == $x & $y
assert t.sortedPairs ==
doAssert t[(x,y)] == $x & $y
doAssert t.sortedPairs ==
@[((x: 0, y: 0), "00"), ((x: 0, y: 1), "01"), ((x: 1, y: 0), "10"), ((x: 1, y: 1), "11")]

block tableTest2:
Expand All @@ -253,31 +253,31 @@ block tablesref:
t["012"] = 67.9
t["123"] = 1.5 # test overwriting

assert t["123"] == 1.5
doAssert t["123"] == 1.5
try:
echo t["111"] # deleted
except KeyError:
discard
assert(not hasKey(t, "111"))
assert "111" notin t
doAssert(not hasKey(t, "111"))
doAssert "111" notin t

for key, val in items(data): t[key] = val.toFloat
for key, val in items(data): assert t[key] == val.toFloat
for key, val in items(data): doAssert t[key] == val.toFloat


block orderedTableTest1:
var t = newOrderedTable[string, int](2)
for key, val in items(data): t[key] = val
for key, val in items(data): assert t[key] == val
for key, val in items(data): doAssert t[key] == val
var i = 0
# `pairs` needs to yield in insertion order:
for key, val in pairs(t):
assert key == data[i][0]
assert val == data[i][1]
doAssert key == data[i][0]
doAssert val == data[i][1]
inc(i)

for key, val in mpairs(t): val = 99
for val in mvalues(t): assert val == 99
for val in mvalues(t): doAssert val == 99

block countTableTest1:
var s = data.toTable
Expand All @@ -286,11 +286,11 @@ block tablesref:
for x in [t, r]:
for k in s.keys:
x.inc(k)
assert x[k] == 1
doAssert x[k] == 1
x.inc("90", 3)
x.inc("12", 2)
x.inc("34", 1)
assert t.largest()[0] == "90"
doAssert t.largest()[0] == "90"

t.sort()
r.sort(SortOrder.Ascending)
Expand All @@ -301,9 +301,9 @@ block tablesref:
var i = 0
for (k, v) in ps:
case i
of 0: assert k == "90" and v == 4
of 1: assert k == "12" and v == 3
of 2: assert k == "34" and v == 2
of 0: doAssert k == "90" and v == 4
of 1: doAssert k == "12" and v == 3
of 2: doAssert k == "34" and v == 2
else: break
inc i

Expand All @@ -327,17 +327,17 @@ block tablesref:

block nilTest:
var i, j: TableRef[int, int] = nil
assert i == j
doAssert i == j
j = newTable[int, int]()
assert i != j
assert j != i
doAssert i != j
doAssert j != i
i = newTable[int, int]()
assert i == j
doAssert i == j

proc orderedTableSortTest() =
var t = newOrderedTable[string, int](2)
for key, val in items(data): t[key] = val
for key, val in items(data): assert t[key] == val
for key, val in items(data): doAssert t[key] == val
proc cmper(x, y: tuple[key: string, val: int]): int = cmp(x.key, y.key)
t.sort(cmper)
var i = 0
Expand Down Expand Up @@ -369,25 +369,25 @@ block tablesref:
t["test"] = 1.2345
t["111"] = 1.000043
t["123"] = 1.23
assert t.len() != 0
doAssert t.len() != 0
t.clear()
assert t.len() == 0
doAssert t.len() == 0

block clearOrderedTableTest:
var t = newOrderedTable[string, int](2)
for key, val in items(data): t[key] = val
assert t.len() != 0
doAssert t.len() != 0
t.clear()
assert t.len() == 0
doAssert t.len() == 0

block clearCountTableTest:
var t = newCountTable[string]()
t.inc("90", 3)
t.inc("12", 2)
t.inc("34", 1)
assert t.len() != 0
doAssert t.len() != 0
t.clear()
assert t.len() == 0
doAssert t.len() == 0

orderedTableSortTest()
echo "3"
Expand Down Expand Up @@ -415,7 +415,7 @@ block: # https://github.com/nim-lang/Nim/issues/13496
doAssert sortedPairs(t) == @[(15, 1), (17, 3), (19, 2)]
var s = newSeq[int]()
for v in t.values: s.add(v)
assert s.len == 3
doAssert s.len == 3
doAssert sortedItems(s) == @[1, 2, 3]
when t is OrderedTable|OrderedTableRef:
doAssert toSeq(t.keys) == @[15, 19, 17]
Expand All @@ -433,14 +433,14 @@ block: # https://github.com/nim-lang/Nim/issues/13496
block testNonPowerOf2:
var a = initTable[int, int](7)
a[1] = 10
assert a[1] == 10
doAssert a[1] == 10

var b = initTable[int, int](9)
b[1] = 10
assert b[1] == 10
doAssert b[1] == 10

block emptyOrdered:
var t1: OrderedTable[int, string]
var t2: OrderedTable[int, string]
assert t1 == t2
doAssert t1 == t2

Loading

0 comments on commit 6d442a4

Please sign in to comment.