crashtester.nim 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import strutils, os, osproc, streams
  2. const
  3. DummyEof = "!EOF!"
  4. proc getPosition(s: string): (int, int) =
  5. result = (1, 1)
  6. var col = 0
  7. for i in 0..<s.len:
  8. if s[i] == '\L':
  9. inc result[0]
  10. col = 0
  11. else:
  12. inc col
  13. result[1] = col+1
  14. proc callNimsuggest() =
  15. let cl = parseCmdLine("nimsuggest --tester temp000.nim")
  16. var p = startProcess(command=cl[0], args=cl[1 .. ^1],
  17. options={poStdErrToStdOut, poUsePath,
  18. poInteractive, poDaemon})
  19. let outp = p.outputStream
  20. let inp = p.inputStream
  21. var report = ""
  22. var a = newStringOfCap(120)
  23. let contents = readFile("tools/nimsuggest/crashtester.nim")
  24. try:
  25. # read and ignore anything nimsuggest says at startup:
  26. while outp.readLine(a):
  27. if a == DummyEof: break
  28. var line = 0
  29. for i in 0 ..< contents.len:
  30. let slic = contents[0..i]
  31. writeFile("temp000.nim", slic)
  32. let (line, col) = getPosition(slic)
  33. inp.writeLine("sug temp000.nim:$#:$#" % [$line, $col])
  34. inp.flush()
  35. var answer = ""
  36. while outp.readLine(a):
  37. if a == DummyEof: break
  38. answer.add a
  39. answer.add '\L'
  40. echo answer
  41. finally:
  42. inp.writeLine("quit")
  43. inp.flush()
  44. close(p)
  45. callNimsuggest()