gen-test: don't expose diff + attributions

This commit is contained in:
Alex Bezzubov 2022-12-12 20:48:35 +01:00
parent c79c32f525
commit c0176b04e7
2 changed files with 29 additions and 22 deletions

View File

@ -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])

View File

@ -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
}