mirror of
https://github.com/golang/go
synced 2024-11-19 05:54:44 -07:00
5889748991
Change-Id: I2f94c2a68d0036a47ccac3fce07cf9f3b784d443 Reviewed-on: https://go-review.googlesource.com/c/tools/+/200558 Run-TryBot: Ian Cottrell <iancottrell@google.com> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
41 lines
1.2 KiB
Go
41 lines
1.2 KiB
Go
// 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 (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"golang.org/x/tools/internal/lsp/cmd"
|
|
"golang.org/x/tools/internal/span"
|
|
"golang.org/x/tools/internal/tool"
|
|
)
|
|
|
|
func (r *runner) Rename(t *testing.T, spn span.Span, newText string) {
|
|
filename := spn.URI().Filename()
|
|
goldenTag := newText + "-rename"
|
|
app := cmd.New("gopls-test", r.data.Config.Dir, r.data.Config.Env, r.options)
|
|
loc := fmt.Sprintf("%v", spn)
|
|
var err error
|
|
got := CaptureStdOut(t, func() {
|
|
err = tool.Run(r.ctx, app, []string{"-remote=internal", "rename", loc, newText})
|
|
})
|
|
if err != nil {
|
|
got = err.Error()
|
|
}
|
|
got = normalizePaths(r.data, got)
|
|
expect := string(r.data.Golden(goldenTag, filename, func() ([]byte, error) {
|
|
return []byte(got), nil
|
|
}))
|
|
if expect != got {
|
|
t.Errorf("rename failed with %v %v expected:\n%s\ngot:\n%s", loc, newText, expect, got)
|
|
}
|
|
// now check we can build a valid unified diff
|
|
unified := CaptureStdOut(t, func() {
|
|
_ = tool.Run(r.ctx, app, []string{"-remote=internal", "rename", "-d", loc, newText})
|
|
})
|
|
checkUnified(t, filename, expect, unified)
|
|
}
|