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("""\ 10FirstTest. 11 subTestA 12 subTestB 13 subTestC 14 subTestD 15ParameterizedTest/0. 16 subTest 17ParameterizedTest/1. 18 subTest""") 19 sys.exit(0) 20elif len(sys.argv) != 1: 21 # sharding and json output are specified using environment variables 22 raise ValueError("unexpected argument: %r" % (' '.join(sys.argv[1:]))) 23 24for e in ['GTEST_TOTAL_SHARDS', 'GTEST_SHARD_INDEX', 'GTEST_OUTPUT']: 25 if e not in os.environ: 26 raise ValueError("missing environment variables: " + e) 27 28if not os.environ['GTEST_OUTPUT'].startswith('json:'): 29 raise ValueError("must emit json output: " + os.environ['GTEST_OUTPUT']) 30 31dummy_output = """\ 32{ 33"testsuites": [ 34] 35}""" 36 37if os.environ['GTEST_SHARD_INDEX'] == '0': 38 print("""\ 39[----------] 4 test from FirstTest 40[ RUN ] FirstTest.subTestA 41[ OK ] FirstTest.subTestA (18 ms) 42[ RUN ] FirstTest.subTestB""", flush=True) 43 print('I am about to crash', file=sys.stderr, flush=True) 44 exit_code = 1 45else: 46 json_filename = os.environ['GTEST_OUTPUT'].split(':', 1)[1] 47 with open(json_filename, 'w', encoding='utf-8') as f: 48 f.write(dummy_output) 49 exit_code = 0 50 51sys.exit(exit_code) 52