2019-10-29 02:41:12 -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 (
|
|
|
|
"os/exec"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"golang.org/x/tools/internal/span"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (r *runner) Import(t *testing.T, spn span.Span) {
|
|
|
|
uri := spn.URI()
|
|
|
|
filename := uri.Filename()
|
2019-11-21 17:58:38 -07:00
|
|
|
got, _ := r.NormalizeGoplsCmd(t, "imports", filename)
|
2019-10-29 02:41:12 -06:00
|
|
|
want := string(r.data.Golden("goimports", filename, func() ([]byte, error) {
|
|
|
|
cmd := exec.Command("goimports", filename)
|
|
|
|
out, _ := cmd.Output() // ignore error, sometimes we have intentionally ungofmt-able files
|
|
|
|
return out, nil
|
|
|
|
}))
|
|
|
|
if want != got {
|
2019-10-11 09:03:23 -06:00
|
|
|
t.Errorf("imports failed for %s, expected:\n%q\ngot:\n%q", filename, want, got)
|
2019-10-29 02:41:12 -06:00
|
|
|
}
|
|
|
|
}
|