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)}
|
|
|
|
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 {
|
|
|
|
t.Errorf("suggested fixes failed for %s, expected:\n%v\ngot:\n%v", filename, want, got)
|
|
|
|
}
|
|
|
|
}
|