]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go/internal/modfile: don't use cmd/internal/diff
authorJay Conrod <jayconrod@google.com>
Tue, 29 Oct 2019 19:25:22 +0000 (15:25 -0400)
committerJay Conrod <jayconrod@google.com>
Tue, 29 Oct 2019 19:41:46 +0000 (19:41 +0000)
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>
src/cmd/go/internal/modfile/read_test.go

index 3c88e6928157df3ac909e4c4f8a58f33a9f9a7b6..32401304b999f9d82c5bfec59ea0f0030f3b077f 100644 (file)
@@ -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