From 2464ebc238c79c952e959203457ef2a23f241991 Mon Sep 17 00:00:00 2001 From: Mattias Wadman Date: Wed, 20 Jul 2022 18:13:31 +0200 Subject: [PATCH] fuzz: Replace built tag with FUZZTEST env and use new interp api Build tag hides build errors --- Makefile | 2 +- format/fuzz_test.go | 27 ++++++++++++++++----------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index 3a3102c9..d9b03255 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/format/fuzz_test.go b/format/fuzz_test.go index 30d8278c..837c0b45 100644 --- a/format/fuzz_test.go +++ b/format/fuzz_test.go @@ -1,5 +1,3 @@ -//go:build fuzz - package format_test import ( @@ -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{} @@ -69,14 +66,18 @@ 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 } @@ -84,8 +85,8 @@ func FuzzFormats(f *testing.F) { return nil } - b, err := ioutil.ReadFile(path) - if err != nil { + b, readErr := ioutil.ReadFile(path) + if readErr != nil { f.Fatal(err) } @@ -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) }