Debian Codegraph @

llvm-project/llvm/utils/lit/tests/Inputs/googletest-sanitizer-error/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 sys.exit(0)
13 elif len(sys.argv) != 1:
14 # sharding and json output are specified using environment variables
15 raise ValueError("unexpected argument: %r" % (' '.join(sys.argv[1:])))
16
17 for e in ['GTEST_TOTAL_SHARDS', 'GTEST_SHARD_INDEX', 'GTEST_OUTPUT']:
18 if e not in os.environ:
19 raise ValueError("missing environment variables: " + e)
20
21 if not os.environ['GTEST_OUTPUT'].startswith('json:'):
22 raise ValueError("must emit json output: " + os.environ['GTEST_OUTPUT'])
23
24 output = """\
25 {
26 "random_seed": 123,
27 "testsuites": [
28 {
29 "name": "FirstTest",
30 "testsuite": [
31 {
32 "name": "subTestA",
33 "result": "COMPLETED",
34 "time": "0.001s"
35 }
36 ]
37 }
38 ]
39 }"""
40
41 dummy_output = """\
42 {
43 "testsuites": [
44 ]
45 }"""
46
47 json_filename = os.environ['GTEST_OUTPUT'].split(':', 1)[1]
48 with open(json_filename, 'w', encoding='utf-8') as f:
49 if os.environ['GTEST_SHARD_INDEX'] == '0':
50 print('[ RUN ] FirstTest.subTestA', flush=True)
51 print('[ OK ] FirstTest.subTestA (8 ms)', flush=True)
52
53 f.write(output)
54 exit_code = 1
55 else:
56 f.write(dummy_output)
57 exit_code = 0
58
59 sys.exit(exit_code)