Skip to content

Commit 5b42968

Browse files
authored
Fix status message output for single line test output. NFC (emscripten-core#25838)
We now use the full terminal width and only truncate when we need to. Fixes: emscripten-core#25836
1 parent 425a4bc commit 5b42968

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

test/single_line_runner.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,17 @@ def clearline(stream):
1616

1717

1818
def term_width():
19-
return shutil.get_terminal_size()[0]
19+
return shutil.get_terminal_size().columns
2020

2121

2222
class SingleLineTestResult(ColorTextResult):
2323
"""Similar to the standard TextTestResult but uses ANSI escape codes
2424
for color output and reusing a single line on the terminal.
2525
"""
26-
max_status_msg = 20
26+
27+
# Reserve at least 20 columns for the status message
28+
min_status_msg = 20
29+
status_limit = None
2730

2831
def _write_status(self, _test, status):
2932
# Add some color to the status message
@@ -36,7 +39,7 @@ def _write_status(self, _test, status):
3639
status += '\n'
3740
else:
3841
color = CYAN
39-
status = status[:self.max_status_msg]
42+
status = status[:self.status_limit]
4043
line = f'{with_color(color, status)}'
4144
self.stream.write(line)
4245
self.stream.flush()
@@ -47,12 +50,17 @@ def startTest(self, test):
4750
self.showAll = True
4851
clearline(self.stream)
4952
prefix_len = self.writeProgressPrefix()
50-
max_desc = term_width() - prefix_len - len(' ... ') - self.max_status_msg
53+
total_width = term_width()
54+
max_desc = total_width - prefix_len - len(' ... ') - self.min_status_msg
5155
desc = str(test)[:max_desc]
5256
self.stream.write(desc)
5357
self.stream.write(' ... ')
5458
self.stream.flush()
5559

60+
# Calcualte the remaining terminal width available for the _write_status
61+
# message. This will never be lower that `self.max_status_msg`
62+
self.status_limit = total_width - prefix_len - len(desc) - len(' ... ')
63+
5664
def printErrors(self):
5765
# All tests have been run at this point so print a final newline
5866
# to end out status line

0 commit comments

Comments
 (0)