Skip to content

Commit 9f93fd2

Browse files
author
Jay Conrod
committed
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>
1 parent 07b72d9 commit 9f93fd2

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

src/cmd/go/internal/modfile/read_test.go

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@ import (
99
"fmt"
1010
"io/ioutil"
1111
"os"
12+
"os/exec"
1213
"path/filepath"
1314
"reflect"
1415
"strings"
1516
"testing"
16-
17-
"cmd/internal/diff"
1817
)
1918

2019
// exists reports whether the named file exists.
@@ -283,9 +282,37 @@ func (eq *eqchecker) checkValue(v, w reflect.Value) error {
283282
return nil
284283
}
285284

285+
// diff returns the output of running diff on b1 and b2.
286+
func diff(b1, b2 []byte) (data []byte, err error) {
287+
f1, err := ioutil.TempFile("", "testdiff")
288+
if err != nil {
289+
return nil, err
290+
}
291+
defer os.Remove(f1.Name())
292+
defer f1.Close()
293+
294+
f2, err := ioutil.TempFile("", "testdiff")
295+
if err != nil {
296+
return nil, err
297+
}
298+
defer os.Remove(f2.Name())
299+
defer f2.Close()
300+
301+
f1.Write(b1)
302+
f2.Write(b2)
303+
304+
data, err = exec.Command("diff", "-u", f1.Name(), f2.Name()).CombinedOutput()
305+
if len(data) > 0 {
306+
// diff exits with a non-zero status when the files don't match.
307+
// Ignore that failure as long as we get output.
308+
err = nil
309+
}
310+
return
311+
}
312+
286313
// tdiff logs the diff output to t.Error.
287314
func tdiff(t *testing.T, a, b string) {
288-
data, err := diff.Diff("modfile-test", []byte(a), []byte(b))
315+
data, err := diff([]byte(a), []byte(b))
289316
if err != nil {
290317
t.Error(err)
291318
return

0 commit comments

Comments
 (0)