Skip to content

Commit

Permalink
Adding fuzzing for v3
Browse files Browse the repository at this point in the history
  • Loading branch information
mattfarina committed Sep 11, 2019
1 parent 0873dd6 commit fcff123
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
_fuzz/
6 changes: 6 additions & 0 deletions Makefile
Expand Up @@ -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
Expand Down
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 fcff123

Please sign in to comment.