-
-
Notifications
You must be signed in to change notification settings - Fork 529
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #289 from BurntSushi/gofuzz
Add support for "go test -fuzz"
- Loading branch information
Showing
4 changed files
with
74 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package toml | ||
|
||
import "encoding" | ||
|
||
// DEPRECATED! | ||
// | ||
// Use the identical encoding.TextMarshaler instead. It is defined here to | ||
// support Go 1.1 and older. | ||
type TextMarshaler encoding.TextMarshaler | ||
|
||
// DEPRECATED! | ||
// | ||
// Use the identical encoding.TextUnmarshaler instead. It is defined here to | ||
// support Go 1.1 and older. | ||
type TextUnmarshaler encoding.TextUnmarshaler | ||
|
||
// DEPRECATED! | ||
// | ||
// Use MetaData.PrimitiveDecode instead. | ||
func PrimitiveDecode(primValue Primitive, v interface{}) error { | ||
md := MetaData{decoded: make(map[string]bool)} | ||
return md.unify(primValue.undecoded, rvalue(v)) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// +build gofuzzbeta | ||
// +build go1.17 | ||
|
||
package toml | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
) | ||
|
||
func FuzzDecode(f *testing.F) { | ||
buf := make([]byte, 0, 2048) | ||
|
||
f.Add(` | ||
# This is a TOML document | ||
title = "TOML Example" | ||
[owner] | ||
name = "Tom Preston-Werner" | ||
dob = 1979-05-27T07:32:00-08:00 | ||
[database] | ||
enabled = true | ||
ports = [ 8000, 8001, 8002 ] | ||
data = [ ["delta", "phi"], [3.14] ] | ||
temp_targets = { cpu = 79.5, case = 72.0 } | ||
[servers] | ||
[servers.alpha] | ||
ip = "10.0.0.1" | ||
role = "frontend" | ||
[servers.beta] | ||
ip = "10.0.0.2" | ||
role = "backend" | ||
`) | ||
f.Fuzz(func(t *testing.T, file string) { | ||
var m map[string]interface{} | ||
_, err := Decode(file, &m) | ||
if err != nil { | ||
t.Skip() | ||
} | ||
|
||
NewEncoder(bytes.NewBuffer(buf)).Encode(m) | ||
|
||
// TODO: should check if the output is equal to the input, too, but some | ||
// information is lost when encoding. | ||
}) | ||
} |