mirror of
https://github.com/ralsina/tartrazine.git
synced 2025-05-23 08:30:07 -03:00
gen: compare generated code to gold ignoring whitespaces
Reason is that gofmt can change between versions e.g see https://go-review.googlesource.com/c/go/+/122295/ and this would avoid breaking tests and edit wars Signed-off-by: Alexander Bezzubov <bzz@apache.org>
This commit is contained in:
parent
c8e0f75132
commit
baefa18475
@ -6,6 +6,7 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@ -282,6 +283,17 @@ func (s *GeneratorTestSuite) TestGenerationFiles() {
|
||||
assert.NoError(s.T(), err)
|
||||
out, err := ioutil.ReadFile(outPath.Name())
|
||||
assert.NoError(s.T(), err)
|
||||
assert.Equal(s.T(), string(gold), string(out))
|
||||
|
||||
expected := normalizeSpaces(string(gold))
|
||||
actual := normalizeSpaces(string(out))
|
||||
assert.Equal(s.T(), expected, actual, "Test %s", test.name)
|
||||
}
|
||||
}
|
||||
|
||||
// normalizeSpaces returns a copy of str with whitespaces normalizeds.
|
||||
// We use this to compare generated source as gofmt format may change.
|
||||
// E.g for changines beteween Go 1.10 and 1.11 see
|
||||
// https://go-review.googlesource.com/c/go/+/122295/
|
||||
func normalizeSpaces(str string) string {
|
||||
return strings.Join(strings.Fields(str), " ")
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user