x/tools/internal/lsp/source: avoid panic in failing Highlight test

When testing Highlight the highlight count is checked against expected
number of highlights. If it doesn't match t.Errorf(...) is called and
the test continues.

A few lines below the test ranges over results using the index for both
result and expected result leading to a panic if there are less then
expected highlights.

This change fails fast with t.Fatalf(...) instead to avoid the panic.

Change-Id: I33d0973f3145c307d9084d037ffbb73b244a3acb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/236099
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Pontus Leitzler 2020-06-03 17:27:22 +02:00 committed by Rebecca Stambler
parent a45abac6c9
commit 1c0c6cf43e
1 changed files with 1 additions and 1 deletions

View File

@ -592,7 +592,7 @@ func (r *runner) Highlight(t *testing.T, src span.Span, locations []span.Span) {
t.Errorf("highlight failed for %s: %v", src.URI(), err)
}
if len(highlights) != len(locations) {
t.Errorf("got %d highlights for highlight at %v:%v:%v, expected %d", len(highlights), src.URI().Filename(), src.Start().Line(), src.Start().Column(), len(locations))
t.Fatalf("got %d highlights for highlight at %v:%v:%v, expected %d", len(highlights), src.URI().Filename(), src.Start().Line(), src.Start().Column(), len(locations))
}
// Check to make sure highlights have a valid range.
var results []span.Span