Skip to content

Commit 4492473

Browse files
authored
Merge pull request #121 from mattfarina/fuzzing
Adding fuzzing for v3
2 parents 3c3e3c7 + b01f0c4 commit 4492473

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
_fuzz/

Makefile

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
GOPATH=$(shell go env GOPATH)
22
GOLANGCI_LINT=$(GOPATH)/bin/golangci-lint
3+
GOFUZZBUILD = $(GOPATH)/bin/go-fuzz-build
4+
GOFUZZ = $(GOPATH)/bin/go-fuzz
35

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

21+
.PHONY: fuzz
22+
fuzz: $(GOFUZZBUILD) $(GOFUZZ)
23+
@echo "==> Fuzz testing"
24+
$(GOFUZZBUILD)
25+
$(GOFUZZ) -workdir=_fuzz
26+
1927
$(GOLANGCI_LINT):
2028
# Install golangci-lint. The configuration for it is in the .golangci.yml
2129
# file in the root of the repository
2230
echo ${GOPATH}
23-
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(GOPATH)/bin v1.17.1
31+
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(GOPATH)/bin v1.17.1
32+
33+
$(GOFUZZBUILD):
34+
cd / && go get -u github.com/dvyukov/go-fuzz/go-fuzz-build
35+
36+
$(GOFUZZ):
37+
cd / && go get -u github.com/dvyukov/go-fuzz/go-fuzz github.com/dvyukov/go-fuzz/go-fuzz-dep

fuzz.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// +build gofuzz
2+
3+
package semver
4+
5+
func Fuzz(data []byte) int {
6+
d := string(data)
7+
8+
// Test NewVersion
9+
_, _ = NewVersion(d)
10+
11+
// Test StrictNewVersion
12+
_, _ = StrictNewVersion(d)
13+
14+
// Test NewConstraint
15+
_, _ = NewConstraint(d)
16+
17+
// The return value should be 0 normally, 1 if the priority in future tests
18+
// should be increased, and -1 if future tests should skip passing in that
19+
// data. We do not have a reason to change priority so 0 is always returned.
20+
// There are example tests that do this.
21+
return 0
22+
}

0 commit comments

Comments
 (0)