Skip to content

Commit

Permalink
internal/testenv: check that external 'diff' tool is the GNU version
Browse files Browse the repository at this point in the history
TestVerifyUnified in internal/lsp/diff/difftest requires specific
behaviour of the 'diff' command which is known to be satisfied by
GNU diff. The plan9 'diff' command has no '-u' option, and the
illumos 'diff -u' produces output in a different format. Checking
specifically for the GNU version in the HasTool function ensures
the expected behaviour, and otherwise causes the test to be skipped.

Updates golang/go#38772

Change-Id: I5493fa8cfc48a112dc0b7356618c62d3ccb0366f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/232479
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
  • Loading branch information
Richard Miller authored and stamblerre committed May 8, 2020
1 parent b846998 commit 19e4049
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
4 changes: 0 additions & 4 deletions internal/lsp/diff/difftest/difftest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// As of writing illumos uses a version of diff for which `diff -u` reports
// locations differently from GNU diff.
// +build !illumos

// Package difftest supplies a set of tests that will operate on any
// implementation of a diff algorithm as exposed by
// "golang.org/x/tools/internal/lsp/diff"
Expand Down
12 changes: 12 additions & 0 deletions internal/testenv/testenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package testenv

import (
"bytes"
"fmt"
"io/ioutil"
"os"
Expand Down Expand Up @@ -77,6 +78,17 @@ func hasTool(tool string) error {
if checkGoGoroot.err != nil {
return checkGoGoroot.err
}

case "diff":
// Check that diff is the GNU version, needed for the -u argument and
// to report missing newlines at the end of files.
out, err := exec.Command(tool, "-version").Output()
if err != nil {
return err
}
if !bytes.Contains(out, []byte("GNU diffutils")) {
return fmt.Errorf("diff is not the GNU version")
}
}

return nil
Expand Down

0 comments on commit 19e4049

Please sign in to comment.