llvm.org GIT mirror llvm / 30a91fe
[lit][googletest] Handle upstream gtest output Summary: Upstream googletest prints "Running main() from gtest_main.cc" to stdout prior to running tests. LLVM removed that print statement in r61540. If a user were to use lit to run tests that use upstream googletest, however, lit reports "Running main()" as an invalid test name. To avoid such a failure, add an extra conditional to `formats/googletest.py`. Also add tests to demonstrate the modified behavior. Reviewers: abdulras, ddunbar Subscribers: ddunbar, llvm-commits, kastiglione Differential Revision: http://reviews.llvm.org/D18606 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@265034 91177308-0d34-0410-b5e6-96231b3b80d8 Daniel Dunbar 4 years ago
4 changed file(s) with 67 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
4040 nested_tests = []
4141 for ln in lines:
4242 if not ln.strip():
43 continue
44
45 if 'Running main() from gtest_main.cc' in ln:
46 # Upstream googletest prints this to stdout prior to running
47 # tests. LLVM removed that print statement in r61540, but we
48 # handle it here in case upstream googletest is being used.
4349 continue
4450
4551 prefix = ''
0 #!/usr/bin/env python
1
2 import sys
3
4 if len(sys.argv) != 2:
5 raise ValueError("unexpected number of args")
6
7 if sys.argv[1] == "--gtest_list_tests":
8 print("""\
9 Running main() from gtest_main.cc
10 FirstTest.
11 subTestA
12 subTestB
13 ParameterizedTest/0.
14 subTest
15 ParameterizedTest/1.
16 subTest""")
17 sys.exit(0)
18 elif not sys.argv[1].startswith("--gtest_filter="):
19 raise ValueError("unexpected argument: %r" % (sys.argv[1]))
20
21 test_name = sys.argv[1].split('=',1)[1]
22 print('Running main() from gtest_main.cc')
23 if test_name == 'FirstTest.subTestA':
24 print('I am subTest A, I PASS')
25 print('[ PASSED ] 1 test.')
26 sys.exit(0)
27 elif test_name == 'FirstTest.subTestB':
28 print('I am subTest B, I FAIL')
29 print('And I have two lines of output')
30 sys.exit(1)
31 elif test_name in ('ParameterizedTest/0.subTest',
32 'ParameterizedTest/1.subTest'):
33 print('I am a parameterized test, I also PASS')
34 print('[ PASSED ] 1 test.')
35 sys.exit(0)
36 else:
37 raise SystemExit("error: invalid test name: %r" % (test_name,))
0 import lit.formats
1 config.name = 'googletest-upstream-format'
2 config.test_format = lit.formats.GoogleTest('DummySubDir', 'Test')
0 # Check the various features of the GoogleTest format.
1 #
2 # RUN: not %{lit} -j 1 -v %{inputs}/googletest-upstream-format > %t.out
3 # RUN: FileCheck < %t.out %s
4 #
5 # END.
6
7 # CHECK: -- Testing:
8 # CHECK: PASS: googletest-upstream-format :: DummySubDir/OneTest/FirstTest.subTestA
9 # CHECK: FAIL: googletest-upstream-format :: DummySubDir/OneTest/FirstTest.subTestB
10 # CHECK-NEXT: *** TEST 'googletest-upstream-format :: DummySubDir/OneTest/FirstTest.subTestB' FAILED ***
11 # CHECK-NEXT: Running main() from gtest_main.cc
12 # CHECK-NEXT: I am subTest B, I FAIL
13 # CHECK-NEXT: And I have two lines of output
14 # CHECK: ***
15 # CHECK: PASS: googletest-upstream-format :: DummySubDir/OneTest/ParameterizedTest/0.subTest
16 # CHECK: PASS: googletest-upstream-format :: DummySubDir/OneTest/ParameterizedTest/1.subTest
17 # CHECK: Failing Tests (1)
18 # CHECK: Expected Passes : 3
19 # CHECK: Unexpected Failures: 1