From fcff12338277a5a1e4a7264d647bbedf6d1d065f Mon Sep 17 00:00:00 2001 From: Matt Farina Date: Wed, 11 Sep 2019 13:17:38 -0400 Subject: [PATCH] Adding fuzzing for v3 --- .gitignore | 1 + Makefile | 6 ++++++ fuzz.go | 22 ++++++++++++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 .gitignore create mode 100644 fuzz.go diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6b061e6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +_fuzz/ \ No newline at end of file diff --git a/Makefile b/Makefile index d92bd5c..1d59cb9 100644 --- a/Makefile +++ b/Makefile @@ -16,6 +16,12 @@ test-cover: @echo "==> Running Tests with coverage" GO111MODULE=on go test -cover . +.PHONY: fuzz +fuzz: + @echo "==> Fuzz testing" + go-fuzz-build + go-fuzz -workdir=_fuzz + $(GOLANGCI_LINT): # Install golangci-lint. The configuration for it is in the .golangci.yml # file in the root of the repository diff --git a/fuzz.go b/fuzz.go new file mode 100644 index 0000000..a242ad7 --- /dev/null +++ b/fuzz.go @@ -0,0 +1,22 @@ +// +build gofuzz + +package semver + +func Fuzz(data []byte) int { + d := string(data) + + // Test NewVersion + _, _ = NewVersion(d) + + // Test StrictNewVersion + _, _ = StrictNewVersion(d) + + // Test NewConstraint + _, _ = NewConstraint(d) + + // The return value should be 0 normally, 1 if the priority in future tests + // should be increased, and -1 if future tests should skip passing in that + // data. We do not have a reason to change priority so 0 is always returned. + // There are example tests that do this. + return 0 +}