Skip to content

Commit 6f625bd

Browse files
authored
Fix windows color terminal output (#24828)
We cannot actually test this is working, but we can at least test that it doesn't crash. Fixes: #24824
1 parent e5c41db commit 6f625bd

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

test/test_other.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12407,7 +12407,15 @@ def test_color_diagnostics_force(self, flag):
1240712407
output = self.expect_fail([EMCC, '-fansi-escape-codes', flag, 'src.c'])
1240812408
self.assertIn("\x1b[1msrc.c:1:13: \x1b[0m\x1b[0;1;31merror: \x1b[0m\x1b[1mexpected '}'\x1b[0m", output)
1240912409
# Verify that emcc errors show up as red and bold
12410-
self.assertIn("emcc: \x1b[31m\x1b[1m", output)
12410+
self.assertIn('emcc: \x1b[31m\x1b[1m', output)
12411+
12412+
if WINDOWS:
12413+
# Also test without -fansi-escape-codes on windows.
12414+
# In those mode the code will use kernel calls such as SetConsoleTextAttribute to
12415+
# change the output color. We cannot detect this in the output, but we can at least
12416+
# get coverage of the code path in the diagnositics.py.
12417+
output = self.expect_fail([EMCC, flag, 'src.c'])
12418+
self.assertNotIn('\x1b', output)
1241112419

1241212420
def test_sanitizer_color(self):
1241312421
create_file('src.c', '''

tools/diagnostics.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ def reset_color_windows():
116116

117117
def output_color(color):
118118
if WINDOWS and not force_ansi:
119-
return output_color_windows(color)
119+
output_color_windows(color)
120+
return ''
120121
return '\033[3%sm' % color
121122

122123

@@ -129,7 +130,8 @@ def bold():
129130

130131
def reset_color():
131132
if WINDOWS and not force_ansi:
132-
return reset_color_windows()
133+
reset_color_windows()
134+
return ''
133135
return '\033[0m'
134136

135137

0 commit comments

Comments
 (0)