diff --git a/internal/code-generator/generator/generator_test.go b/internal/code-generator/generator/generator_test.go index f36d053..ec8c809 100644 --- a/internal/code-generator/generator/generator_test.go +++ b/internal/code-generator/generator/generator_test.go @@ -10,7 +10,6 @@ import ( "strings" "testing" - "github.com/go-enry/go-enry/v2/internal/code-generator/generator/diff" "github.com/go-enry/go-enry/v2/internal/tokenizer" "github.com/stretchr/testify/assert" @@ -327,7 +326,7 @@ func (s *GeneratorTestSuite) TestGenerationFiles() { // assert.Equal(s.T(), expected, actual, "Test %s", test.name) if expected != actual { assert.Fail(s.T(), fmt.Sprintf("%s output is different from %q", test.name, test.wantOut)) - diff, err := diff.Diff(gold, out) + diff, err := text_diff(gold, out) if err != nil { s.T().Logf("Failed produce a diff between expected and actual: %s", err.Error()) s.T().Logf("Expected %q", expected[:400]) diff --git a/internal/code-generator/generator/diff/diff.go b/internal/code-generator/generator/generator_test_util.go similarity index 62% rename from internal/code-generator/generator/diff/diff.go rename to internal/code-generator/generator/generator_test_util.go index 4fcbd55..552d90b 100644 --- a/internal/code-generator/generator/diff/diff.go +++ b/internal/code-generator/generator/generator_test_util.go @@ -1,4 +1,9 @@ -package diff +// Copyright 2017 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. +// https://cs.opensource.google/go/x/perf/+/e8d778a6:LICENSE + +package generator import ( "bytes" @@ -7,25 +12,11 @@ import ( "os/exec" ) -func writeTempFile(dir, prefix string, data []byte) (string, error) { - file, err := os.CreateTemp(dir, prefix) - if err != nil { - return "", err - } - - _, err = file.Write(data) - if err1 := file.Close(); err == nil { - err = err1 - } - if err != nil { - os.Remove(file.Name()) - return "", err - } - return file.Name(), nil -} - -// Diff returns a human-readable description of the differences between s1 and s2. -func Diff(b1, b2 []byte) (string, error) { +// text_diff returns a human-readable description of the differences between s1 and s2. +// It essentially is https://cs.opensource.google/go/x/perf/+/e8d778a6:internal/diff/diff.go +// Used only in code generator tests, as a debugging aid. +// It is not part of any release artifact and is not distibuted with enry. +func text_diff(b1, b2 []byte) (string, error) { if bytes.Equal(b1, b2) { return "", nil } @@ -56,3 +47,20 @@ func Diff(b1, b2 []byte) (string, error) { } return string(data), nil } + +func writeTempFile(dir, prefix string, data []byte) (string, error) { + file, err := os.CreateTemp(dir, prefix) + if err != nil { + return "", err + } + + _, err = file.Write(data) + if err1 := file.Close(); err == nil { + err = err1 + } + if err != nil { + os.Remove(file.Name()) + return "", err + } + return file.Name(), nil +}