diff options
author | Yuriy Glukhov <yuriy.glukhov@gmail.com> | 2018-06-15 19:46:17 +0300 |
---|---|---|
committer | Yuriy Glukhov <yuriy.glukhov@gmail.com> | 2018-06-15 19:46:17 +0300 |
commit | 78cbf6734a2bb0514703232e623fac344f4b7b74 (patch) | |
tree | 7fb7954e342dfbd9fe759b2de4e589ae40bfab11 /tests/overflw | |
parent | 951157a4e9937eea895a95df0bd46c03b330f7c2 (diff) | |
download | Nim-78cbf6734a2bb0514703232e623fac344f4b7b74.tar.gz |
Added more tests to toverflw
Diffstat (limited to 'tests/overflw')
-rw-r--r-- | tests/overflw/toverflw.nim | 75 |
1 files changed, 69 insertions, 6 deletions
diff --git a/tests/overflw/toverflw.nim b/tests/overflw/toverflw.nim index 771a43303..20bc56a53 100644 --- a/tests/overflw/toverflw.nim +++ b/tests/overflw/toverflw.nim @@ -1,21 +1,84 @@ discard """ file: "toverflw.nim" - output: "the computation overflowed" + output: "ok" + cmd: "nim $target -d:release $options $file" + """ # Tests nim's ability to detect overflows {.push overflowChecks: on.} var - a, b: int -a = high(int) -b = -2 + a = high(int) + b = -2 + overflowDetected = false + try: writeLine(stdout, b - a) except OverflowError: - writeLine(stdout, "the computation overflowed") + overflowDetected = true {.pop.} # overflow check -#OUT the computation overflowed + +doAssert(overflowDetected) + +block: # Overflow checks in a proc + var + a = high(int) + b = -2 + overflowDetected = false + + {.push overflowChecks: on.} + proc foo() = + let c = b - a + {.pop.} + + try: + foo() + except OverflowError: + overflowDetected = true + + doAssert(overflowDetected) + +block: # Overflow checks in a forward declared proc + var + a = high(int) + b = -2 + overflowDetected = false + + proc foo() + + {.push overflowChecks: on.} + proc foo() = + let c = b - a + {.pop.} + + try: + foo() + except OverflowError: + overflowDetected = true + + doAssert(overflowDetected) + +block: # Overflow checks doesn't affect fwd declaration + var + a = high(int) + b = -2 + overflowDetected = false + + {.push overflowChecks: on.} + proc foo() + {.pop.} + + proc foo() = + let c = b - a + + try: + foo() + except OverflowError: + overflowDetected = true + + doAssert(not overflowDetected) +echo "ok" |