[tools] internal/diff: use ape/patch and ape/diff on Plan 9

4 views
Skip to first unread message

David du Colombier (Gerrit)

unread,
Jun 26, 2026, 2:06:51 PM (17 hours ago) Jun 26
to Richard Miller, Alan Donovan, Robert Findley, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
Attention needed from Alan Donovan, Richard Miller and Robert Findley

David du Colombier has uploaded the change for review

David du Colombier would like Richard Miller, Alan Donovan and Robert Findley to review this change.

Commit message

internal/diff: use ape/patch and ape/diff on Plan 9

TestToUnified and TestVerifyUnified run the system
patch and diff commands to check the unified diffs
produced by the diff package.

On Plan 9, there is no patch command, and the diff
command does not support the unified (-u) output
format, so both tests fail.

This change uses ape/patch and ape/diff, the POSIX
patch and diff commands, on Plan 9.

ape/diff does not emit the "\ No newline at end of
file" marker, so TestVerifyUnified ignores it when
comparing on Plan 9.
Change-Id: I0bee7e95b0eff91bb224bee9fcd4ab4ad656752c

Change diff

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 {

Change information

Files:
  • M internal/diff/diff_test.go
  • M internal/diff/difftest/difftest_test.go
Change size: S
Delta: 2 files changed, 25 insertions(+), 6 deletions(-)
Open in Gerrit

Related details

Attention is currently required from:
  • Alan Donovan
  • Richard Miller
  • Robert Findley
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newchange
Gerrit-Project: tools
Gerrit-Branch: master
Gerrit-Change-Id: I0bee7e95b0eff91bb224bee9fcd4ab4ad656752c
Gerrit-Change-Number: 794840
Gerrit-PatchSet: 1
Gerrit-Owner: David du Colombier <0in...@gmail.com>
Gerrit-Reviewer: Alan Donovan <adon...@google.com>
Gerrit-Reviewer: Richard Miller <millerr...@gmail.com>
Gerrit-Reviewer: Robert Findley <rfin...@golang.org>
Gerrit-Attention: Richard Miller <millerr...@gmail.com>
Gerrit-Attention: Alan Donovan <adon...@google.com>
Gerrit-Attention: Robert Findley <rfin...@golang.org>
unsatisfied_requirement
satisfied_requirement
open
diffy

Alan Donovan (Gerrit)

unread,
Jun 26, 2026, 2:11:12 PM (17 hours ago) Jun 26
to David du Colombier, goph...@pubsubhelper.golang.org, Peter Weinberger, Richard Miller, golang-co...@googlegroups.com
Attention needed from David du Colombier and Richard Miller

Alan Donovan voted and added 1 comment

Votes added by Alan Donovan

Auto-Submit+1
Code-Review+2
Commit-Queue+1

1 comment

Patchset-level comments
File-level comment, Patchset 1 (Latest):
Alan Donovan . resolved

Thanks!

Open in Gerrit

Related details

Attention is currently required from:
  • David du Colombier
  • Richard Miller
Submit Requirements:
  • requirement satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: tools
Gerrit-Branch: master
Gerrit-Change-Id: I0bee7e95b0eff91bb224bee9fcd4ab4ad656752c
Gerrit-Change-Number: 794840
Gerrit-PatchSet: 1
Gerrit-Owner: David du Colombier <0in...@gmail.com>
Gerrit-Reviewer: Alan Donovan <adon...@google.com>
Gerrit-Reviewer: Richard Miller <millerr...@gmail.com>
Gerrit-CC: Peter Weinberger <p...@google.com>
Gerrit-Attention: David du Colombier <0in...@gmail.com>
Gerrit-Attention: Richard Miller <millerr...@gmail.com>
Gerrit-Comment-Date: Fri, 26 Jun 2026 18:11:09 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
satisfied_requirement
unsatisfied_requirement
open
diffy

David du Colombier (Gerrit)

unread,
Jun 26, 2026, 3:24:20 PM (15 hours ago) Jun 26
to goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, Alan Donovan, Peter Weinberger, Richard Miller, golang-co...@googlegroups.com
Attention needed from Alan Donovan, David du Colombier and Richard Miller

David du Colombier removed a vote from this change

Attention is currently required from:
  • Alan Donovan
  • David du Colombier
  • Richard Miller
Submit Requirements:
  • requirement satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: deleteVote
Gerrit-Project: tools
Gerrit-Branch: master
Gerrit-Change-Id: I0bee7e95b0eff91bb224bee9fcd4ab4ad656752c
Gerrit-Change-Number: 794840
Gerrit-PatchSet: 1
Gerrit-Owner: David du Colombier <0in...@gmail.com>
Gerrit-Reviewer: Alan Donovan <adon...@google.com>
Gerrit-Reviewer: Richard Miller <millerr...@gmail.com>
Gerrit-CC: Peter Weinberger <p...@google.com>
Gerrit-Attention: David du Colombier <0in...@gmail.com>
Gerrit-Attention: Richard Miller <millerr...@gmail.com>
Gerrit-Attention: Alan Donovan <adon...@google.com>
satisfied_requirement
unsatisfied_requirement
open
diffy

David du Colombier (Gerrit)

unread,
Jun 26, 2026, 3:26:50 PM (15 hours ago) Jun 26
to goph...@pubsubhelper.golang.org, Alan Donovan, Peter Weinberger, Richard Miller, golang-co...@googlegroups.com
Attention needed from Alan Donovan and Richard Miller

David du Colombier voted Commit-Queue+1

Commit-Queue+1
Open in Gerrit

Related details

Attention is currently required from:
  • Alan Donovan
  • Richard Miller
Submit Requirements:
  • requirement satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: tools
Gerrit-Branch: master
Gerrit-Change-Id: I0bee7e95b0eff91bb224bee9fcd4ab4ad656752c
Gerrit-Change-Number: 794840
Gerrit-PatchSet: 1
Gerrit-Owner: David du Colombier <0in...@gmail.com>
Gerrit-Reviewer: Alan Donovan <adon...@google.com>
Gerrit-Reviewer: David du Colombier <0in...@gmail.com>
Gerrit-Reviewer: Richard Miller <millerr...@gmail.com>
Gerrit-CC: Peter Weinberger <p...@google.com>
Gerrit-Attention: Richard Miller <millerr...@gmail.com>
Gerrit-Attention: Alan Donovan <adon...@google.com>
Gerrit-Comment-Date: Fri, 26 Jun 2026 19:26:43 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
satisfied_requirement
unsatisfied_requirement
open
diffy

David du Colombier (Gerrit)

unread,
Jun 26, 2026, 4:19:37 PM (15 hours ago) Jun 26
to goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, Alan Donovan, Peter Weinberger, Richard Miller, golang-co...@googlegroups.com
Attention needed from Alan Donovan and Richard Miller

David du Colombier voted Auto-Submit+1

Auto-Submit+1
Open in Gerrit

Related details

Attention is currently required from:
  • Alan Donovan
  • Richard Miller
Submit Requirements:
    • requirement satisfiedCode-Review
    • requirement satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: tools
    Gerrit-Branch: master
    Gerrit-Change-Id: I0bee7e95b0eff91bb224bee9fcd4ab4ad656752c
    Gerrit-Change-Number: 794840
    Gerrit-PatchSet: 1
    Gerrit-Owner: David du Colombier <0in...@gmail.com>
    Gerrit-Reviewer: Alan Donovan <adon...@google.com>
    Gerrit-Reviewer: David du Colombier <0in...@gmail.com>
    Gerrit-Reviewer: Richard Miller <millerr...@gmail.com>
    Gerrit-CC: Peter Weinberger <p...@google.com>
    Gerrit-Attention: Richard Miller <millerr...@gmail.com>
    Gerrit-Attention: Alan Donovan <adon...@google.com>
    Gerrit-Comment-Date: Fri, 26 Jun 2026 20:19:30 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: Yes
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy

    Dmitri Shuralyov (Gerrit)

    unread,
    Jun 26, 2026, 7:57:50 PM (11 hours ago) Jun 26
    to David du Colombier, goph...@pubsubhelper.golang.org, Dmitri Shuralyov, golang...@luci-project-accounts.iam.gserviceaccount.com, Alan Donovan, Peter Weinberger, Richard Miller, golang-co...@googlegroups.com

    Dmitri Shuralyov voted Code-Review+1

    Code-Review+1
    Open in Gerrit

    Related details

    Attention set is empty
    Submit Requirements:
      • requirement satisfiedCode-Review
      • requirement satisfiedNo-Unresolved-Comments
      • requirement satisfiedReview-Enforcement
      • requirement satisfiedTryBots-Pass
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: tools
      Gerrit-Branch: master
      Gerrit-Change-Id: I0bee7e95b0eff91bb224bee9fcd4ab4ad656752c
      Gerrit-Change-Number: 794840
      Gerrit-PatchSet: 1
      Gerrit-Owner: David du Colombier <0in...@gmail.com>
      Gerrit-Reviewer: Alan Donovan <adon...@google.com>
      Gerrit-Reviewer: David du Colombier <0in...@gmail.com>
      Gerrit-Reviewer: Dmitri Shuralyov <dmit...@google.com>
      Gerrit-Reviewer: Richard Miller <millerr...@gmail.com>
      Gerrit-CC: Dmitri Shuralyov <dmit...@golang.org>
      Gerrit-Comment-Date: Fri, 26 Jun 2026 23:57:45 +0000
      Gerrit-HasComments: No
      Gerrit-Has-Labels: Yes
      satisfied_requirement
      open
      diffy

      Gopher Robot (Gerrit)

      unread,
      Jun 26, 2026, 7:58:28 PM (11 hours ago) Jun 26
      to David du Colombier, goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, Dmitri Shuralyov, Dmitri Shuralyov, golang...@luci-project-accounts.iam.gserviceaccount.com, Alan Donovan, Peter Weinberger, Richard Miller, golang-co...@googlegroups.com

      Gopher Robot submitted the change

      Change information

      Commit message:
      internal/diff: use ape/patch and ape/diff on Plan 9

      TestToUnified and TestVerifyUnified run the system
      patch and diff commands to check the unified diffs
      produced by the diff package.

      On Plan 9, there is no patch command, and the diff
      command does not support the unified (-u) output
      format, so both tests fail.

      This change uses ape/patch and ape/diff, the POSIX
      patch and diff commands, on Plan 9.

      ape/diff does not emit the "\ No newline at end of
      file" marker, so TestVerifyUnified ignores it when
      comparing on Plan 9.
      Change-Id: I0bee7e95b0eff91bb224bee9fcd4ab4ad656752c
      Reviewed-by: Dmitri Shuralyov <dmit...@google.com>
      Reviewed-by: Alan Donovan <adon...@google.com>
      Auto-Submit: Alan Donovan <adon...@google.com>
      Auto-Submit: David du Colombier <0in...@gmail.com>
      Files:
      • M internal/diff/diff_test.go
      • M internal/diff/difftest/difftest_test.go
      Change size: S
      Delta: 2 files changed, 25 insertions(+), 6 deletions(-)
      Branch: refs/heads/master
      Submit Requirements:
      Open in Gerrit
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: merged
      Gerrit-Project: tools
      Gerrit-Branch: master
      Gerrit-Change-Id: I0bee7e95b0eff91bb224bee9fcd4ab4ad656752c
      Gerrit-Change-Number: 794840
      Gerrit-PatchSet: 2
      Gerrit-Owner: David du Colombier <0in...@gmail.com>
      Gerrit-Reviewer: Alan Donovan <adon...@google.com>
      Gerrit-Reviewer: David du Colombier <0in...@gmail.com>
      Gerrit-Reviewer: Dmitri Shuralyov <dmit...@google.com>
      Gerrit-Reviewer: Gopher Robot <go...@golang.org>
      open
      diffy
      satisfied_requirement
      Reply all
      Reply to author
      Forward
      0 new messages