From 1c0c6cf43e70e5fa150b63e46fb232d9eab42bc5 Mon Sep 17 00:00:00 2001 From: Pontus Leitzler Date: Wed, 3 Jun 2020 17:27:22 +0200 Subject: [PATCH] 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 Run-TryBot: Rebecca Stambler TryBot-Result: Gobot Gobot --- internal/lsp/source/source_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/lsp/source/source_test.go b/internal/lsp/source/source_test.go index b0e50d5a57..95922c8f9d 100644 --- a/internal/lsp/source/source_test.go +++ b/internal/lsp/source/source_test.go @@ -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