Skip to content

Commit

Permalink
internal/lsp/regtest: add regression test for golang/go#36960
Browse files Browse the repository at this point in the history
It's in the build tagged tests because the fix is only in 1.14.

Fixes golang/go#36960

Change-Id: I606dfb4f73735c6db8c48f67f19720d340be8361
Reviewed-on: https://go-review.googlesource.com/c/tools/+/232991
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
  • Loading branch information
stamblerre committed May 12, 2020
1 parent 5485bfc commit aaeff5d
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 7 deletions.
3 changes: 3 additions & 0 deletions internal/lsp/fake/editor.go
Expand Up @@ -288,7 +288,10 @@ func (e *Editor) SaveBuffer(ctx context.Context, path string) error {
if err := e.FormatBuffer(ctx, path); err != nil {
return fmt.Errorf("formatting before save: %w", err)
}
return e.SaveBufferWithoutActions(ctx, path)
}

func (e *Editor) SaveBufferWithoutActions(ctx context.Context, path string) error {
e.mu.Lock()
buf, ok := e.buffers[path]
if !ok {
Expand Down
40 changes: 39 additions & 1 deletion internal/lsp/regtest/diagnostics_114_test.go
Expand Up @@ -2,13 +2,14 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// +build 1.14
//+build go1.14

package regtest

import (
"testing"

"golang.org/x/tools/internal/lsp"
"golang.org/x/tools/internal/lsp/fake"
"golang.org/x/tools/internal/lsp/protocol"
)
Expand Down Expand Up @@ -122,3 +123,40 @@ func main() {
)
}, WithProxy(ardanLabsProxy))
}

func TestNewFileBadImports_Issue36960(t *testing.T) {
const simplePackage = `
-- go.mod --
module mod.com
go 1.14
-- a/a1.go --
package a
import "fmt"
func _() {
fmt.Println("hi")
}
`
runner.Run(t, simplePackage, func(t *testing.T, env *Env) {
env.OpenFile("a/a1.go")
env.CreateBuffer("a/a2.go", ``)
if err := env.Editor.SaveBufferWithoutActions(env.Ctx, "a/a2.go"); err != nil {
t.Fatal(err)
}
env.Await(
OnceMet(
CompletedWork(lsp.DiagnosticWorkTitle(lsp.FromDidSave), 1),
NoDiagnostics("a/a1.go"),
),
)
env.EditBuffer("a/a2.go", fake.NewEdit(0, 0, 0, 0, `package a`))
env.Await(
OnceMet(
CompletedWork(lsp.DiagnosticWorkTitle(lsp.FromDidChange), 1),
NoDiagnostics("a/a1.go"),
),
)
})
}
19 changes: 15 additions & 4 deletions internal/lsp/regtest/diagnostics_test.go
Expand Up @@ -293,8 +293,10 @@ func main() {}
// package renaming was fully processed. Therefore, in order for this
// test to actually exercise the bug, we must wait until that work has
// completed.
NoDiagnostics("a.go"),
CompletedWork(lsp.DiagnosticWorkTitle(lsp.FromDidChange), 1),
OnceMet(
CompletedWork(lsp.DiagnosticWorkTitle(lsp.FromDidChange), 1),
NoDiagnostics("a.go"),
),
)
})
}
Expand Down Expand Up @@ -473,7 +475,13 @@ func f() {
`
runner.Run(t, noModule, func(t *testing.T, env *Env) {
env.OpenFile("a.go")
env.Await(NoDiagnostics("a.go"), EmptyShowMessage(""))
env.Await(
OnceMet(
CompletedWork(lsp.DiagnosticWorkTitle(lsp.FromDidOpen), 1),
NoDiagnostics("a.go"),
),
EmptyShowMessage(""),
)
// introduce an error, expect no Show Message
env.RegexpReplace("a.go", "func", "fun")
env.Await(env.DiagnosticAtRegexp("a.go", "fun"), EmptyShowMessage(""))
Expand Down Expand Up @@ -514,7 +522,10 @@ func main() {
}
badFile := fmt.Sprintf("%s/found packages main (main.go) and x (x.go) in %s/src/x", dir, env.Sandbox.GOPATH())
env.Await(
EmptyDiagnostics("x/main.go"),
OnceMet(
CompletedWork(lsp.DiagnosticWorkTitle(lsp.FromDidChange), 1),
EmptyDiagnostics("x/main.go"),
),
NoDiagnostics(badFile),
)
}, InGOPATH())
Expand Down
6 changes: 4 additions & 2 deletions internal/lsp/regtest/env.go
Expand Up @@ -479,7 +479,9 @@ func EmptyDiagnostics(name string) Expectation {
}

// NoDiagnostics asserts that no diagnostics are sent for the
// workspace-relative path name.
// workspace-relative path name. It should be used primarily in conjunction
// with a OnceMet, as it has to check that all outstanding diagnostics have
// already been delivered.
func NoDiagnostics(name string) Expectation {
check := func(s State) (Verdict, interface{}) {
if _, ok := s.diagnostics[name]; !ok {
Expand All @@ -489,7 +491,7 @@ func NoDiagnostics(name string) Expectation {
}
return SimpleExpectation{
check: check,
description: "empty diagnostics",
description: "no diagnostics",
}
}

Expand Down

0 comments on commit aaeff5d

Please sign in to comment.