diff --git a/internal/diff/diff_test.go b/internal/diff/diff_test.go
index 2f06856..259c4d0 100644
--- a/internal/diff/diff_test.go
+++ b/internal/diff/diff_test.go
@@ -11,6 +11,7 @@
"os/exec"
"path/filepath"
"reflect"
+ "runtime"
"strings"
"testing"
"unicode/utf8"
@@ -120,7 +121,12 @@
}
func TestToUnified(t *testing.T) {
- testenv.NeedsTool(t, "patch")
+ // Plan 9 has no patch command, so use ape/patch, the POSIX patch.
+ patch := "patch"
+ if runtime.GOOS == "plan9" {
+ patch = "/bin/ape/patch"
+ }
+ testenv.NeedsTool(t, patch)
for _, tc := range difftest.TestCases {
t.Run(tc.Name, func(t *testing.T) {
nedits := diff.Lines(tc.In, tc.Out)
@@ -141,7 +147,7 @@
if err != nil {
t.Fatal(err)
}
- cmd := exec.Command("patch", "-p0", "-u", "-s", "-o", temp, orig)
+ cmd := exec.Command(patch, "-p0", "-u", "-s", "-o", temp, orig)
cmd.Stdin = strings.NewReader(xunified)
cmd.Stdout = new(bytes.Buffer)
cmd.Stderr = new(bytes.Buffer)
diff --git a/internal/diff/difftest/difftest_test.go b/internal/diff/difftest/difftest_test.go
index 84dd115..2230943 100644
--- a/internal/diff/difftest/difftest_test.go
+++ b/internal/diff/difftest/difftest_test.go
@@ -11,6 +11,7 @@
"fmt"
"os"
"os/exec"
+ "runtime"
"strings"
"testing"
@@ -18,9 +19,16 @@
"golang.org/x/tools/internal/testenv"
)
+func diffCmd() string {
+ if runtime.GOOS == "plan9" {
+ return "/bin/ape/diff"
+ }
+ return "diff"
+}
+
// check that the TestCases match diff -u output
func TestVerifyUnified(t *testing.T) {
- testenv.NeedsTool(t, "diff")
+ testenv.NeedsTool(t, diffCmd())
for _, test := range difftest.TestCases {
t.Run(test.Name, func(t *testing.T) {
if test.NoDiff {
@@ -33,8 +41,13 @@
if len(diff) > 0 {
diff = difftest.UnifiedPrefix + diff
}
- if diff != test.Unified {
- t.Errorf("unified:\n%s\ndiff -u:\n%s", test.Unified, diff)
+ want := test.Unified
+ if runtime.GOOS == "plan9" {
+ // ape/diff omits the "\ No newline at end of file" marker.
+ want = strings.ReplaceAll(want, "\\ No newline at end of file\n", "")
+ }
+ if diff != want {
+ t.Errorf("unified:\n%s\ndiff -u:\n%s", want, diff)
}
})
}
@@ -63,7 +76,7 @@
if err := fileB.Close(); err != nil {
return "", err
}
- cmd := exec.Command("diff", "-u", fileA.Name(), fileB.Name())
+ cmd := exec.Command(diffCmd(), "-u", fileA.Name(), fileB.Name())
cmd.Env = append(cmd.Env, "LANG=en_US.UTF-8")
out, err := cmd.Output()
if err != nil {