Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/tests/TestScripts
diff options
context:
space:
mode:
authorMartin Hořeňovský2021-09-12 00:00:47 +0200
committerMartin Hořeňovský2021-09-14 13:19:45 +0200
commit10fb93cce8cb878fdfe8faa118b531258db96a26 (patch)
tree41eadf4802932051def7770b52a4a7fe94260c80 /tests/TestScripts
parent4dcf8382c70c25a3ccfbe5d9e37276adf7c6058f (diff)
downloadcatch3-10fb93cce8cb878fdfe8faa118b531258db96a26.tar.gz
Add new reporter event called for each test case enter/exit
This means that e.g. for `TEST_CASE` with two sibling `SECTION`s the event will fire twice, because the `TEST_CASE` will be entered twice. Closes #2107 (the event mentioned there already exists, but this is its counterpart that we also want to provide to users)
Diffstat (limited to 'tests/TestScripts')
-rwxr-xr-xtests/TestScripts/testPartialTestCaseEvent.py72
1 files changed, 72 insertions, 0 deletions
diff --git a/tests/TestScripts/testPartialTestCaseEvent.py b/tests/TestScripts/testPartialTestCaseEvent.py
new file mode 100755
index 00000000..d119e6da
--- /dev/null
+++ b/tests/TestScripts/testPartialTestCaseEvent.py
@@ -0,0 +1,72 @@
+#!/usr/bin/env python3
+
+"""
+This test script verifies that the testCasePartial{Starting,Ended} reporter
+events fire properly. This is done by calling a test binary compiled with
+reporter that reports specifically testCase* events, and verifying the
+outputs match what we expect.
+"""
+
+import subprocess
+import sys
+
+expected_section_output = '''\
+TestCaseStarting: section
+TestCaseStartingPartial: section#0
+TestCasePartialEnded: section#0
+TestCaseStartingPartial: section#1
+TestCasePartialEnded: section#1
+TestCaseStartingPartial: section#2
+TestCasePartialEnded: section#2
+TestCaseStartingPartial: section#3
+TestCasePartialEnded: section#3
+TestCaseEnded: section
+'''
+
+expected_generator_output = '''\
+TestCaseStarting: generator
+TestCaseStartingPartial: generator#0
+TestCasePartialEnded: generator#0
+TestCaseStartingPartial: generator#1
+TestCasePartialEnded: generator#1
+TestCaseStartingPartial: generator#2
+TestCasePartialEnded: generator#2
+TestCaseStartingPartial: generator#3
+TestCasePartialEnded: generator#3
+TestCaseEnded: generator
+'''
+
+
+from typing import List
+
+def get_test_output(test_exe: str, sections: bool) -> List[str]:
+ cmd = [test_exe, '--reporter', 'partial']
+ if sections:
+ cmd.append('section')
+ else:
+ cmd.append('generator')
+
+ ret = subprocess.run(cmd,
+ stdout = subprocess.PIPE,
+ stderr = subprocess.PIPE,
+ timeout = 10,
+ check = True,
+ universal_newlines = True)
+
+ return ret.stdout
+
+def main():
+ test_exe, = sys.argv[1:]
+ actual_section_output = get_test_output(test_exe, sections = True)
+
+ assert actual_section_output == expected_section_output, (
+ 'Sections\nActual:\n{}\nExpected:\n{}\n'.format(actual_section_output, expected_section_output))
+
+ actual_generator_output = get_test_output(test_exe, sections = False)
+ assert actual_generator_output == expected_generator_output, (
+ 'Generators\nActual:\n{}\nExpected:\n{}\n'.format(actual_generator_output, expected_generator_output))
+
+
+
+if __name__ == '__main__':
+ sys.exit(main())