Skip to content

Commit c892d0b

Browse files
committed
gopls/test/quickfix_test: verify that issue 70755 is fixed
As of last December, quickfixes (and unimported completions) failed to cope with packages whose name was not the name of their directory. This test shows that this no longer happens. Fixes: golang.go/go#70755 Change-Id: Ifb64ca46329b01471a02bb94995032d60d279367 Reviewed-on: https://go-review.googlesource.com/c/tools/+/706256 Reviewed-by: Madeline Kalil <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent fde1c99 commit c892d0b

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

gopls/internal/test/integration/workspace/quickfix_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,3 +456,53 @@ var _ [int("")]byte
456456
}
457457
})
458458
}
459+
460+
// quick fix didn't offer add imports
461+
func TestIssue70755(t *testing.T) {
462+
files := `
463+
-- go.mod --
464+
module failure.com
465+
go 1.23
466+
-- bar/bar.go --
467+
package notbar
468+
type NotBar struct{}
469+
-- baz/baz.go --
470+
package baz
471+
type Baz struct{}
472+
-- foo/foo.go --
473+
package foo
474+
type foo struct {
475+
bar notbar.NotBar
476+
bzz baz.Baz
477+
}
478+
`
479+
480+
Run(t, files, func(t *testing.T, env *Env) {
481+
env.OpenFile("foo/foo.go")
482+
var d protocol.PublishDiagnosticsParams
483+
env.AfterChange(ReadDiagnostics("foo/foo.go", &d))
484+
// should get two, one for undefined notbar
485+
// and one for undefined baz
486+
fixes := env.GetQuickFixes("foo/foo.go", d.Diagnostics)
487+
if len(fixes) != 2 {
488+
t.Fatalf("got %v, want 2 quick fixes", fixes)
489+
}
490+
good := 0
491+
failures := ""
492+
for _, f := range fixes {
493+
ti := f.Title
494+
// these may be overly white-space sensitive
495+
if ti == "Add import: notbar \"failure.com/bar\"" ||
496+
ti == "Add import: \"failure.com/baz\"" {
497+
good++
498+
} else {
499+
failures += ti
500+
}
501+
}
502+
if good != 2 {
503+
t.Errorf("failed to find\n%q, got\n%q\n%q", failures, fixes[0].Title,
504+
fixes[1].Title)
505+
}
506+
507+
})
508+
}

0 commit comments

Comments
 (0)