mirror of
https://github.com/golang/go
synced 2024-11-18 06:54:49 -07:00
cmd/go/internal/modfile: don't use cmd/internal/diff
This is a partial revert of CL 203218. cmd/go/internal/modfile is about to be deleted and replaced with golang.org/x/mod/modfile in CL 202698. cmd/internal/diff is not visible from golang.org/x/mod/modfile, and it doesn't make sense to extract it into a new package there. Updates #31761 Change-Id: I3bbbc4cae81120020e1092c1138524729530b415 Reviewed-on: https://go-review.googlesource.com/c/go/+/204103 Run-TryBot: Jay Conrod <jayconrod@google.com> Reviewed-by: Bryan C. Mills <bcmills@google.com>
This commit is contained in:
parent
07b72d9189
commit
9f93fd225f
@ -9,12 +9,11 @@ import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"cmd/internal/diff"
|
||||
)
|
||||
|
||||
// exists reports whether the named file exists.
|
||||
@ -283,9 +282,37 @@ func (eq *eqchecker) checkValue(v, w reflect.Value) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// diff returns the output of running diff on b1 and b2.
|
||||
func diff(b1, b2 []byte) (data []byte, err error) {
|
||||
f1, err := ioutil.TempFile("", "testdiff")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer os.Remove(f1.Name())
|
||||
defer f1.Close()
|
||||
|
||||
f2, err := ioutil.TempFile("", "testdiff")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer os.Remove(f2.Name())
|
||||
defer f2.Close()
|
||||
|
||||
f1.Write(b1)
|
||||
f2.Write(b2)
|
||||
|
||||
data, err = exec.Command("diff", "-u", f1.Name(), f2.Name()).CombinedOutput()
|
||||
if len(data) > 0 {
|
||||
// diff exits with a non-zero status when the files don't match.
|
||||
// Ignore that failure as long as we get output.
|
||||
err = nil
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// tdiff logs the diff output to t.Error.
|
||||
func tdiff(t *testing.T, a, b string) {
|
||||
data, err := diff.Diff("modfile-test", []byte(a), []byte(b))
|
||||
data, err := diff([]byte(a), []byte(b))
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
|
Loading…
Reference in New Issue
Block a user