-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
go/analysis: remove stray print statement in the timeformat analyzer
A debugging print statement was left in the analyzer, which breaks gopls' communication over stdin/stdout. Fix this, and add tests. Fixes golang/vscode-go#2406 Change-Id: I1b785fa09e66eae2f1b1e03806e5b59d2015e75e Reviewed-on: https://go-review.googlesource.com/c/tools/+/422902 TryBot-Result: Gopher Robot <[email protected]> gopls-CI: kokoro <[email protected]> Run-TryBot: Robert Findley <[email protected]> Reviewed-by: Tim King <[email protected]>
- Loading branch information
Showing
5 changed files
with
62 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright 2022 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package diagnostics | ||
|
||
import ( | ||
"testing" | ||
|
||
"golang.org/x/tools/internal/lsp/protocol" | ||
. "golang.org/x/tools/internal/lsp/regtest" | ||
) | ||
|
||
// Test for the timeformat analyzer, following golang/vscode-go#2406. | ||
// | ||
// This test checks that applying the suggested fix from the analyzer resolves | ||
// the diagnostic warning. | ||
func TestTimeFormatAnalyzer(t *testing.T) { | ||
const files = ` | ||
-- go.mod -- | ||
module mod.com | ||
go 1.18 | ||
-- main.go -- | ||
package main | ||
import ( | ||
"fmt" | ||
"time" | ||
) | ||
func main() { | ||
now := time.Now() | ||
fmt.Println(now.Format("2006-02-01")) | ||
}` | ||
|
||
Run(t, files, func(t *testing.T, env *Env) { | ||
env.OpenFile("main.go") | ||
|
||
var d protocol.PublishDiagnosticsParams | ||
env.Await( | ||
OnceMet( | ||
env.DoneWithOpen(), | ||
env.DiagnosticAtRegexp("main.go", "2006-02-01"), | ||
ReadDiagnostics("main.go", &d), | ||
), | ||
) | ||
|
||
env.ApplyQuickFixes("main.go", d.Diagnostics) | ||
env.Await( | ||
EmptyDiagnostics("main.go"), | ||
) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters