if len(vals) == 0 {
panic("must have at least one value to marshal")
}
- b := bytes.NewBuffer([]byte(encVersion1))
+ b := bytes.NewBuffer([]byte(encVersion1 + "\n"))
// TODO(katiehockman): keep uint8 and int32 encoding where applicable,
// instead of changing to byte and rune respectively.
for _, val := range vals {
switch t := val.(type) {
case int, int8, int16, int64, uint, uint16, uint32, uint64, float32, float64, bool:
- fmt.Fprintf(b, "\n%T(%v)", t, t)
+ fmt.Fprintf(b, "%T(%v)\n", t, t)
case string:
- fmt.Fprintf(b, "\nstring(%q)", t)
+ fmt.Fprintf(b, "string(%q)\n", t)
case rune: // int32
- fmt.Fprintf(b, "\nrune(%q)", t)
+ fmt.Fprintf(b, "rune(%q)\n", t)
case byte: // uint8
- fmt.Fprintf(b, "\nbyte(%q)", t)
+ fmt.Fprintf(b, "byte(%q)\n", t)
case []byte: // []uint8
- fmt.Fprintf(b, "\n[]byte(%q)", t)
+ fmt.Fprintf(b, "[]byte(%q)\n", t)
default:
panic(fmt.Sprintf("unsupported type: %T", t))
}
},
{
in: `go test fuzz v1
+string("has final newline")
+`,
+ ok: true, // has final newline
+ },
+ {
+ in: `go test fuzz v1
string("extra")
[]byte("spacing")
`,
- ok: true,
+ ok: true, // extra spaces in the final newline
},
{
in: `go test fuzz v1
float64(0)
-float32(0)
-`,
+float32(0)`,
ok: true, // will be an integer literal since there is no decimal
},
{
if err != nil {
t.Fatalf("marshal unexpected error: %v", err)
}
- want := strings.TrimSpace(test.in)
- if want != string(newB) {
- t.Errorf("values changed after unmarshal then marshal\nbefore: %q\nafter: %q", want, newB)
+ if newB[len(newB)-1] != '\n' {
+ t.Error("didn't write final newline to corpus file")
+ }
+ before, after := strings.TrimSpace(test.in), strings.TrimSpace(string(newB))
+ if before != after {
+ t.Errorf("values changed after unmarshal then marshal\nbefore: %q\nafter: %q", before, after)
}
})
}