testPartialTestCaseEvent.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #!/usr/bin/env python3
  2. # Copyright Catch2 Authors
  3. # Distributed under the Boost Software License, Version 1.0.
  4. # (See accompanying file LICENSE_1_0.txt or copy at
  5. # https://www.boost.org/LICENSE_1_0.txt)
  6. # SPDX-License-Identifier: BSL-1.0
  7. """
  8. This test script verifies that the testCasePartial{Starting,Ended} reporter
  9. events fire properly. This is done by calling a test binary compiled with
  10. reporter that reports specifically testCase* events, and verifying the
  11. outputs match what we expect.
  12. """
  13. import subprocess
  14. import sys
  15. expected_section_output = '''\
  16. TestCaseStarting: section
  17. TestCaseStartingPartial: section#0
  18. TestCasePartialEnded: section#0
  19. TestCaseStartingPartial: section#1
  20. TestCasePartialEnded: section#1
  21. TestCaseStartingPartial: section#2
  22. TestCasePartialEnded: section#2
  23. TestCaseStartingPartial: section#3
  24. TestCasePartialEnded: section#3
  25. TestCaseEnded: section
  26. '''
  27. expected_generator_output = '''\
  28. TestCaseStarting: generator
  29. TestCaseStartingPartial: generator#0
  30. TestCasePartialEnded: generator#0
  31. TestCaseStartingPartial: generator#1
  32. TestCasePartialEnded: generator#1
  33. TestCaseStartingPartial: generator#2
  34. TestCasePartialEnded: generator#2
  35. TestCaseStartingPartial: generator#3
  36. TestCasePartialEnded: generator#3
  37. TestCaseEnded: generator
  38. '''
  39. from typing import List
  40. def get_test_output(test_exe: str, sections: bool) -> List[str]:
  41. cmd = [test_exe, '--reporter', 'partial']
  42. if sections:
  43. cmd.append('section')
  44. else:
  45. cmd.append('generator')
  46. ret = subprocess.run(cmd,
  47. stdout = subprocess.PIPE,
  48. stderr = subprocess.PIPE,
  49. timeout = 10,
  50. check = True,
  51. universal_newlines = True)
  52. return ret.stdout
  53. def main():
  54. test_exe, = sys.argv[1:]
  55. actual_section_output = get_test_output(test_exe, sections = True)
  56. assert actual_section_output == expected_section_output, (
  57. 'Sections\nActual:\n{}\nExpected:\n{}\n'.format(actual_section_output, expected_section_output))
  58. actual_generator_output = get_test_output(test_exe, sections = False)
  59. assert actual_generator_output == expected_generator_output, (
  60. 'Generators\nActual:\n{}\nExpected:\n{}\n'.format(actual_generator_output, expected_generator_output))
  61. if __name__ == '__main__':
  62. sys.exit(main())