generate test to ensure code generation worked

This commit is contained in:
Michael McLoughlin
2018-11-24 17:53:17 -08:00
parent 0edbdb064f
commit 6d3e3be578
6 changed files with 98 additions and 41 deletions

View File

@@ -3,6 +3,9 @@ package gen
import "testing"
func TestBuilderInterfaces(t *testing.T) {
var _ Builder = NewAsmTest
var _ Builder = NewGoData
var _ = []Builder{
NewAsmTest,
NewGoData,
NewGoDataTest,
}
}

View File

@@ -61,3 +61,37 @@ func (g godata) Generate(is []inst.Instruction) ([]byte, error) {
return p.Result()
}
type godatatest struct {
cfg Config
}
func NewGoDataTest(cfg Config) Interface {
return GoFmt(godatatest{cfg: cfg})
}
func (g godatatest) Generate(is []inst.Instruction) ([]byte, error) {
p := &printer{}
p.Printf("// %s\n\n", g.cfg.GeneratedWarning())
p.Printf("package inst_test\n\n")
p.Printf(`import (
"reflect"
"testing"
"github.com/mmcloughlin/avo/internal/inst"
)
`)
p.Printf("var raw = %#v\n\n", is)
p.Printf(`func TestVerifyInstructionsList(t *testing.T) {
if !reflect.DeepEqual(raw, inst.Instructions) {
t.Fatal("bad code generation for instructions list")
}
}
`)
return p.Result()
}