From 333e489763cf741035cae7d0b425f22622fea3de Mon Sep 17 00:00:00 2001 From: Ayush Ranjan Date: Mon, 8 Mar 2021 15:49:27 -0800 Subject: [lisa] Do not generate any tests for dynamic types. The dynamic type user defines the marshalling logic, so we don't need to test for things like alignment, absence of slices, etc. For dynamic types, the go_marshal generator just generates the missing methods required to implement marshal.Marshallable. PiperOrigin-RevId: 361676311 --- tools/go_marshal/gomarshal/generator.go | 8 ++++++-- tools/go_marshal/gomarshal/generator_tests.go | 12 ++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) (limited to 'tools/go_marshal/gomarshal') diff --git a/tools/go_marshal/gomarshal/generator.go b/tools/go_marshal/gomarshal/generator.go index abd6f69ea..634abd1af 100644 --- a/tools/go_marshal/gomarshal/generator.go +++ b/tools/go_marshal/gomarshal/generator.go @@ -427,7 +427,7 @@ func (g *Generator) generateOne(t *marshallableType, fset *token.FileSet) *inter // implementations type t. func (g *Generator) generateOneTestSuite(t *marshallableType) *testGenerator { i := newTestGenerator(t.spec, t.recv) - i.emitTests(t.slice, t.dynamic) + i.emitTests(t.slice) return i } @@ -488,7 +488,11 @@ func (g *Generator) Run() error { panic(fmt.Sprintf("Generated code for '%s' referenced a non-existent import with local name '%s'. Either go-marshal needs to add an import to the generated file, or a package in an input source file has a package name differ from the final component of its path, which go-marshal doesn't know how to detect; use an import alias to work around this limitation.", impl.typeName(), name)) } } - ts = append(ts, g.generateOneTestSuite(t)) + // Do not generate tests for dynamic types because they inherently + // violate some go_marshal requirements. + if !t.dynamic { + ts = append(ts, g.generateOneTestSuite(t)) + } } } diff --git a/tools/go_marshal/gomarshal/generator_tests.go b/tools/go_marshal/gomarshal/generator_tests.go index ca3e15c16..6cf00843f 100644 --- a/tools/go_marshal/gomarshal/generator_tests.go +++ b/tools/go_marshal/gomarshal/generator_tests.go @@ -216,16 +216,12 @@ func (g *testGenerator) emitTestSizeBytesOnTypedNilPtr() { }) } -func (g *testGenerator) emitTests(slice *sliceAPI, isDynamic bool) { +func (g *testGenerator) emitTests(slice *sliceAPI) { g.emitTestNonZeroSize() g.emitTestSuspectAlignment() - if !isDynamic { - // Do not test these for dynamic structs because they violate some - // assumptions that these tests make. - g.emitTestMarshalUnmarshalPreservesData() - g.emitTestWriteToUnmarshalPreservesData() - g.emitTestSizeBytesOnTypedNilPtr() - } + g.emitTestMarshalUnmarshalPreservesData() + g.emitTestWriteToUnmarshalPreservesData() + g.emitTestSizeBytesOnTypedNilPtr() if slice != nil { g.emitTestMarshalUnmarshalSlicePreservesData(slice) -- cgit v1.2.3