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 """\ 11T. 12 QuickSubTest 13 InfiniteLoopSubTest 14""" 15 ) 16 sys.exit(0) 17elif len(sys.argv) != 1: 18 # sharding and json output are specified using environment variables 19 raise ValueError("unexpected argument: %r" % (" ".join(sys.argv[1:]))) 20 21for e in ["GTEST_TOTAL_SHARDS", "GTEST_SHARD_INDEX", "GTEST_OUTPUT", "GTEST_FILTER"]: 22 if e not in os.environ: 23 raise ValueError("missing environment variables: " + e) 24 25if not os.environ["GTEST_OUTPUT"].startswith("json:"): 26 raise ValueError("must emit json output: " + os.environ["GTEST_OUTPUT"]) 27 28output = """\ 29{ 30"testsuites": [ 31 { 32 "name": "T", 33 "testsuite": [ 34 { 35 "name": "QuickSubTest", 36 "result": "COMPLETED", 37 "time": "2s" 38 } 39 ] 40 } 41] 42}""" 43 44dummy_output = """\ 45{ 46"testsuites": [ 47] 48}""" 49 50json_filename = os.environ["GTEST_OUTPUT"].split(":", 1)[1] 51 52if os.environ["GTEST_SHARD_INDEX"] == "0": 53 test_name = os.environ["GTEST_FILTER"] 54 if test_name == "QuickSubTest": 55 with open(json_filename, "w", encoding="utf-8") as f: 56 f.write(output) 57 exit_code = 0 58 elif test_name == "InfiniteLoopSubTest": 59 while True: 60 pass 61 else: 62 raise SystemExit("error: invalid test name: %r" % (test_name,)) 63else: 64 with open(json_filename, "w", encoding="utf-8") as f: 65 f.write(dummy_output) 66 exit_code = 0 67 68sys.exit(exit_code) 69