Skip to content

Commit

Permalink
fuzz: Replace built tag with FUZZTEST env and use new interp api
Browse files Browse the repository at this point in the history
Build tag hides build errors
  • Loading branch information
wader committed Jul 20, 2022
1 parent 6011d0b commit 2464ebc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ update-gomod:
.PHONY: fuzz
fuzz:
# in other terminal: tail -f /tmp/repanic
REPANIC_LOG=/tmp/repanic gotip test -tags fuzz -v -run Fuzz -fuzz=Fuzz ./format/
FUZZTEST=1 REPANIC_LOG=/tmp/repanic gotip test -v -run Fuzz -fuzz=Fuzz ./format/

# usage: make release VERSION=0.0.1
# tag forked dependeces for history and to make then stay around
Expand Down
27 changes: 16 additions & 11 deletions format/fuzz_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//go:build fuzz

package format_test

import (
Expand All @@ -16,7 +14,6 @@ import (
_ "github.com/wader/fq/format/all"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/registry"
)

type fuzzFS struct{}
Expand Down Expand Up @@ -69,23 +66,27 @@ func (ft *fuzzTest) Readline(opts interp.ReadlineOpts) (string, error) {
}

func FuzzFormats(f *testing.F) {
if os.Getenv("FUZZTEST") == "" {
f.Skip("run with FUZZTEST=1 do fuzz")
}

i := 0

filepath.Walk(".", func(path string, info os.FileInfo, err error) error {
if err := filepath.Walk(".", func(path string, info os.FileInfo, err error) error {
if filepath.Base(path) != "testdata" {
return nil
}

filepath.Walk(path, func(path string, info os.FileInfo, err error) error {
if err := filepath.Walk(path, func(path string, info os.FileInfo, err error) error {
if filepath.Ext(path) == ".fqtest" {
return nil
}
if st, err := os.Stat(path); err != nil || st.IsDir() {
return nil
}

b, err := ioutil.ReadFile(path)
if err != nil {
b, readErr := ioutil.ReadFile(path)
if readErr != nil {
f.Fatal(err)
}

Expand All @@ -94,16 +95,20 @@ func FuzzFormats(f *testing.F) {
i++

return nil
})
}); err != nil {
f.Fatal(f)
}
return nil
})
}); err != nil {
f.Fatal(f)
}

gi := 0
g := interp.DefaultRegister.MustAll()
g := interp.DefaultRegistry.MustAll()

f.Fuzz(func(t *testing.T, b []byte) {
fz := &fuzzTest{b: b, f: g[gi]}
q, err := interp.New(fz, interp.DefaultRegister)
q, err := interp.New(fz, interp.DefaultRegistry)
if err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit 2464ebc

Please sign in to comment.