From 19e4049dcde33004d7d56018a1acd06e0aa31170 Mon Sep 17 00:00:00 2001 From: Richard Miller Date: Wed, 6 May 2020 14:59:27 +0100 Subject: [PATCH] internal/testenv: check that external 'diff' tool is the GNU version 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 Run-TryBot: Rebecca Stambler TryBot-Result: Gobot Gobot --- internal/lsp/diff/difftest/difftest_test.go | 4 ---- internal/testenv/testenv.go | 12 ++++++++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/internal/lsp/diff/difftest/difftest_test.go b/internal/lsp/diff/difftest/difftest_test.go index 21d9cd13b40..f87354366b2 100644 --- a/internal/lsp/diff/difftest/difftest_test.go +++ b/internal/lsp/diff/difftest/difftest_test.go @@ -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" diff --git a/internal/testenv/testenv.go b/internal/testenv/testenv.go index 71f4d6806e0..6c5fb98c452 100644 --- a/internal/testenv/testenv.go +++ b/internal/testenv/testenv.go @@ -7,6 +7,7 @@ package testenv import ( + "bytes" "fmt" "io/ioutil" "os" @@ -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