Index: llvm/trunk/utils/lit/lit/formats/googletest.py =================================================================== --- llvm/trunk/utils/lit/lit/formats/googletest.py +++ llvm/trunk/utils/lit/lit/formats/googletest.py @@ -13,11 +13,14 @@ class GoogleTest(TestFormat): def __init__(self, test_sub_dirs, test_suffix): self.test_sub_dirs = os.path.normcase(str(test_sub_dirs)).split(';') - self.test_suffix = str(test_suffix) # On Windows, assume tests will also end in '.exe'. + exe_suffix = str(test_suffix) if kIsWindows: - self.test_suffix += '.exe' + exe_suffix += '.exe' + + # Also check for .py files for testing purposes. + self.test_suffixes = {exe_suffix, test_suffix + '.py'} def getGTestTests(self, path, litConfig, localConfig): """getGTestTests(path) - [name] @@ -29,8 +32,10 @@ litConfig: LitConfig instance localConfig: TestingConfig instance""" + list_test_cmd = self.maybeAddPythonToCmd([path, '--gtest_list_tests']) + try: - output = subprocess.check_output([path, '--gtest_list_tests'], + output = subprocess.check_output(list_test_cmd, env=localConfig.environment) except subprocess.CalledProcessError as exc: litConfig.warning( @@ -82,7 +87,7 @@ if not os.path.isdir(dir_path): continue for fn in lit.util.listdir_files(dir_path, - suffixes={self.test_suffix}): + suffixes=self.test_suffixes): # Discover the tests in this executable. execpath = os.path.join(source_path, subdir, fn) testnames = self.getGTestTests(execpath, litConfig, localConfig) @@ -100,6 +105,7 @@ testName = namePrefix + '/' + testName cmd = [testPath, '--gtest_filter=' + testName] + cmd = self.maybeAddPythonToCmd(cmd) if litConfig.useValgrind: cmd = litConfig.valgrindArgs + cmd @@ -126,3 +132,14 @@ return lit.Test.UNRESOLVED, msg return lit.Test.PASS,'' + + def maybeAddPythonToCmd(self, cmd): + """Insert the python exe into the command if cmd[0] ends in .py + + We cannot rely on the system to interpret shebang lines for us on + Windows, so add the python executable to the command if this is a .py + script. + """ + if cmd[0].endswith('.py'): + return [sys.executable] + cmd + return cmd Index: llvm/trunk/utils/lit/tests/Inputs/googletest-format/DummySubDir/OneTest =================================================================== --- llvm/trunk/utils/lit/tests/Inputs/googletest-format/DummySubDir/OneTest +++ llvm/trunk/utils/lit/tests/Inputs/googletest-format/DummySubDir/OneTest @@ -1,36 +0,0 @@ -#!/usr/bin/env python - -import sys - -if len(sys.argv) != 2: - raise ValueError("unexpected number of args") - -if sys.argv[1] == "--gtest_list_tests": - print("""\ -FirstTest. - subTestA - subTestB -ParameterizedTest/0. - subTest -ParameterizedTest/1. - subTest""") - sys.exit(0) -elif not sys.argv[1].startswith("--gtest_filter="): - raise ValueError("unexpected argument: %r" % (sys.argv[1])) - -test_name = sys.argv[1].split('=',1)[1] -if test_name == 'FirstTest.subTestA': - print('I am subTest A, I PASS') - print('[ PASSED ] 1 test.') - sys.exit(0) -elif test_name == 'FirstTest.subTestB': - print('I am subTest B, I FAIL') - print('And I have two lines of output') - sys.exit(1) -elif test_name in ('ParameterizedTest/0.subTest', - 'ParameterizedTest/1.subTest'): - print('I am a parameterized test, I also PASS') - print('[ PASSED ] 1 test.') - sys.exit(0) -else: - raise SystemExit("error: invalid test name: %r" % (test_name,)) Index: llvm/trunk/utils/lit/tests/Inputs/googletest-format/DummySubDir/OneTest.py =================================================================== --- llvm/trunk/utils/lit/tests/Inputs/googletest-format/DummySubDir/OneTest.py +++ llvm/trunk/utils/lit/tests/Inputs/googletest-format/DummySubDir/OneTest.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python + +import sys + +if len(sys.argv) != 2: + raise ValueError("unexpected number of args") + +if sys.argv[1] == "--gtest_list_tests": + print("""\ +FirstTest. + subTestA + subTestB +ParameterizedTest/0. + subTest +ParameterizedTest/1. + subTest""") + sys.exit(0) +elif not sys.argv[1].startswith("--gtest_filter="): + raise ValueError("unexpected argument: %r" % (sys.argv[1])) + +test_name = sys.argv[1].split('=',1)[1] +if test_name == 'FirstTest.subTestA': + print('I am subTest A, I PASS') + print('[ PASSED ] 1 test.') + sys.exit(0) +elif test_name == 'FirstTest.subTestB': + print('I am subTest B, I FAIL') + print('And I have two lines of output') + sys.exit(1) +elif test_name in ('ParameterizedTest/0.subTest', + 'ParameterizedTest/1.subTest'): + print('I am a parameterized test, I also PASS') + print('[ PASSED ] 1 test.') + sys.exit(0) +else: + raise SystemExit("error: invalid test name: %r" % (test_name,)) Index: llvm/trunk/utils/lit/tests/Inputs/googletest-timeout/DummySubDir/OneTest =================================================================== --- llvm/trunk/utils/lit/tests/Inputs/googletest-timeout/DummySubDir/OneTest +++ llvm/trunk/utils/lit/tests/Inputs/googletest-timeout/DummySubDir/OneTest @@ -1,35 +0,0 @@ -#!/usr/bin/env python - -import sys -import time - -if len(sys.argv) != 2: - raise ValueError("unexpected number of args") - -if sys.argv[1] == "--gtest_list_tests": - print("""\ -FirstTest. - subTestA - subTestB - subTestC -""") - sys.exit(0) -elif not sys.argv[1].startswith("--gtest_filter="): - raise ValueError("unexpected argument: %r" % (sys.argv[1])) - -test_name = sys.argv[1].split('=',1)[1] -if test_name == 'FirstTest.subTestA': - print('I am subTest A, I PASS') - print('[ PASSED ] 1 test.') - sys.exit(0) -elif test_name == 'FirstTest.subTestB': - print('I am subTest B, I am slow') - time.sleep(6) - print('[ PASSED ] 1 test.') - sys.exit(0) -elif test_name == 'FirstTest.subTestC': - print('I am subTest C, I will hang') - while True: - pass -else: - raise SystemExit("error: invalid test name: %r" % (test_name,)) Index: llvm/trunk/utils/lit/tests/Inputs/googletest-timeout/DummySubDir/OneTest.py =================================================================== --- llvm/trunk/utils/lit/tests/Inputs/googletest-timeout/DummySubDir/OneTest.py +++ llvm/trunk/utils/lit/tests/Inputs/googletest-timeout/DummySubDir/OneTest.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python + +import sys +import time + +if len(sys.argv) != 2: + raise ValueError("unexpected number of args") + +if sys.argv[1] == "--gtest_list_tests": + print("""\ +FirstTest. + subTestA + subTestB + subTestC +""") + sys.exit(0) +elif not sys.argv[1].startswith("--gtest_filter="): + raise ValueError("unexpected argument: %r" % (sys.argv[1])) + +test_name = sys.argv[1].split('=',1)[1] +if test_name == 'FirstTest.subTestA': + print('I am subTest A, I PASS') + print('[ PASSED ] 1 test.') + sys.exit(0) +elif test_name == 'FirstTest.subTestB': + print('I am subTest B, I am slow') + time.sleep(6) + print('[ PASSED ] 1 test.') + sys.exit(0) +elif test_name == 'FirstTest.subTestC': + print('I am subTest C, I will hang') + while True: + pass +else: + raise SystemExit("error: invalid test name: %r" % (test_name,)) Index: llvm/trunk/utils/lit/tests/Inputs/googletest-upstream-format/DummySubDir/OneTest =================================================================== --- llvm/trunk/utils/lit/tests/Inputs/googletest-upstream-format/DummySubDir/OneTest +++ llvm/trunk/utils/lit/tests/Inputs/googletest-upstream-format/DummySubDir/OneTest @@ -1,38 +0,0 @@ -#!/usr/bin/env python - -import sys - -if len(sys.argv) != 2: - raise ValueError("unexpected number of args") - -if sys.argv[1] == "--gtest_list_tests": - print("""\ -Running main() from gtest_main.cc -FirstTest. - subTestA - subTestB -ParameterizedTest/0. - subTest -ParameterizedTest/1. - subTest""") - sys.exit(0) -elif not sys.argv[1].startswith("--gtest_filter="): - raise ValueError("unexpected argument: %r" % (sys.argv[1])) - -test_name = sys.argv[1].split('=',1)[1] -print('Running main() from gtest_main.cc') -if test_name == 'FirstTest.subTestA': - print('I am subTest A, I PASS') - print('[ PASSED ] 1 test.') - sys.exit(0) -elif test_name == 'FirstTest.subTestB': - print('I am subTest B, I FAIL') - print('And I have two lines of output') - sys.exit(1) -elif test_name in ('ParameterizedTest/0.subTest', - 'ParameterizedTest/1.subTest'): - print('I am a parameterized test, I also PASS') - print('[ PASSED ] 1 test.') - sys.exit(0) -else: - raise SystemExit("error: invalid test name: %r" % (test_name,)) Index: llvm/trunk/utils/lit/tests/Inputs/googletest-upstream-format/DummySubDir/OneTest.py =================================================================== --- llvm/trunk/utils/lit/tests/Inputs/googletest-upstream-format/DummySubDir/OneTest.py +++ llvm/trunk/utils/lit/tests/Inputs/googletest-upstream-format/DummySubDir/OneTest.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python + +import sys + +if len(sys.argv) != 2: + raise ValueError("unexpected number of args") + +if sys.argv[1] == "--gtest_list_tests": + print("""\ +Running main() from gtest_main.cc +FirstTest. + subTestA + subTestB +ParameterizedTest/0. + subTest +ParameterizedTest/1. + subTest""") + sys.exit(0) +elif not sys.argv[1].startswith("--gtest_filter="): + raise ValueError("unexpected argument: %r" % (sys.argv[1])) + +test_name = sys.argv[1].split('=',1)[1] +print('Running main() from gtest_main.cc') +if test_name == 'FirstTest.subTestA': + print('I am subTest A, I PASS') + print('[ PASSED ] 1 test.') + sys.exit(0) +elif test_name == 'FirstTest.subTestB': + print('I am subTest B, I FAIL') + print('And I have two lines of output') + sys.exit(1) +elif test_name in ('ParameterizedTest/0.subTest', + 'ParameterizedTest/1.subTest'): + print('I am a parameterized test, I also PASS') + print('[ PASSED ] 1 test.') + sys.exit(0) +else: + raise SystemExit("error: invalid test name: %r" % (test_name,)) Index: llvm/trunk/utils/lit/tests/googletest-format.py =================================================================== --- llvm/trunk/utils/lit/tests/googletest-format.py +++ llvm/trunk/utils/lit/tests/googletest-format.py @@ -1,22 +1,19 @@ # Check the various features of the GoogleTest format. # -# PR33933 -# XFAIL: windows -# # RUN: not %{lit} -j 1 -v %{inputs}/googletest-format > %t.out # RUN: FileCheck < %t.out %s # # END. # CHECK: -- Testing: -# CHECK: PASS: googletest-format :: DummySubDir/OneTest/FirstTest.subTestA -# CHECK: FAIL: googletest-format :: DummySubDir/OneTest/FirstTest.subTestB -# CHECK-NEXT: *** TEST 'googletest-format :: DummySubDir/OneTest/FirstTest.subTestB' FAILED *** +# CHECK: PASS: googletest-format :: {{[Dd]ummy[Ss]ub[Dd]ir}}/OneTest.py/FirstTest.subTestA +# CHECK: FAIL: googletest-format :: {{[Dd]ummy[Ss]ub[Dd]ir}}/OneTest.py/FirstTest.subTestB +# CHECK-NEXT: *** TEST 'googletest-format :: {{[Dd]ummy[Ss]ub[Dd]ir}}/OneTest.py/FirstTest.subTestB' FAILED *** # CHECK-NEXT: I am subTest B, I FAIL # CHECK-NEXT: And I have two lines of output # CHECK: *** -# CHECK: PASS: googletest-format :: DummySubDir/OneTest/ParameterizedTest/0.subTest -# CHECK: PASS: googletest-format :: DummySubDir/OneTest/ParameterizedTest/1.subTest +# CHECK: PASS: googletest-format :: {{[Dd]ummy[Ss]ub[Dd]ir}}/OneTest.py/ParameterizedTest/0.subTest +# CHECK: PASS: googletest-format :: {{[Dd]ummy[Ss]ub[Dd]ir}}/OneTest.py/ParameterizedTest/1.subTest # CHECK: Failing Tests (1) # CHECK: Expected Passes : 3 # CHECK: Unexpected Failures: 1 Index: llvm/trunk/utils/lit/tests/googletest-timeout.py =================================================================== --- llvm/trunk/utils/lit/tests/googletest-timeout.py +++ llvm/trunk/utils/lit/tests/googletest-timeout.py @@ -1,8 +1,5 @@ # REQUIRES: python-psutil -# PR33934 -# XFAIL: windows - # Check that the per test timeout is enforced when running GTest tests. # # RUN: not %{lit} -j 1 -v %{inputs}/googletest-timeout --timeout=1 > %t.cmd.out @@ -16,9 +13,9 @@ # RUN: FileCheck < %t.cfgset.out %s # CHECK: -- Testing: -# CHECK: PASS: googletest-timeout :: DummySubDir/OneTest/FirstTest.subTestA -# CHECK: TIMEOUT: googletest-timeout :: DummySubDir/OneTest/FirstTest.subTestB -# CHECK: TIMEOUT: googletest-timeout :: DummySubDir/OneTest/FirstTest.subTestC +# CHECK: PASS: googletest-timeout :: {{[Dd]ummy[Ss]ub[Dd]ir}}/OneTest.py/FirstTest.subTestA +# CHECK: TIMEOUT: googletest-timeout :: {{[Dd]ummy[Ss]ub[Dd]ir}}/OneTest.py/FirstTest.subTestB +# CHECK: TIMEOUT: googletest-timeout :: {{[Dd]ummy[Ss]ub[Dd]ir}}/OneTest.py/FirstTest.subTestC # CHECK: Expected Passes : 1 # CHECK: Individual Timeouts: 2 Index: llvm/trunk/utils/lit/tests/googletest-upstream-format.py =================================================================== --- llvm/trunk/utils/lit/tests/googletest-upstream-format.py +++ llvm/trunk/utils/lit/tests/googletest-upstream-format.py @@ -1,23 +1,20 @@ # Check the various features of the GoogleTest format. # -# PR33935 -# XFAIL: windows -# # RUN: not %{lit} -j 1 -v %{inputs}/googletest-upstream-format > %t.out # RUN: FileCheck < %t.out %s # # END. # CHECK: -- Testing: -# CHECK: PASS: googletest-upstream-format :: DummySubDir/OneTest/FirstTest.subTestA -# CHECK: FAIL: googletest-upstream-format :: DummySubDir/OneTest/FirstTest.subTestB -# CHECK-NEXT: *** TEST 'googletest-upstream-format :: DummySubDir/OneTest/FirstTest.subTestB' FAILED *** +# CHECK: PASS: googletest-upstream-format :: {{[Dd]ummy[Ss]ub[Dd]ir}}/OneTest.py/FirstTest.subTestA +# CHECK: FAIL: googletest-upstream-format :: {{[Dd]ummy[Ss]ub[Dd]ir}}/OneTest.py/FirstTest.subTestB +# CHECK-NEXT: *** TEST 'googletest-upstream-format :: {{[Dd]ummy[Ss]ub[Dd]ir}}/OneTest.py/FirstTest.subTestB' FAILED *** # CHECK-NEXT: Running main() from gtest_main.cc # CHECK-NEXT: I am subTest B, I FAIL # CHECK-NEXT: And I have two lines of output # CHECK: *** -# CHECK: PASS: googletest-upstream-format :: DummySubDir/OneTest/ParameterizedTest/0.subTest -# CHECK: PASS: googletest-upstream-format :: DummySubDir/OneTest/ParameterizedTest/1.subTest +# CHECK: PASS: googletest-upstream-format :: {{[Dd]ummy[Ss]ub[Dd]ir}}/OneTest.py/ParameterizedTest/0.subTest +# CHECK: PASS: googletest-upstream-format :: {{[Dd]ummy[Ss]ub[Dd]ir}}/OneTest.py/ParameterizedTest/1.subTest # CHECK: Failing Tests (1) # CHECK: Expected Passes : 3 # CHECK: Unexpected Failures: 1