Skip to content

Commit ca7f26b

Browse files
committed
test_message_order: better error handling for when view is updated
This makes it so that it can wait a little longer for the view to update, and also provides a little better error message.
1 parent 1a79bda commit ca7f26b

File tree

1 file changed

+29
-11
lines changed

1 file changed

+29
-11
lines changed

tests/test_message_order.py

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,19 @@ def _test_message_order(self, view, messages, inline, command):
106106

107107
to_close = []
108108

109+
# Helper to check when the view is updated to the correct location.
110+
def check_view_has_updated(window, expected_filename, expected_row_col):
111+
view = window.active_view()
112+
view_filename = os.path.normpath(view.file_name())
113+
if view_filename != expected_filename:
114+
return False
115+
region = view.sel()[0]
116+
rowcol = view.rowcol(region.begin())
117+
if expected_row_col[1] is None:
118+
return rowcol[0] == expected_row_col[0]
119+
else:
120+
return rowcol == expected_row_col
121+
109122
def check_sequence(direction):
110123
omsgs = messages if direction == 'next' else reversed(messages)
111124
levels = ('all', 'error', 'warning') if inline else ('all',)
@@ -124,22 +137,27 @@ def check_sequence(direction):
124137
window.run_command('rust_' + direction + '_message',
125138
{'levels': level})
126139
# Sublime doesn't always immediately move the active
127-
# view when 'next_result' is called, so give it a
128-
# moment to update.
129-
time.sleep(0.1)
130-
next_view = window.active_view()
131-
to_close.append(next_view)
132-
self.assertEqual(os.path.normpath(next_view.file_name()),
133-
os.path.normpath(next_filename))
134-
region = next_view.sel()[0]
135-
rowcol = next_view.rowcol(region.begin())
140+
# view when 'next_result' is called, so loop until
141+
# it looks like it has updated to the correct location.
142+
expected_filename = os.path.normpath(next_filename)
136143
if inline:
137-
self.assertEqual(rowcol, next_row_col)
144+
expected_row_col = next_row_col
138145
else:
139146
# When inline is disabled, we use Sublime's
140147
# built-in next/prev, which goes to the beginning.
141148
# Just validate the row is correct.
142-
self.assertEqual(rowcol[0], next_row_col[0])
149+
expected_row_col = (next_row_col[0], None)
150+
for _ in range(30):
151+
if check_view_has_updated(window, expected_filename, expected_row_col):
152+
break
153+
time.sleep(0.1)
154+
else:
155+
view = window.active_view()
156+
raise AssertionError('view did not update to %r at %r as expected\ncurrent view is %r at %r' % (
157+
expected_filename, expected_row_col,
158+
view.file_name(), view.rowcol(view.sel()[0].begin()))
159+
)
160+
to_close.append(window.active_view())
143161
# Verify the output panel is highlighting the correct
144162
# thing.
145163
build_panel = window.find_output_panel(

0 commit comments

Comments
 (0)