From f901623876544c984e79bd993e30294458d31af7 Mon Sep 17 00:00:00 2001 From: Robert Findley Date: Mon, 19 Sep 2022 18:02:00 -0400 Subject: [PATCH] gopls/internal/lsp: suppress noisy log output in tests Disable logging for lsp tests: logs are not scoped to the failing test and are therefore misleading. For golang/go#54845 Change-Id: I232e4cfc114382121923e8e697452007793ec3c9 Reviewed-on: https://go-review.googlesource.com/c/tools/+/431843 gopls-CI: kokoro Reviewed-by: Alan Donovan TryBot-Result: Gopher Robot Run-TryBot: Robert Findley --- gopls/internal/lsp/lsp_test.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/gopls/internal/lsp/lsp_test.go b/gopls/internal/lsp/lsp_test.go index 6656549cd7..7a8dd80954 100644 --- a/gopls/internal/lsp/lsp_test.go +++ b/gopls/internal/lsp/lsp_test.go @@ -15,14 +15,15 @@ import ( "strings" "testing" - "golang.org/x/tools/internal/bug" "golang.org/x/tools/gopls/internal/lsp/cache" "golang.org/x/tools/gopls/internal/lsp/command" - "golang.org/x/tools/internal/diff" "golang.org/x/tools/gopls/internal/lsp/protocol" "golang.org/x/tools/gopls/internal/lsp/source" "golang.org/x/tools/gopls/internal/lsp/tests" "golang.org/x/tools/gopls/internal/lsp/tests/compare" + "golang.org/x/tools/internal/bug" + "golang.org/x/tools/internal/diff" + "golang.org/x/tools/internal/event" "golang.org/x/tools/internal/span" "golang.org/x/tools/internal/testenv" ) @@ -30,6 +31,14 @@ import ( func TestMain(m *testing.M) { bug.PanicOnBugs = true testenv.ExitIfSmallMachine() + + // Set the global exporter to nil so that we don't log to stderr. This avoids + // a lot of misleading noise in test output. + // + // TODO(rfindley): investigate whether we can/should capture logs scoped to + // individual tests by passing in a context with a local exporter. + event.SetExporter(nil) + os.Exit(m.Run()) }