Skip to content
This repository has been archived by the owner on Mar 23, 2021. It is now read-only.

Commit

Permalink
Use github.com/rogpeppe/go-internal@v1.3.0; fix tests for 1.13 (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
myitcv committed Jul 12, 2019
1 parent 082f55c commit ef4e0fa
Show file tree
Hide file tree
Showing 28 changed files with 721 additions and 110 deletions.
10 changes: 8 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ cache:
- $GOPATH/pkg/mod/cache

go:
- "1.11.x"
- "1.12.x"
- "1.11.12"
- "1.12.7"
- "1.13beta1"

os:
- linux
Expand Down Expand Up @@ -60,5 +61,10 @@ script:
# - go run github.com/myitcv/gobin -m -run myitcv.io/cmd/mdreplace -long -online -w README.md
# - gobin -m -run myitcv.io/cmd/mdreplace -w README.md

# Go 1.13 fixed the sorting of vendor/modules.txt. However, this breaks our
# check on prior versions of Go that are in the build matrix. Hence, apply
# known diffs to satisfy the git status check.
- ./_scripts/apply_known_diffs.sh

- if [[ -n $CHECK_GOFMT ]]; then diff <(echo -n) <(gofmt -d .); fi
- test -z "$(git status --porcelain)" || (git status; git diff; false)
29 changes: 29 additions & 0 deletions _scripts/apply_known_diffs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash

# Copyright (c) 2016 Paul Jolly <paul@myitcv.org.uk>, all rights reserved.
# Use of this document is governed by a license found in the LICENSE document.

set -eu
set -o pipefail
set -o errtrace

cd $(git rev-parse --show-toplevel)

if [ ! -d _scripts/known_diffs ]
then
exit 0
fi

goversion=$(go version | cut -d ' ' -f 3)

for i in $(ls _scripts/known_diffs)
do
if [ "$goversion" == $i ]
then
for j in $(find _scripts/known_diffs/$i -type f)
do
git apply $j
done
fi
done

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
diff --git b/vendor/modules.txt a/vendor/modules.txt
index 49894ad..5b8d57c 100644
--- b/vendor/modules.txt
+++ a/vendor/modules.txt
@@ -1,16 +1,16 @@
# github.com/rogpeppe/go-internal v1.3.0
github.com/rogpeppe/go-internal/cmd/txtar-addmod
-github.com/rogpeppe/go-internal/module
-github.com/rogpeppe/go-internal/txtar
-github.com/rogpeppe/go-internal/semver
github.com/rogpeppe/go-internal/goproxytest
github.com/rogpeppe/go-internal/gotooltest
-github.com/rogpeppe/go-internal/testscript
-github.com/rogpeppe/go-internal/par
github.com/rogpeppe/go-internal/imports
github.com/rogpeppe/go-internal/internal/os/execpath
github.com/rogpeppe/go-internal/internal/textutil
+github.com/rogpeppe/go-internal/module
+github.com/rogpeppe/go-internal/par
+github.com/rogpeppe/go-internal/semver
github.com/rogpeppe/go-internal/testenv
+github.com/rogpeppe/go-internal/testscript
+github.com/rogpeppe/go-internal/txtar
# gopkg.in/errgo.v2 v2.1.0
-gopkg.in/errgo.v2/fmt/errors
gopkg.in/errgo.v2/errors
+gopkg.in/errgo.v2/fmt/errors
27 changes: 27 additions & 0 deletions _scripts/known_diffs/go1.12.7/badly_sorted_vendor_modules.txt.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
diff --git b/vendor/modules.txt a/vendor/modules.txt
index 49894ad..5b8d57c 100644
--- b/vendor/modules.txt
+++ a/vendor/modules.txt
@@ -1,16 +1,16 @@
# github.com/rogpeppe/go-internal v1.3.0
github.com/rogpeppe/go-internal/cmd/txtar-addmod
-github.com/rogpeppe/go-internal/module
-github.com/rogpeppe/go-internal/txtar
-github.com/rogpeppe/go-internal/semver
github.com/rogpeppe/go-internal/goproxytest
github.com/rogpeppe/go-internal/gotooltest
-github.com/rogpeppe/go-internal/testscript
-github.com/rogpeppe/go-internal/par
github.com/rogpeppe/go-internal/imports
github.com/rogpeppe/go-internal/internal/os/execpath
github.com/rogpeppe/go-internal/internal/textutil
+github.com/rogpeppe/go-internal/module
+github.com/rogpeppe/go-internal/par
+github.com/rogpeppe/go-internal/semver
github.com/rogpeppe/go-internal/testenv
+github.com/rogpeppe/go-internal/testscript
+github.com/rogpeppe/go-internal/txtar
# gopkg.in/errgo.v2 v2.1.0
-gopkg.in/errgo.v2/fmt/errors
gopkg.in/errgo.v2/errors
+gopkg.in/errgo.v2/fmt/errors
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module github.com/myitcv/gobin

require github.com/rogpeppe/go-internal v1.0.1-alpha.6
require github.com/rogpeppe/go-internal v1.3.0

go 1.11
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/rogpeppe/go-internal v1.0.1-alpha.6 h1:fnE9sfZK1UMsLbzex+ofSe83iGxjJwWNvvMW46cTiDw=
github.com/rogpeppe/go-internal v1.0.1-alpha.6/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.3.0 h1:RR9dF3JtopPvtkroDZuVD7qquD0bnHlKSqaQhgwt8yk=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/errgo.v2 v2.1.0 h1:0vLT13EuvQ0hNvakwLuFZ/jYrLp5F3kcWHXdRggjCE8=
Expand Down
59 changes: 51 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ var (
fDownload = flag.Bool("d", false, "stop after installing main packages to the gobin install cache")
fUpgrade = flag.Bool("u", false, "check for the latest tagged version of main packages")
fNoNet = flag.Bool("nonet", false, "prevent network access")
fDebug = flag.Bool("debug", false, "print debug information")
fDebug = flag.Bool("debug", debug, "print debug information")
fTags = flag.String("tags", "", "build tags to apply; go help build for more information")

// envGOFLAGS is the value of GOENV passed to gobin with -tags= values stripped out
Expand Down Expand Up @@ -69,12 +69,16 @@ func main1() int {
}

func mainerr() error {
goenv, err := getGoEnv()
if err != nil {
return err
}
// Set the default value of the -tags value to be the last -tags= value in
// GOFLAGS. Also, strip any -tags= values from GOFLAGS to ensure a "clean"
// value that can then be used for any cmd/go calls.
if gf := os.Getenv("GOFLAGS"); gf != "" {
if goenv.GOFLAGS != "" {
var goenvVals []string
for _, v := range strings.Fields(gf) {
for _, v := range strings.Fields(goenv.GOFLAGS) {
if strings.HasPrefix(v, "-tags=") {
*fTags = strings.TrimPrefix(v, "-tags=")
continue
Expand Down Expand Up @@ -135,7 +139,7 @@ func mainerr() error {

// cache path discovery
{
gopath = os.Getenv("GOPATH")
gopath = goenv.GOPATH
if gopath != "" {
gopath = filepath.SplitList(gopath)[0]
} else {
Expand All @@ -145,10 +149,15 @@ func mainerr() error {
}
gopath = filepath.Join(uhd, "go")
}

// TODO I don't think the module cache path is advertised anywhere public...
// intentionally but in case it is, replace what follows
localCacheProxy = "GOPROXY=file://" + path.Join(filepath.ToSlash(gopath), "pkg", "mod", "cache", "download")
cachePath := path.Join(filepath.ToSlash(gopath), "pkg", "mod", "cache", "download")
if goenv.ReleaseTags["go1.13"] && cachePath[0] != '/' {
// in Go 1.13 the handling of file:// proxy URLs changed to require a /
cachePath = "/" + cachePath
}

localCacheProxy = "GOPROXY=file://" + cachePath

if *fMainMod {
md := cwd
Expand Down Expand Up @@ -271,7 +280,7 @@ func mainerr() error {

// network resolution step
for _, pkg := range netPkgs {
proxy := os.Getenv("GOPROXY")
proxy := goenv.GOPROXY
if proxy != "" {
proxy = "GOPROXY=" + proxy
}
Expand Down Expand Up @@ -669,7 +678,7 @@ func (cmd *goCmd) run() error {

end := time.Now()

if !debug && !*fDebug {
if !*fDebug {
return nil
}

Expand All @@ -683,3 +692,37 @@ func (cmd *goCmd) run() error {

return nil
}

type goEnv struct {
ReleaseTags map[string]bool
GOFLAGS string
GOPATH string
GOPROXY string
GOBIN string
}

func getGoEnv() (goEnv, error) {
var res goEnv
{
cmd := exec.Command("go", "env", "-json")
out, err := cmd.CombinedOutput()
if err != nil {
return goEnv{}, fmt.Errorf("failed to get go env: %v\n%s", err, out)
}
if err := json.Unmarshal(out, &res); err != nil {
return goEnv{}, fmt.Errorf("failed to unmarshal go env: %v (output was %q)", err, out)
}
}
{
cmd := exec.Command("go", "list", `-f={{join context.ReleaseTags "\n"}}`, "runtime")
out, err := cmd.CombinedOutput()
if err != nil {
return goEnv{}, fmt.Errorf("failed to get release tags: %v\n%s", err, out)
}
res.ReleaseTags = make(map[string]bool)
for _, t := range strings.Fields(string(out)) {
res.ReleaseTags[t] = true
}
}
return res, nil
}
2 changes: 2 additions & 0 deletions script_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func TestExitCode(t *testing.T) {
cmd.Env = os.Environ()
cmd.Env = append(cmd.Env, homeEnv(temp)...)
cmd.Env = append(cmd.Env,
"GONOSUMDB=*",
"GOPROXY="+proxyURL,
"TESTSCRIPT_COMMAND=gobin",
)
Expand Down Expand Up @@ -125,6 +126,7 @@ func TestScripts(t *testing.T) {
e.Vars = append(e.Vars,
"TESTGOPATH="+modTestGOPATH,
"GOBINMODPATH="+pathToMod,
"GONOSUMDB=*",
"GOPROXY="+proxyURL,
"USERCACHEDIR="+ucd,
)
Expand Down
9 changes: 8 additions & 1 deletion testdata/install-main-module-simple-main.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
# Test that gobin -m works for various permutations of GOPATH and GOBIN being set

cd repo

# By "resetting" the go.mod below we are ensuring that the go command has work to do, i.e. the get is not already satisfied.

# No GOPATH
env GOPATH=
cp go.mod.orig go.mod
gobin -m github.com/gobin-testrepos/simple-main@v1.0.0
[!windows] stdout '^\QInstalled github.com/gobin-testrepos/simple-main@v1.0.0 to \E'${HOME@R}\Q/go/bin/simple-main\E'$'
[windows] stdout '^\QInstalled github.com/gobin-testrepos/simple-main@v1.0.0 to \E'${HOME@R}\Q\go\bin\simple-main.exe\E'$'
Expand All @@ -10,6 +15,7 @@ exists $HOME/go/bin/simple-main$exe

# GOPATH set
env GOPATH=$WORK/asdf
cp go.mod.orig go.mod
gobin -m github.com/gobin-testrepos/simple-main@v1.0.0
[!windows] stdout '^\QInstalled github.com/gobin-testrepos/simple-main@v1.0.0 to \E'${WORK@R}\Q/asdf/bin/simple-main\E'$'
[windows] stdout '^\QInstalled github.com/gobin-testrepos/simple-main@v1.0.0 to \E'${WORK@R}\Q\asdf\bin\simple-main.exe\E'$'
Expand All @@ -19,11 +25,12 @@ exists $WORK/asdf/bin/simple-main$exe
# GOBIN set
mkdir bin
env GOBIN=$WORK/repo/bin
cp go.mod.orig go.mod
gobin -m github.com/gobin-testrepos/simple-main@v1.0.0
[!windows] stdout '^\QInstalled github.com/gobin-testrepos/simple-main@v1.0.0 to \E'${WORK@R}\Q/repo/bin/simple-main\E'$'
[windows] stdout '^\QInstalled github.com/gobin-testrepos/simple-main@v1.0.0 to \E'${WORK@R}\Q\repo\bin\simple-main.exe\E'$'
! stderr .+
exists $WORK/repo/bin/simple-main$exe

-- repo/go.mod --
-- repo/go.mod.orig --
module example.com/repo
6 changes: 3 additions & 3 deletions testdata/latest-global.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ gobin github.com/gobin-testrepos/simple-main@v1.0.0
! stderr .+

# Verify we get that same version back via latest...
# and that we _don't_ hit the network at all.
# without having to hit the network
env PREVGOPROXY=$GOPROXY
env GOPROXY=asdf
gobin github.com/gobin-testrepos/simple-main@latest
env GOPROXY=
gobin -nonet github.com/gobin-testrepos/simple-main@latest
[!windows] stdout '^\QInstalled github.com/gobin-testrepos/simple-main@v1.0.0 to \E'${WORK@R}\Q/gopath/bin/simple-main\E'$'
[windows] stdout '^\QInstalled github.com/gobin-testrepos/simple-main@v1.0.0 to \E'${WORK@R}\Q\gopath\bin\simple-main.exe\E'$'
! stderr .+
Expand Down
2 changes: 1 addition & 1 deletion testdata/mod_readonly.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ cd repo
! gobin -mod=readonly github.com/gobin-testrepos/simple-main
! stdout .+
[go1.11] [!go1.12] stderr 'import lookup disabled by -mod=readonly'
[go1.12] stderr 'go: updates to go.mod needed, disabled by -mod=readonly'
[go1.12] stderr 'can''t load package: package github.com/gobin-testrepos/simple-main: unknown import path "github.com/gobin-testrepos/simple-main": import lookup disabled by -mod=readonly'

-- repo/go.mod --
module example.com/repo
10 changes: 7 additions & 3 deletions testdata/run_alt_goos_goarch.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
env GOOS=rubbish
env GOARCH=myarch
# Test that the value of GOOS and GOARCH does not affect -run

# Set values that we will never test with
env GOOS=solaris
env GOARCH=amd64

gobin -m -run mod.com/p
stdout '^GOOS is rubbish, GOARCH is myarch$'
stdout '^GOOS is solaris, GOARCH is amd64$'

-- go.mod --
module mod.com
Expand Down
Loading

0 comments on commit ef4e0fa

Please sign in to comment.