format_tap.py 844 B

123456789101112131415161718192021222324252627282930313233
  1. import sys
  2. from tap.parser import Parser
  3. from tap.line import Result, Unknown, Diagnostic
  4. out = ["### TAP Output for " + sys.argv[2]]
  5. p = Parser()
  6. in_error = False
  7. for line in p.parse_file(sys.argv[1]):
  8. if isinstance(line, Result):
  9. if in_error:
  10. out.append("")
  11. out.append("</pre></code></details>")
  12. out.append("")
  13. out.append("----")
  14. out.append("")
  15. in_error = False
  16. if not line.ok and not line.todo:
  17. in_error = True
  18. out.append("FAILURE Test #%d: ``%s``" % (line.number, line.description))
  19. out.append("")
  20. out.append("<details><summary>Show log</summary><code><pre>")
  21. elif isinstance(line, Diagnostic) and in_error:
  22. out.append(line.text)
  23. if out:
  24. for line in out[:-3]:
  25. print(line)