added crashtester tool
This commit is contained in:
parent
29f97f8cb1
commit
b5b9c7d2e2
1 changed files with 52 additions and 0 deletions
52
tools/nimsuggest/crashtester.nim
Normal file
52
tools/nimsuggest/crashtester.nim
Normal file
|
|
@ -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()
|
||||
Loading…
Add table
Add a link
Reference in a new issue