Skip to content

Commit

Permalink
testdata: don't let tests rely on rewriting mod files
Browse files Browse the repository at this point in the history
In Go 1.15, if a dependency is required but not listed in go.mod/go.sum,
it's resolved and added automatically.

This is changing in 1.16. From that release, one will have to explicitly
update the mod files via 'go mod tidy' or 'go get'.

To get ahead of the curve, start using -mod=readonly to get the same
behavior in 1.15, and fix all existing tests.

The only tests that failed were imports.txt and syntax.txt, the only
ones to require other modules. But since we're here, let's add the 'go'
line to all go.mod files as well.
  • Loading branch information
mvdan committed Nov 8, 2020
1 parent 4e79bfc commit 39372a8
Show file tree
Hide file tree
Showing 17 changed files with 50 additions and 0 deletions.
1 change: 1 addition & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func TestScripts(t *testing.T) {
env.Vars = append(env.Vars,
"GOPROXY="+proxyURL,
"GONOSUMDB=*",
"GOFLAGS=-mod=readonly", // TODO(mvdan): remove once we switch to Go 1.16
"gofullversion="+runtime.Version(),
)
bindir := filepath.Join(env.WorkDir, ".bin")
Expand Down
2 changes: 2 additions & 0 deletions testdata/scripts/asm.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ cmp stderr main.stderr

-- go.mod --
module test/main

go 1.15
-- main.go --
package main

Expand Down
2 changes: 2 additions & 0 deletions testdata/scripts/basic.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ binsubstr main$exe 'main.go' 'globalVar' 'globalFunc' $gofullversion

-- go.mod --
module test/mainfoo

go 1.15
-- main.go --
package main

Expand Down
2 changes: 2 additions & 0 deletions testdata/scripts/cgo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ cmp stderr main.stderr

-- go.mod --
module test/main

go 1.15
-- main.go --
package main

Expand Down
2 changes: 2 additions & 0 deletions testdata/scripts/debugdir.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ garble -debugdir ./test1 build -v

-- go.mod --
module test/main

go 1.15
-- main.go --
package main

Expand Down
2 changes: 2 additions & 0 deletions testdata/scripts/goprivate.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ garble build -o=out ./standalone

-- go.mod --
module test/main

go 1.15
-- standalone/main.go --
package main

Expand Down
2 changes: 2 additions & 0 deletions testdata/scripts/implement.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ cmp stderr main.stderr

-- go.mod --
module test/main

go 1.15
-- main.go --
package main

Expand Down
14 changes: 14 additions & 0 deletions testdata/scripts/imports.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# Note that this is the only test with a module where we rely on the detection
# of GOPRIVATE.
# Also note that, since this is the only test using "real" external modules
# fetched via GOPROXY, go.mod and go.sum should declare the dependencies.

garble build -tags buildtag
exec cat go.sum
exec ./main
cmp stdout main.stdout

Expand Down Expand Up @@ -29,6 +32,17 @@ cmp stdout main.stdout

-- go.mod --
module test/main

go 1.15

require rsc.io/quote v1.5.2
-- go.sum --
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c h1:pvCbr/wm8HzDD3fVywevekufpn6tCGPY3spdHeZJEsw=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
rsc.io/quote v1.5.2 h1:3fEykkD9k7lYzXqCYrwGAf7iNhbk4yCjHmKBN9td4L0=
rsc.io/quote v1.5.2/go.mod h1:LzX7hefJvL54yjefDEDHNONDjII0t9xZLPXsUe+TKr0=
rsc.io/sampler v1.3.0 h1:HLGR/BgEtI3r0uymSP/nl2uPLsUnNJX8toRyhfpBTII=
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
-- main.go --
package main

Expand Down
2 changes: 2 additions & 0 deletions testdata/scripts/init.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ cmp stderr main.stderr

-- go.mod --
module test/main

go 1.15
-- main.go --
package main

Expand Down
2 changes: 2 additions & 0 deletions testdata/scripts/ldflags.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ binsubstr main$exe 'unexportedVersion'

-- go.mod --
module domain.test/main

go 1.15
-- main.go --
package main

Expand Down
2 changes: 2 additions & 0 deletions testdata/scripts/literals.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ grep '^\s+type \w+ func\(byte\) \w+$' .obf-src/main/extraLiterals.go

-- go.mod --
module test/main

go 1.15
-- main.go --
package main

Expand Down
2 changes: 2 additions & 0 deletions testdata/scripts/modinfo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ binsubstr main$exe '(devel)'

-- go.mod --
module test/main

go 1.15
-- main.go --
package main

Expand Down
2 changes: 2 additions & 0 deletions testdata/scripts/plugin.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ cmp stderr main.stderr

-- go.mod --
module test/main

go 1.15
-- plugin/main.go --
package main

Expand Down
2 changes: 2 additions & 0 deletions testdata/scripts/seed.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ stderr .

-- go.mod --
module test/main

go 1.15
-- main.go --
package main

Expand Down
7 changes: 7 additions & 0 deletions testdata/scripts/syntax.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
env GOPRIVATE='test/main,private.source/*'

garble build -tags directives
exec cat go.mod
exec ./main$exe
cmp stderr main.stderr

Expand All @@ -19,6 +20,8 @@ binsubstr main$exe 'globalVar' # 'globalType' only matches on go < 1.15

-- extra/go.mod --
module "private.source/extra"

go 1.15
-- extra/extra.go --
package extra

Expand All @@ -28,8 +31,12 @@ func Func() string {
-- go.mod --
module test/main

go 1.15

// We include an extra module to obfuscate, included in the same original source
// code via a replace directive.
require private.source/extra v0.0.0-00010101000000-000000000000

replace private.source/extra => ./extra
-- main.go --
package main
Expand Down
2 changes: 2 additions & 0 deletions testdata/scripts/test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ stdout 'PASS.*TestFoo'

-- go.mod --
module test/bar

go 1.15
-- bar.go --
package bar

Expand Down
2 changes: 2 additions & 0 deletions testdata/scripts/tiny.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ stderr 'panic: oh noes'

-- go.mod --
module test/main

go 1.15
-- main.go --
package main

Expand Down

0 comments on commit 39372a8

Please sign in to comment.