Use only basename for log-file names. (#42) This addresses a bug where test log names were too long to fit within MAX_PATH on Windows, since they included the path to the test as well. As os.path.basename()s are already unique for all binaries (enforced in main()), this is gives cleaner log names without risking collisions either.
diff --git a/gtest_parallel.py b/gtest_parallel.py index d9c4f0f..ea830f4 100755 --- a/gtest_parallel.py +++ b/gtest_parallel.py
@@ -167,11 +167,8 @@ self.test_id = (test_binary, test_name) self.task_id = (test_binary, test_name, self.execution_number) - log_name = '%s-%s-%s.log' % (self.__normalize(test_binary), - self.__normalize(test_name), - self.execution_number) - - self.log_file = os.path.join(output_dir, log_name) + self.log_file = Task._logname(self.output_dir, self.test_binary, + test_name, self.execution_number) def __lt__(self, other): if self.last_execution_time is None: @@ -180,9 +177,17 @@ return False return self.last_execution_time > other.last_execution_time - def __normalize(self, string): + @staticmethod + def _normalize(string): return re.sub('[^A-Za-z0-9]', '_', string) + @staticmethod + def _logname(output_dir, test_binary, test_name, execution_number): + log_name = '%s-%s-%d.log' % (Task._normalize(os.path.basename(test_binary)), + Task._normalize(test_name), execution_number) + + return os.path.join(output_dir, log_name) + def run(self): begin = time.time() with open(self.log_file, 'w') as log: @@ -288,7 +293,6 @@ for task in tasks: shutil.move(task.log_file, destination_dir) - def print_tests(self, message, tasks, print_try_number): self.out.permanent_line("%s (%s/%s):" % (message, len(tasks), self.total_tasks))
diff --git a/gtest_parallel_tests.py b/gtest_parallel_tests.py index ad1e257..18e74c5 100755 --- a/gtest_parallel_tests.py +++ b/gtest_parallel_tests.py
@@ -18,6 +18,7 @@ import os.path import random import shutil +import sys import tempfile import threading import time @@ -412,5 +413,38 @@ worker.join() +class TestFilterFormat(unittest.TestCase): + def test_log_file_names(self): + def root(): + return 'C:\\' if sys.platform == 'win32' else '/' + + self.assertEqual( + 'bin-Test_case-100.log', + gtest_parallel.Task._logname('', 'bin', 'Test.case', 100)) + + self.assertEqual( + os.path.join('..', 'a', 'b', 'bin-Test_case_2-1.log'), + gtest_parallel.Task._logname(os.path.join('..', 'a', 'b'), + os.path.join('..', 'bin'), + 'Test.case/2', 1)) + + self.assertEqual( + os.path.join('..', 'a', 'b', 'bin-Test_case_2-5.log'), + gtest_parallel.Task._logname(os.path.join('..', 'a', 'b'), + os.path.join(root(), 'c', 'd', 'bin'), + 'Test.case/2', 5)) + + self.assertEqual( + os.path.join(root(), 'a', 'b', 'bin-Instantiation_Test_case_2-3.log'), + gtest_parallel.Task._logname(os.path.join(root(), 'a', 'b'), + os.path.join('..', 'c', 'bin'), + 'Instantiation/Test.case/2', 3)) + + self.assertEqual( + os.path.join(root(), 'a', 'b', 'bin-Test_case-1.log'), + gtest_parallel.Task._logname(os.path.join(root(), 'a', 'b'), + os.path.join(root(), 'c', 'd', 'bin'), + 'Test.case', 1)) + if __name__ == '__main__': unittest.main()