2019-10-29 02:38:47 -06:00
|
|
|
// Copyright 2019 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 cmdtest
|
|
|
|
|
|
|
|
import (
|
2020-03-05 07:42:47 -07:00
|
|
|
"fmt"
|
2019-10-29 02:38:47 -06:00
|
|
|
"testing"
|
|
|
|
|
2020-01-22 12:23:12 -07:00
|
|
|
"golang.org/x/tools/internal/lsp/tests"
|
2019-10-29 02:38:47 -06:00
|
|
|
"golang.org/x/tools/internal/span"
|
|
|
|
)
|
|
|
|
|
2020-03-05 07:42:47 -07:00
|
|
|
func (r *runner) SuggestedFix(t *testing.T, spn span.Span, actionKinds []string) {
|
2019-10-29 02:38:47 -06:00
|
|
|
uri := spn.URI()
|
|
|
|
filename := uri.Filename()
|
2020-03-05 07:42:47 -07:00
|
|
|
args := []string{"fix", "-a", fmt.Sprintf("%s", spn)}
|
2020-06-12 15:10:06 -06:00
|
|
|
for _, kind := range actionKinds {
|
|
|
|
if kind == "refactor.rewrite" {
|
|
|
|
t.Skip("refactor.rewrite is not yet supported on the command line")
|
|
|
|
}
|
|
|
|
}
|
2020-03-05 07:42:47 -07:00
|
|
|
args = append(args, actionKinds...)
|
|
|
|
got, _ := r.NormalizeGoplsCmd(t, args...)
|
2020-01-22 12:23:12 -07:00
|
|
|
want := string(r.data.Golden("suggestedfix_"+tests.SpanName(spn), filename, func() ([]byte, error) {
|
2019-10-29 02:38:47 -06:00
|
|
|
return []byte(got), nil
|
|
|
|
}))
|
|
|
|
if want != got {
|
2020-06-12 15:10:06 -06:00
|
|
|
t.Errorf("suggested fixes failed for %s: %s", filename, tests.Diff(want, got))
|
2019-10-29 02:38:47 -06:00
|
|
|
}
|
|
|
|
}
|