Skip to content

Commit d80ab5d

Browse files
volo-zykopbos
authored andcommitted
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.
1 parent 6f65b6c commit d80ab5d

File tree

2 files changed

+45
-7
lines changed

2 files changed

+45
-7
lines changed

gtest_parallel.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,8 @@ def __init__(self, test_binary, test_name, test_command, execution_number,
167167
self.test_id = (test_binary, test_name)
168168
self.task_id = (test_binary, test_name, self.execution_number)
169169

170-
log_name = '%s-%s-%s.log' % (self.__normalize(test_binary),
171-
self.__normalize(test_name),
172-
self.execution_number)
173-
174-
self.log_file = os.path.join(output_dir, log_name)
170+
self.log_file = Task._logname(self.output_dir, self.test_binary,
171+
test_name, self.execution_number)
175172

176173
def __lt__(self, other):
177174
if self.last_execution_time is None:
@@ -180,9 +177,17 @@ def __lt__(self, other):
180177
return False
181178
return self.last_execution_time > other.last_execution_time
182179

183-
def __normalize(self, string):
180+
@staticmethod
181+
def _normalize(string):
184182
return re.sub('[^A-Za-z0-9]', '_', string)
185183

184+
@staticmethod
185+
def _logname(output_dir, test_binary, test_name, execution_number):
186+
log_name = '%s-%s-%d.log' % (Task._normalize(os.path.basename(test_binary)),
187+
Task._normalize(test_name), execution_number)
188+
189+
return os.path.join(output_dir, log_name)
190+
186191
def run(self):
187192
begin = time.time()
188193
with open(self.log_file, 'w') as log:
@@ -288,7 +293,6 @@ def move_to(self, destination_dir, tasks):
288293
for task in tasks:
289294
shutil.move(task.log_file, destination_dir)
290295

291-
292296
def print_tests(self, message, tasks, print_try_number):
293297
self.out.permanent_line("%s (%s/%s):" %
294298
(message, len(tasks), self.total_tasks))

gtest_parallel_tests.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import os.path
1919
import random
2020
import shutil
21+
import sys
2122
import tempfile
2223
import threading
2324
import time
@@ -412,5 +413,38 @@ def test_times_worker():
412413
worker.join()
413414

414415

416+
class TestFilterFormat(unittest.TestCase):
417+
def test_log_file_names(self):
418+
def root():
419+
return 'C:\\' if sys.platform == 'win32' else '/'
420+
421+
self.assertEqual(
422+
'bin-Test_case-100.log',
423+
gtest_parallel.Task._logname('', 'bin', 'Test.case', 100))
424+
425+
self.assertEqual(
426+
os.path.join('..', 'a', 'b', 'bin-Test_case_2-1.log'),
427+
gtest_parallel.Task._logname(os.path.join('..', 'a', 'b'),
428+
os.path.join('..', 'bin'),
429+
'Test.case/2', 1))
430+
431+
self.assertEqual(
432+
os.path.join('..', 'a', 'b', 'bin-Test_case_2-5.log'),
433+
gtest_parallel.Task._logname(os.path.join('..', 'a', 'b'),
434+
os.path.join(root(), 'c', 'd', 'bin'),
435+
'Test.case/2', 5))
436+
437+
self.assertEqual(
438+
os.path.join(root(), 'a', 'b', 'bin-Instantiation_Test_case_2-3.log'),
439+
gtest_parallel.Task._logname(os.path.join(root(), 'a', 'b'),
440+
os.path.join('..', 'c', 'bin'),
441+
'Instantiation/Test.case/2', 3))
442+
443+
self.assertEqual(
444+
os.path.join(root(), 'a', 'b', 'bin-Test_case-1.log'),
445+
gtest_parallel.Task._logname(os.path.join(root(), 'a', 'b'),
446+
os.path.join(root(), 'c', 'd', 'bin'),
447+
'Test.case', 1))
448+
415449
if __name__ == '__main__':
416450
unittest.main()

0 commit comments

Comments
 (0)