add proper test for proof of stack allocation (#23)

This commit is contained in:
Timothee Cour 2018-08-01 12:28:02 -07:00 committed by Yuriy Glukhov
parent 179c03822a
commit 4e6835d041

View File

@ -34,3 +34,14 @@ suite "Stack arrays":
expect RangeError:
arr[3] = "another test"
test "proof of stack allocation":
proc fun() =
# NOTE: has to be inside a proc otherwise x1 not allocated on stack.
var x1 = 0
var arr = allocStackArray(int, 3)
check:
# stack can go either up or down, hence `abs`.
# 1024 should be large enough (was 312 on OSX).
abs(cast[int](x1.addr) - cast[int](addr(arr[0]))) < 1024
fun()