Skip to content

Commit

Permalink
Merge pull request #121 from mattfarina/fuzzing
Browse files Browse the repository at this point in the history
Adding fuzzing for v3
  • Loading branch information
mattfarina committed Sep 12, 2019
2 parents 3c3e3c7 + b01f0c4 commit 4492473
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
_fuzz/
16 changes: 15 additions & 1 deletion Makefile
@@ -1,5 +1,7 @@
GOPATH=$(shell go env GOPATH)
GOLANGCI_LINT=$(GOPATH)/bin/golangci-lint
GOFUZZBUILD = $(GOPATH)/bin/go-fuzz-build
GOFUZZ = $(GOPATH)/bin/go-fuzz

.PHONY: lint
lint: $(GOLANGCI_LINT)
Expand All @@ -16,8 +18,20 @@ test-cover:
@echo "==> Running Tests with coverage"
GO111MODULE=on go test -cover .

.PHONY: fuzz
fuzz: $(GOFUZZBUILD) $(GOFUZZ)
@echo "==> Fuzz testing"
$(GOFUZZBUILD)
$(GOFUZZ) -workdir=_fuzz

$(GOLANGCI_LINT):
# Install golangci-lint. The configuration for it is in the .golangci.yml
# file in the root of the repository
echo ${GOPATH}
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(GOPATH)/bin v1.17.1
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(GOPATH)/bin v1.17.1

$(GOFUZZBUILD):
cd / && go get -u github.com/dvyukov/go-fuzz/go-fuzz-build

$(GOFUZZ):
cd / && go get -u github.com/dvyukov/go-fuzz/go-fuzz github.com/dvyukov/go-fuzz/go-fuzz-dep
22 changes: 22 additions & 0 deletions 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
}

0 comments on commit 4492473

Please sign in to comment.