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