aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorzhanyong.wan <zhanyong.wan@861a406c-534a-0410-8894-cb66d6ee9925>2009-06-19 21:23:56 +0000
committerzhanyong.wan <zhanyong.wan@861a406c-534a-0410-8894-cb66d6ee9925>2009-06-19 21:23:56 +0000
commit046efb852bef27fe2a22dc632fdaeb909d5b0086 (patch)
tree052c7a62cb9de8143c802fa6b0882805b48feeb5 /test
parent3c181b5657a51d73166c1012dad80ed3ee7a30ee (diff)
downloadgoogletest-046efb852bef27fe2a22dc632fdaeb909d5b0086.tar.gz
googletest-046efb852bef27fe2a22dc632fdaeb909d5b0086.tar.bz2
googletest-046efb852bef27fe2a22dc632fdaeb909d5b0086.zip
Fixes the broken run_tests_test (by Vlad Losev).
Diffstat (limited to 'test')
-rwxr-xr-xtest/gtest_test_utils.py3
-rwxr-xr-xtest/run_tests_test.py80
2 files changed, 63 insertions, 20 deletions
diff --git a/test/gtest_test_utils.py b/test/gtest_test_utils.py
index 45b25cd6..5b28fe49 100755
--- a/test/gtest_test_utils.py
+++ b/test/gtest_test_utils.py
@@ -53,6 +53,7 @@ except:
IS_WINDOWS = os.name == 'nt'
+IS_CYGWIN = os.name == 'posix' and 'CYGWIN' in os.uname()[0]
# Here we expose a class from a particular module, depending on the
# environment. The comment suppresses the 'Invalid variable name' lint
@@ -150,7 +151,7 @@ def GetTestExecutablePath(executable_name):
"""
path = os.path.abspath(os.path.join(GetBuildDir(), executable_name))
- if IS_WINDOWS and not path.endswith('.exe'):
+ if (IS_WINDOWS or IS_CYGWIN) and not path.endswith('.exe'):
path += '.exe'
if not os.path.exists(path):
diff --git a/test/run_tests_test.py b/test/run_tests_test.py
index b55739ea..d8bbc362 100755
--- a/test/run_tests_test.py
+++ b/test/run_tests_test.py
@@ -33,12 +33,22 @@
__author__ = 'vladl@google.com (Vlad Losev)'
import os
+import re
+import sets
import sys
import unittest
sys.path.append(os.path.join(os.path.dirname(sys.argv[0]), os.pardir))
import run_tests
+def AddExeExtension(path):
+ """Appends .exe to the path on Windows or Cygwin."""
+
+ if run_tests.IS_WINDOWS or run_tests.IS_CYGWIN:
+ return path + '.exe'
+ else:
+ return path
+
class FakePath(object):
"""A fake os.path module for testing."""
@@ -137,28 +147,43 @@ class FakeOs(object):
class GetTestsToRunTest(unittest.TestCase):
"""Exercises TestRunner.GetTestsToRun."""
- def AssertResultsEqual(self, results, expected):
- """Asserts results returned by GetTestsToRun equal to expected results."""
+ def NormalizeGetTestsToRunResults(self, results):
+ """Normalizes path data returned from GetTestsToRun for comparison."""
+
+ def NormalizePythonTestPair(pair):
+ """Normalizes path data in the (directory, python_script) pair."""
+
+ return (os.path.normpath(pair[0]), os.path.normpath(pair[1]))
- def NormalizeResultPaths(paths):
- """Normalizes values returned by GetTestsToRun for comparison."""
+ def NormalizeBinaryTestPair(pair):
+ """Normalizes path data in the (directory, binary_executable) pair."""
- def NormalizeResultPair(pair):
- return (os.path.normpath(pair[0]), os.path.normpath(pair[1]))
+ directory, executable = map(os.path.normpath, pair)
- return (sorted(map(NormalizeResultPair, paths[0])),
- sorted(map(NormalizeResultPair, paths[1])))
+ # On Windows and Cygwin, the test file names have the .exe extension, but
+ # they can be invoked either by name or by name+extension. Our test must
+ # accommodate both situations.
+ if run_tests.IS_WINDOWS or run_tests.IS_CYGWIN:
+ executable = re.sub(r'\.exe$', '', executable)
+ return (directory, executable)
- self.assertEqual(NormalizeResultPaths(results),
- NormalizeResultPaths(expected),
- 'Incorrect set of tests %s returned vs %s expected' %
+ python_tests = sets.Set(map(NormalizePythonTestPair, results[0]))
+ binary_tests = sets.Set(map(NormalizeBinaryTestPair, results[1]))
+ return (python_tests, binary_tests)
+
+ def AssertResultsEqual(self, results, expected):
+ """Asserts results returned by GetTestsToRun equal to expected results."""
+
+ self.assertEqual(self.NormalizeGetTestsToRunResults(results),
+ self.NormalizeGetTestsToRunResults(expected),
+ 'Incorrect set of tests returned:\n%s\nexpected:\n%s' %
(results, expected))
def setUp(self):
self.fake_os = FakeOs(FakePath(
current_dir=os.path.abspath(os.path.dirname(run_tests.__file__)),
- known_paths=['scons/build/dbg/scons/gtest_unittest',
- 'scons/build/opt/scons/gtest_unittest',
+ known_paths=[AddExeExtension('scons/build/dbg/scons/gtest_unittest'),
+ AddExeExtension('scons/build/opt/scons/gtest_unittest'),
'test/gtest_color_test.py']))
self.fake_configurations = ['dbg', 'opt']
self.test_runner = run_tests.TestRunner(injected_os=self.fake_os,
@@ -390,8 +415,7 @@ class GetTestsToRunTest(unittest.TestCase):
self.fake_os = FakeOs(FakePath(
current_dir=os.path.abspath(os.path.dirname(run_tests.__file__)),
- known_paths=['scons/build/dbg/scons/gtest_nontest',
- 'scons/build/opt/scons/gtest_nontest.exe',
+ known_paths=[AddExeExtension('scons/build/dbg/scons/gtest_nontest'),
'test/']))
self.test_runner = run_tests.TestRunner(injected_os=self.fake_os,
injected_subprocess=None,
@@ -412,8 +436,8 @@ class GetTestsToRunTest(unittest.TestCase):
self.fake_os = FakeOs(FakePath(
current_dir=os.path.abspath('/a/b/c'),
known_paths=['/a/b/c/',
- '/d/scons/build/dbg/scons/gtest_unittest',
- '/d/scons/build/opt/scons/gtest_unittest',
+ AddExeExtension('/d/scons/build/dbg/scons/gtest_unittest'),
+ AddExeExtension('/d/scons/build/opt/scons/gtest_unittest'),
'/d/test/gtest_color_test.py']))
self.fake_configurations = ['dbg', 'opt']
self.test_runner = run_tests.TestRunner(injected_os=self.fake_os,
@@ -461,6 +485,24 @@ class GetTestsToRunTest(unittest.TestCase):
False,
available_configurations=self.fake_configurations))
+ if run_tests.IS_WINDOWS or run_tests.IS_CYGWIN:
+ def testDoesNotPickNonExeFilesOnWindows(self):
+ """Verifies that GetTestsToRun does not find _test files on Windows."""
+
+ self.fake_os = FakeOs(FakePath(
+ current_dir=os.path.abspath(os.path.dirname(run_tests.__file__)),
+ known_paths=['scons/build/dbg/scons/gtest_test', 'test/']))
+ self.test_runner = run_tests.TestRunner(injected_os=self.fake_os,
+ injected_subprocess=None,
+ injected_script_dir='.')
+ self.AssertResultsEqual(
+ self.test_runner.GetTestsToRun(
+ [],
+ '',
+ True,
+ available_configurations=self.fake_configurations),
+ ([], []))
+
class RunTestsTest(unittest.TestCase):
"""Exercises TestRunner.RunTests."""
@@ -480,8 +522,8 @@ class RunTestsTest(unittest.TestCase):
def setUp(self):
self.fake_os = FakeOs(FakePath(
current_dir=os.path.abspath(os.path.dirname(run_tests.__file__)),
- known_paths=['scons/build/dbg/scons/gtest_unittest',
- 'scons/build/opt/scons/gtest_unittest',
+ known_paths=[AddExeExtension('scons/build/dbg/scons/gtest_unittest'),
+ AddExeExtension('scons/build/opt/scons/gtest_unittest'),
'test/gtest_color_test.py']))
self.fake_configurations = ['dbg', 'opt']
self.test_runner = run_tests.TestRunner(injected_os=self.fake_os,