From e0c2bfba934523d381f2422d301d6d7b82f2b06c Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Sat, 9 Feb 2019 00:21:31 -0800 Subject: [PATCH] fix #9880 index out of bounds (remaining cases); revives #10228 --- compiler/vm.nim | 2 +- lib/core/typeinfo.nim | 2 +- lib/pure/collections/sharedstrings.nim | 2 +- lib/pure/os.nim | 2 +- lib/system/jssys.nim | 2 +- tests/exception/tindexerrorformatbounds.nim | 41 +++++---------------- 6 files changed, 15 insertions(+), 36 deletions(-) diff --git a/compiler/vm.nim b/compiler/vm.nim index 43eac2414d7c..f289ca9f67c4 100644 --- a/compiler/vm.nim +++ b/compiler/vm.nim @@ -11,7 +11,7 @@ ## An instruction is 1-3 int32s in memory, it is a register based VM. import ast except getstr -import system/helpers2 +import system/indexerrors import strutils, astalgo, msgs, vmdef, vmgen, nimsets, types, passes, diff --git a/lib/core/typeinfo.nim b/lib/core/typeinfo.nim index a4573ff402a4..13ffb28cc047 100644 --- a/lib/core/typeinfo.nim +++ b/lib/core/typeinfo.nim @@ -20,7 +20,7 @@ include "system/inclrtl.nim" include "system/hti.nim" -import system/helpers2 +import system/indexerrors {.pop.} diff --git a/lib/pure/collections/sharedstrings.nim b/lib/pure/collections/sharedstrings.nim index b283cd4b10e5..ca52ec63c4a7 100644 --- a/lib/pure/collections/sharedstrings.nim +++ b/lib/pure/collections/sharedstrings.nim @@ -12,7 +12,7 @@ type UncheckedCharArray = UncheckedArray[char] -import system/helpers2 +import system/indexerrors type Buffer = ptr object diff --git a/lib/pure/os.nim b/lib/pure/os.nim index 6813393542bc..0b9c8babc846 100644 --- a/lib/pure/os.nim +++ b/lib/pure/os.nim @@ -47,7 +47,7 @@ include "system/inclrtl" import - strutils, pathnorm, system/helpers2 + strutils, pathnorm, system/indexerrors const weirdTarget = defined(nimscript) or defined(js) diff --git a/lib/system/jssys.nim b/lib/system/jssys.nim index 20a46f1b90c6..27dd9b0209b3 100644 --- a/lib/system/jssys.nim +++ b/lib/system/jssys.nim @@ -7,7 +7,7 @@ # distribution, for details about the copyright. # -import system/helpers2 +import system/indexerrors proc log*(s: cstring) {.importc: "console.log", varargs, nodecl.} diff --git a/tests/exception/tindexerrorformatbounds.nim b/tests/exception/tindexerrorformatbounds.nim index a5757e4e10b2..c1e7a731e42f 100644 --- a/tests/exception/tindexerrorformatbounds.nim +++ b/tests/exception/tindexerrorformatbounds.nim @@ -1,6 +1,4 @@ -import os -import strutils - +import os, osproc, strutils const characters = "abcdefghijklmnopqrstuvwxyz" var s: string @@ -13,40 +11,21 @@ block: discard s[0..999] except IndexError: let msg = getCurrentExceptionMsg() - let expected = "(i:$#) <= (n:$#)" % [$len(s), $(len(s)-1)] - doAssert msg.contains expected + let expected = "(i: $#) <= (n: $#)" % [$len(s), $(len(s)-1)] + doAssert msg.contains expected, $(msg, expected) block: try: discard paramStr(999) except IndexError: let msg = getCurrentExceptionMsg() - let expected = "(i:999) <= (n:0)" + let expected = "(i: 999) <= (n: 0)" doAssert msg.contains expected -static: +block: const nim = getCurrentCompilerExe() - - block: - let ret = gorgeEx(nim & " e testindexerroroutput.nims test1") - let expected = "(i:3) <= (n:2)" - doAssert ret.exitCode != 0 - doAssert ret.output.contains expected - - block: - let ret = gorgeEx(nim & " e testindexerroroutput.nims test2") - let expected = "(i:3) <= (n:2)" - doAssert ret.exitCode != 0 - doAssert ret.output.contains expected - - block: - let ret = gorgeEx(nim & " e testindexerroroutput.nims test3") - let expected = "(i:3) <= (n:2)" - doAssert ret.exitCode != 0 - doAssert ret.output.contains expected - - block: - let ret = gorgeEx(nim & " e testindexerroroutput.nims test4") - let expected = "(i:3) <= (n:2)" - doAssert ret.exitCode != 0 - doAssert ret.output.contains expected + for i in 1..4: + let (outp, errC) = execCmdEx("$# e tests/exception/testindexerroroutput.nims test$#" % [nim, $i]) + let expected = "(i: 3) <= (n: 2)" + doAssert errC != 0 + doAssert outp.contains expected, $(outp, errC, expected, i)