-
Notifications
You must be signed in to change notification settings - Fork 277
preliminary Go modules support #274
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4ab89a8
preliminary Go modules support (#2)
thepudds f6aba75
Merge branch 'master' into dev-modules-2
thepudds e55f0a1
modules support: adjust wording based on first-pass review, and updat…
thepudds de80537
readme: update wording based on review
thepudds 649ad58
readme: remove a blank line to re-trigger travis
thepudds File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Start by seeing if anything works at all. | ||
# This is intended to excercise travis and the testscript cmd invoking go-fuzz. | ||
# If this fails, likely everything else will fail too, but if so might be easier to | ||
# start by troubleshooting this. | ||
|
||
# Ask go-fuzz-build to emit its help message, which should be a failing status code. | ||
! exec go-fuzz-build -h | ||
thepudds marked this conversation as resolved.
Show resolved
Hide resolved
|
||
stderr 'Usage of.*go-fuzz-build' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# These steps validate that go-fuzz/go-fuzz-dep and go-fuzz/go-fuzz-defs are found, | ||
# along with validating how they are currently found, and where they end up being located. | ||
|
||
# Enter a simple module with a fuzz function. | ||
# Note that we are outside of GOPATH, so the presence of the 'go.mod' here will | ||
# enable module-module for cmd/go (which is true in Go 1.11-1.13, and likely will be true in 1.14 as well). | ||
cd testmod | ||
|
||
# Sanity check the module seems well formed. | ||
exec go list -m all | ||
stdout '^example.com/testmod$' | ||
exec go build | ||
|
||
# Sanity check go-fuzz is not in our go.mod, nor reported by 'go list -m all'. | ||
! grep 'github.com/dvyukov/go-fuzz' go.mod | ||
exec go list -m all | ||
! stdout 'github.com/dvyukov/go-fuzz' | ||
|
||
# Ask go-fuzz-build to build, including specifying the fuzz function for mod. | ||
exec go-fuzz-build -func=FuzzMod | ||
exists testmod-fuzz.zip | ||
|
||
# Sanity check github.com/dvyukov/go-fuzz was added by go-fuzz-build | ||
# to our go.mod and is now visible via 'go list -m all'. | ||
# This is not necessarily a requirement for all time, | ||
# but this is the way the current modules approach for go-fuzz works. | ||
# This is important to make sure the go-fuzz-dep source code is | ||
# findable by go-fuzz-build (when it invokes 'go list'). | ||
grep -count=1 '^require github.com/dvyukov/go-fuzz v[^ ]+ // indirect$' go.mod | ||
exec go list -m all | ||
stdout '^example.com/testmod$' | ||
stdout '^github.com/dvyukov/go-fuzz v[^ ]+$' | ||
|
||
# Also output directories for go-fuzz-defs and go-fuzz-dep | ||
# in case we need to debug this at some point in the future, | ||
# or in case cmd/go or go-fuzz change in the future | ||
# in some way that moves these out of $GOPATH/pkg/testmod or | ||
# otherwise alters where these are located. | ||
# The exact location might not be critical, but we should be aware of what it is, | ||
# so capture the location here in this test so we know if it changes later. | ||
exec go list -f {{.Dir}} github.com/dvyukov/go-fuzz/go-fuzz-defs | ||
stdout 'gopath.pkg.mod.github.com.dvyukov.go-fuzz@v[^ ]+.go-fuzz-defs$' | ||
exec go list -f {{.Dir}} github.com/dvyukov/go-fuzz/go-fuzz-dep | ||
stdout 'gopath.pkg.mod.github.com.dvyukov.go-fuzz@v[^ ]+.go-fuzz-dep$' | ||
|
||
# Define a simple module 'mod' that has a fuzz function. | ||
|
||
-- testmod/go.mod -- | ||
module example.com/testmod | ||
|
||
-- testmod/fuzz.go -- | ||
package testmod | ||
|
||
func FuzzMod(data []byte) int { | ||
return 0 | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
# These steps validate we can fuzz inside of GOPATH | ||
# with GO111MODULE on and off. | ||
|
||
# Here, we purposefully do not test with GO111MODULE auto and unset, | ||
# because the meaning of auto within GOPATH has changed with | ||
# Go 1.13, and the meaning of unset will likely change in Go 1.14 | ||
# (and some chance auto could change meaning again in Go 1.14). | ||
# However, the Go 1.13 and 1.14 changes ultimately translate | ||
# to what external conditions enable or disable module mode | ||
# for cmd/go. Testing here with GO111MODULE on and off allows | ||
# us to explicitly test with cmd/go's module mode enabled and disabled in GOPATH, | ||
# which is our current goal here. (These are not cmd/go tests after all). | ||
|
||
# The foo module being fuzzed depends on a 'replace' | ||
# in its go.mod to find one of its dependencies, and that dependency bar | ||
# is located *outside* of GOPATH, which is a way to check that | ||
# module-mode is required to compile successfully. | ||
# (Other go-fuzz tests validate that non-module targets work in GOPATH with | ||
# cmd/go's module mode disabled; that has been the status quo). | ||
|
||
# Enter a simple module with a fuzz function. | ||
# This is inside GOPATH. | ||
cd gopath/src/example.com/foo | ||
|
||
# Copy a pristine go.mod file. | ||
cp go.mod_PRISTINE go.mod | ||
|
||
# First, we test with GO111MODULE=on, which will likely be the default in Go 1.14. | ||
env GO111MODULE=on | ||
|
||
# Sanity check the module seems well formed. | ||
exec go list -m all | ||
stdout '^example.com/foo$' | ||
exec go build | ||
|
||
# Ask go-fuzz-build to build, including specifying the fuzz function for mod. | ||
exec go-fuzz-build -func=FuzzMod | ||
exists foo-fuzz.zip | ||
|
||
# Validate we can start fuzzing. | ||
# Note that 'timeout(1)' will error here, so we preface the invocation with '!'. | ||
# For travis on Windows, we install 'timeout(1)' as part of our travis setup steps. | ||
# To test this locally on Windows, you might need to change 'timeout' to '\cygwin64\bin\timeout' or similar. | ||
! exec timeout 5 go-fuzz -procs=1 -func=FuzzMod | ||
stderr 'workers: \d+, corpus: ' | ||
|
||
# Clean up. | ||
cp go.mod_PRISTINE go.mod | ||
rm foo-fuzz.zip | ||
|
||
# Second, we test with GO111MODULE=off. | ||
# The meaning of this is unlikely to change in Go 1.14, | ||
# altough in some (distant?) future, GO111MODULE=off might | ||
# no longer be supported. | ||
env GO111MODULE=off | ||
|
||
# Confirm 'go list -m' and 'go build' fail. | ||
! exec go list -m all | ||
! exec go build | ||
|
||
# Confirm go-fuzz-build fails. | ||
! exec go-fuzz-build -func=FuzzMod | ||
! exists foo-fuzz.zip | ||
|
||
# Clean up (mainly in case we later add another test below). | ||
cp go.mod_PRISTINE go.mod | ||
rm foo-fuzz.zip | ||
|
||
# Define two modules. | ||
# example.com/foo has a fuzz function, and depends on example.com/bar. | ||
# foo is inside GOPATH, and bar is outside of GOPATH. | ||
|
||
-- gopath/src/example.com/foo/go.mod_PRISTINE -- | ||
module example.com/foo | ||
|
||
require example.com/bar v0.0.0 | ||
|
||
replace example.com/bar => ../../../../bar | ||
|
||
-- gopath/src/example.com/foo/fuzz.go -- | ||
package foo | ||
|
||
import "example.com/bar" | ||
|
||
func FuzzMod(data []byte) int { | ||
bar.Bar() | ||
return 0 | ||
} | ||
|
||
-- bar/go.mod -- | ||
module example.com/bar | ||
|
||
-- bar/bar.go -- | ||
package bar | ||
|
||
func Bar() string { | ||
return "hello from bar" | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.