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("""\ 10T. 11 QuickSubTest 12 InfiniteLoopSubTest 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', 'GTEST_FILTER']: 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"testsuites": [ 29 { 30 "name": "T", 31 "testsuite": [ 32 { 33 "name": "QuickSubTest", 34 "result": "COMPLETED", 35 "time": "2s" 36 } 37 ] 38 } 39] 40}""" 41 42dummy_output = """\ 43{ 44"testsuites": [ 45] 46}""" 47 48json_filename = os.environ['GTEST_OUTPUT'].split(':', 1)[1] 49 50if os.environ['GTEST_SHARD_INDEX'] == '0': 51 test_name = os.environ['GTEST_FILTER'] 52 if test_name == 'QuickSubTest': 53 with open(json_filename, 'w', encoding='utf-8') as f: 54 f.write(output) 55 exit_code = 0 56 elif test_name == 'InfiniteLoopSubTest': 57 while True: 58 pass 59 else: 60 raise SystemExit("error: invalid test name: %r" % (test_name,)) 61else: 62 with open(json_filename, 'w', encoding='utf-8') as f: 63 f.write(dummy_output) 64 exit_code = 0 65 66sys.exit(exit_code) 67