format_tap.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # -*- coding: utf-8 -*-
  2. # Copyright 2019 The Matrix.org Foundation C.I.C.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. import sys
  16. from tap.parser import Parser
  17. from tap.line import Result, Unknown, Diagnostic
  18. out = ["### TAP Output for " + sys.argv[2]]
  19. p = Parser()
  20. in_error = False
  21. for line in p.parse_file(sys.argv[1]):
  22. if isinstance(line, Result):
  23. if in_error:
  24. out.append("")
  25. out.append("</pre></code></details>")
  26. out.append("")
  27. out.append("----")
  28. out.append("")
  29. in_error = False
  30. if not line.ok and not line.todo:
  31. in_error = True
  32. out.append("FAILURE Test #%d: ``%s``" % (line.number, line.description))
  33. out.append("")
  34. out.append("<details><summary>Show log</summary><code><pre>")
  35. elif isinstance(line, Diagnostic) and in_error:
  36. out.append(line.text)
  37. if out:
  38. for line in out[:-3]:
  39. print(line)