xref: /llvm-project/llvm/utils/lit/tests/Inputs/googletest-cmd-wrapper/DummySubDir/OneTest.exe (revision ea7968bf76ceea83b4acea49ea8366edd90452e3)
1import os
2import sys
3
4if len(sys.argv) == 3 and sys.argv[1] == "--gtest_list_tests":
5    if sys.argv[2] != '--gtest_filter=-*DISABLED_*':
6        raise ValueError("unexpected argument: %s" % (sys.argv[2]))
7    print("""\
8FirstTest.
9  subTestA""")
10    sys.exit(0)
11elif len(sys.argv) != 1:
12    # sharding and json output are specified using environment variables
13    raise ValueError("unexpected argument: %r" % (' '.join(sys.argv[1:])))
14
15for e in ['GTEST_TOTAL_SHARDS', 'GTEST_SHARD_INDEX', 'GTEST_OUTPUT']:
16    if e not in os.environ:
17        raise ValueError("missing environment variables: " + e)
18
19if not os.environ['GTEST_OUTPUT'].startswith('json:'):
20    raise ValueError("must emit json output: " + os.environ['GTEST_OUTPUT'])
21
22output = """\
23{
24"testsuites": [
25    {
26        "name": "FirstTest",
27        "testsuite": [
28            {
29                "name": "subTestA",
30                "result": "COMPLETED",
31                "time": "0.001s"
32            }
33        ]
34    }
35]
36}"""
37
38dummy_output = """\
39{
40"testsuites": [
41]
42}"""
43
44json_filename = os.environ['GTEST_OUTPUT'].split(':', 1)[1]
45with open(json_filename, 'w', encoding='utf-8') as f:
46    if os.environ['GTEST_SHARD_INDEX'] == '0':
47        f.write(output)
48    else:
49        f.write(dummy_output)
50
51sys.exit(0)
52