Debian Codegraph @

tests/TestScripts/testPartialTestCaseEvent.py

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