diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2017-02-07 11:13:11 +0100 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2017-02-07 11:13:11 +0100 |
commit | b5b9c7d2e2839767fc514d7499b31d45eb732150 (patch) | |
tree | 87ab3e3a1db0b3d61ba1f26b4d6e40a91c6af2e6 /tools/nimsuggest/crashtester.nim | |
parent | 29f97f8cb1024d66b050a60f0cbffe19c99b3d7a (diff) | |
download | Nim-b5b9c7d2e2839767fc514d7499b31d45eb732150.tar.gz |
added crashtester tool
Diffstat (limited to 'tools/nimsuggest/crashtester.nim')
-rw-r--r-- | tools/nimsuggest/crashtester.nim | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/tools/nimsuggest/crashtester.nim b/tools/nimsuggest/crashtester.nim new file mode 100644 index 000000000..4b3ba4026 --- /dev/null +++ b/tools/nimsuggest/crashtester.nim @@ -0,0 +1,52 @@ + + +import strutils, os, osproc, streams + +const + DummyEof = "!EOF!" + +proc getPosition(s: string): (int, int) = + result = (1, 1) + var col = 0 + for i in 0..<s.len: + if s[i] == '\L': + inc result[0] + col = 0 + else: + inc col + result[1] = col+1 + +proc callNimsuggest() = + let cl = parseCmdLine("nimsuggest --tester temp000.nim") + var p = startProcess(command=cl[0], args=cl[1 .. ^1], + options={poStdErrToStdOut, poUsePath, + poInteractive, poDemon}) + let outp = p.outputStream + let inp = p.inputStream + var report = "" + var a = newStringOfCap(120) + let contents = readFile("tools/nimsuggest/crashtester.nim") + try: + # read and ignore anything nimsuggest says at startup: + while outp.readLine(a): + if a == DummyEof: break + + var line = 0 + for i in 0..< contents.len: + let slic = contents[0..i] + writeFile("temp000.nim", slic) + let (line, col) = getPosition(slic) + inp.writeLine("sug temp000.nim:$#:$#" % [$line, $col]) + inp.flush() + var answer = "" + while outp.readLine(a): + if a == DummyEof: break + answer.add a + answer.add '\L' + echo answer + finally: + inp.writeLine("quit") + inp.flush() + close(p) + +callNimsuggest() |