Debian Codegraph @

llvm-project/llvm/utils/lit/tests/Inputs/googletest-format-respect-gtest-sharding-env-vars/DummySubDir/OneTest.py

raw
1 #!/usr/bin/env python
2
3 import os
4 import sys
5
6 if len(sys.argv) == 3 and sys.argv[1] == "--gtest_list_tests":
7 if sys.argv[2] != '--gtest_filter=-*DISABLED_*':
8 raise ValueError("unexpected argument: %s" % (sys.argv[2]))
9 print("""\
10 FirstTest.
11 subTestA
12 subTestB
13 subTestC
14 subTestD
15 ParameterizedTest/0.
16 subTest
17 ParameterizedTest/1.
18 subTest""")
19 sys.exit(0)
20 elif len(sys.argv) != 1:
21 # sharding and json output are specified using environment variables
22 raise ValueError("unexpected argument: %r" % (' '.join(sys.argv[1:])))
23
24 for e in ['GTEST_TOTAL_SHARDS', 'GTEST_SHARD_INDEX', 'GTEST_OUTPUT']:
25 if e not in os.environ:
26 raise ValueError("missing environment variables: " + e)
27
28 if not os.environ['GTEST_OUTPUT'].startswith('json:'):
29 raise ValueError("must emit json output: " + os.environ['GTEST_OUTPUT'])
30
31 output = """\
32 {
33 "random_seed": 123,
34 "testsuites": [
35 {
36 "name": "FirstTest",
37 "testsuite": [
38 {
39 "name": "subTestA",
40 "result": "COMPLETED",
41 "time": "0.001s"
42 },
43 {
44 "name": "subTestB",
45 "result": "COMPLETED",
46 "time": "0.001s",
47 "failures": [
48 {
49 "failure": "I am subTest B, I FAIL\\nAnd I have two lines of output",
50 "type": ""
51 }
52 ]
53 },
54 {
55 "name": "subTestC",
56 "result": "SKIPPED",
57 "time": "0.001s"
58 },
59 {
60 "name": "subTestD",
61 "result": "UNRESOLVED",
62 "time": "0.001s"
63 }
64 ]
65 },
66 {
67 "name": "ParameterizedTest/0",
68 "testsuite": [
69 {
70 "name": "subTest",
71 "result": "COMPLETED",
72 "time": "0.001s"
73 }
74 ]
75 },
76 {
77 "name": "ParameterizedTest/1",
78 "testsuite": [
79 {
80 "name": "subTest",
81 "result": "COMPLETED",
82 "time": "0.001s"
83 }
84 ]
85 }
86 ]
87 }"""
88
89 dummy_output = """\
90 {
91 "testsuites": [
92 ]
93 }"""
94
95 json_filename = os.environ['GTEST_OUTPUT'].split(':', 1)[1]
96 with open(json_filename, 'w', encoding='utf-8') as f:
97 if os.environ['GTEST_TOTAL_SHARDS'] == '1':
98 print('[ RUN ] FirstTest.subTestB', flush=True)
99 print('I am subTest B output', file=sys.stderr, flush=True)
100 print('[ FAILED ] FirstTest.subTestB (8 ms)', flush=True)
101
102 f.write(output)
103 exit_code = 1
104 else:
105 f.write(dummy_output)
106 exit_code = 0
107
108 sys.exit(exit_code)