gopls/internal/test: option to suppress LSP logs on failure

Adds a RunOption NoLogsOnFailure() to suppress the printing of
the voluminous LSP logs when there is a test failure. While debugging
tests these logs can be a noisy distraction.

Change-Id: I41379fdcef8ba00f8b8a49ec89d8795274797888
Reviewed-on: https://go-review.googlesource.com/c/tools/+/574035
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
diff --git a/gopls/internal/test/integration/options.go b/gopls/internal/test/integration/options.go
index f1d5425..b36ebc9 100644
--- a/gopls/internal/test/integration/options.go
+++ b/gopls/internal/test/integration/options.go
@@ -10,9 +10,10 @@
 )
 
 type runConfig struct {
-	editor  fake.EditorConfig
-	sandbox fake.SandboxConfig
-	modes   Mode
+	editor        fake.EditorConfig
+	sandbox       fake.SandboxConfig
+	modes         Mode
+	noLogsOnError bool
 }
 
 func defaultConfig() runConfig {
@@ -59,6 +60,13 @@
 	})
 }
 
+// NoLogsOnError turns off dumping the LSP logs on test failures.
+func NoLogsOnError() RunOption {
+	return optionSetter(func(opts *runConfig) {
+		opts.noLogsOnError = true
+	})
+}
+
 // WindowsLineEndings configures the editor to use windows line endings.
 func WindowsLineEndings() RunOption {
 	return optionSetter(func(opts *runConfig) {
diff --git a/gopls/internal/test/integration/runner.go b/gopls/internal/test/integration/runner.go
index 7696b34..ed33358 100644
--- a/gopls/internal/test/integration/runner.go
+++ b/gopls/internal/test/integration/runner.go
@@ -235,7 +235,7 @@
 				if t.Failed() && r.PrintGoroutinesOnFailure {
 					pprof.Lookup("goroutine").WriteTo(os.Stderr, 1)
 				}
-				if t.Failed() || *printLogs {
+				if (t.Failed() && !config.noLogsOnError) || *printLogs {
 					ls.printBuffers(t.Name(), os.Stderr)
 				}
 				// For tests that failed due to a timeout, don't fail to shutdown