diff --git a/tests/wpt/grouping_formatter.py b/tests/wpt/grouping_formatter.py index c97101ca86c..75ec5d4c674 100644 --- a/tests/wpt/grouping_formatter.py +++ b/tests/wpt/grouping_formatter.py @@ -17,11 +17,16 @@ class GroupingFormatter(base.BaseFormatter): self.need_to_erase_last_line = False self.current_display = "" self.running_tests = {} + self.last_test_finished = "Running tests..." self.test_output = collections.defaultdict(str) self.subtest_failures = collections.defaultdict(list) self.tests_with_failing_subtests = [] self.interactive = os.isatty(sys.stdout.fileno()) + # iTerm2 doesn't support the terminal codes used to erase previous lines, + # so only print one line and rely only on backspace characters. + self.one_line = os.environ.get("TERM_PROGRAM", "") == "iTerm.app" + self.expected = { 'OK': 0, 'PASS': 0, @@ -44,8 +49,13 @@ class GroupingFormatter(base.BaseFormatter): def text_to_erase_display(self): if not self.interactive or not self.current_display: return "" + # TODO(mrobinson, 8313): We need to add support for Windows terminals here. - return ("\033[F" + "\033[K") * len(self.current_display.splitlines()) + erase_length = len(self.current_display) + if self.one_line: + return "\b \b" * erase_length + else: + return ("\033[F" + "\033[K") * len(self.current_display.splitlines()) def generate_output(self, text=None, new_display=None): if not self.interactive: @@ -64,6 +74,9 @@ class GroupingFormatter(base.BaseFormatter): else: new_display = " [%i/%i] " % (self.completed_tests, self.number_of_tests) + if self.one_line: + return new_display + self.last_test_finished + if self.running_tests: indent = " " * len(new_display) return new_display + ("\n%s" % indent).join( @@ -161,11 +174,16 @@ class GroupingFormatter(base.BaseFormatter): subtest_failures = self.subtest_failures.pop(test_name, []) del self.running_tests[data['thread']] + self.last_test_finished = test_name new_display = self.build_status_line() if not had_unexpected_test_result and not subtest_failures: self.expected[test_status] += 1 - return self.generate_output(text=None, new_display=new_display) + if self.interactive: + return self.generate_output(text=None, new_display=new_display) + else: + return self.generate_output(text=" %s\n\n" % test_name, + new_display=new_display) # If the test crashed or timed out, we also include any process output, # because there is a good chance that the test produced a stack trace