cmd/eofdump: simplify tests

This commit is contained in:
Martin Holst Swende 2024-09-06 13:53:12 +02:00 committed by Marius van der Wijden
parent 61d8f53934
commit 71ffe6e6dd
2 changed files with 9 additions and 16 deletions

View file

@ -211,6 +211,11 @@ func parseAndValidate(s string, isInitCode bool) (*vm.Container, error) {
if err != nil { if err != nil {
return nil, fmt.Errorf("unable to decode data: %w", err) return nil, fmt.Errorf("unable to decode data: %w", err)
} }
return parse(b, isInitCode)
}
func parse(b []byte, isInitCode bool) (*vm.Container, error) {
var c vm.Container var c vm.Container
if err := c.UnmarshalBinary(b, isInitCode); err != nil { if err := c.UnmarshalBinary(b, isInitCode); err != nil {
return nil, err return nil, err

View file

@ -104,7 +104,10 @@ func testEofParse(t *testing.T, isInitCode bool, wantFile string) {
if err != nil { if err != nil {
panic(err) // rotten corpus panic(err) // rotten corpus
} }
have := parse(b, isInitCode) have := "OK"
if _, err := parse(b, isInitCode); err != nil {
have = fmt.Sprintf("ERR: %v", err)
}
if false { // Change this to generate the want-output if false { // Change this to generate the want-output
fmt.Printf("%v\n", have) fmt.Printf("%v\n", have)
} else { } else {
@ -126,18 +129,3 @@ func testEofParse(t *testing.T, isInitCode bool, wantFile string) {
corpus.Close() corpus.Close()
} }
} }
func parse(data []byte, isInitCode bool) string {
var (
jt = vm.NewPragueEOFInstructionSetForTesting()
c vm.Container
err = c.UnmarshalBinary(data, isInitCode)
)
if err == nil {
if err = c.ValidateCode(&jt, isInitCode); err == nil {
return "OK"
}
return fmt.Sprintf("ERR: %v", err)
}
return fmt.Sprintf("ERR: %v", err)
}