From 39372a8c9b441216eac7aab635cc82d79267d428 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Sat, 7 Nov 2020 20:38:53 +0000 Subject: [PATCH] testdata: don't let tests rely on rewriting mod files 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. --- main_test.go | 1 + testdata/scripts/asm.txt | 2 ++ testdata/scripts/basic.txt | 2 ++ testdata/scripts/cgo.txt | 2 ++ testdata/scripts/debugdir.txt | 2 ++ testdata/scripts/goprivate.txt | 2 ++ testdata/scripts/implement.txt | 2 ++ testdata/scripts/imports.txt | 14 ++++++++++++++ testdata/scripts/init.txt | 2 ++ testdata/scripts/ldflags.txt | 2 ++ testdata/scripts/literals.txt | 2 ++ testdata/scripts/modinfo.txt | 2 ++ testdata/scripts/plugin.txt | 2 ++ testdata/scripts/seed.txt | 2 ++ testdata/scripts/syntax.txt | 7 +++++++ testdata/scripts/test.txt | 2 ++ testdata/scripts/tiny.txt | 2 ++ 17 files changed, 50 insertions(+) diff --git a/main_test.go b/main_test.go index 6dc2e75..3a70645 100644 --- a/main_test.go +++ b/main_test.go @@ -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") diff --git a/testdata/scripts/asm.txt b/testdata/scripts/asm.txt index a92a0bf..47b5b9e 100644 --- a/testdata/scripts/asm.txt +++ b/testdata/scripts/asm.txt @@ -18,6 +18,8 @@ cmp stderr main.stderr -- go.mod -- module test/main + +go 1.15 -- main.go -- package main diff --git a/testdata/scripts/basic.txt b/testdata/scripts/basic.txt index 4f86b65..f6b6562 100644 --- a/testdata/scripts/basic.txt +++ b/testdata/scripts/basic.txt @@ -57,6 +57,8 @@ binsubstr main$exe 'main.go' 'globalVar' 'globalFunc' $gofullversion -- go.mod -- module test/mainfoo + +go 1.15 -- main.go -- package main diff --git a/testdata/scripts/cgo.txt b/testdata/scripts/cgo.txt index f46a1e1..99369e2 100644 --- a/testdata/scripts/cgo.txt +++ b/testdata/scripts/cgo.txt @@ -18,6 +18,8 @@ cmp stderr main.stderr -- go.mod -- module test/main + +go 1.15 -- main.go -- package main diff --git a/testdata/scripts/debugdir.txt b/testdata/scripts/debugdir.txt index 45dffaf..530a3b6 100644 --- a/testdata/scripts/debugdir.txt +++ b/testdata/scripts/debugdir.txt @@ -17,6 +17,8 @@ garble -debugdir ./test1 build -v -- go.mod -- module test/main + +go 1.15 -- main.go -- package main diff --git a/testdata/scripts/goprivate.txt b/testdata/scripts/goprivate.txt index 8dff35b..6f41eaf 100644 --- a/testdata/scripts/goprivate.txt +++ b/testdata/scripts/goprivate.txt @@ -13,6 +13,8 @@ garble build -o=out ./standalone -- go.mod -- module test/main + +go 1.15 -- standalone/main.go -- package main diff --git a/testdata/scripts/implement.txt b/testdata/scripts/implement.txt index ba4b10b..44a7a6d 100644 --- a/testdata/scripts/implement.txt +++ b/testdata/scripts/implement.txt @@ -8,6 +8,8 @@ cmp stderr main.stderr -- go.mod -- module test/main + +go 1.15 -- main.go -- package main diff --git a/testdata/scripts/imports.txt b/testdata/scripts/imports.txt index edd5e11..b247f45 100644 --- a/testdata/scripts/imports.txt +++ b/testdata/scripts/imports.txt @@ -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 @@ -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 diff --git a/testdata/scripts/init.txt b/testdata/scripts/init.txt index 2612062..9145f98 100644 --- a/testdata/scripts/init.txt +++ b/testdata/scripts/init.txt @@ -12,6 +12,8 @@ cmp stderr main.stderr -- go.mod -- module test/main + +go 1.15 -- main.go -- package main diff --git a/testdata/scripts/ldflags.txt b/testdata/scripts/ldflags.txt index 31cbcaf..1121447 100644 --- a/testdata/scripts/ldflags.txt +++ b/testdata/scripts/ldflags.txt @@ -20,6 +20,8 @@ binsubstr main$exe 'unexportedVersion' -- go.mod -- module domain.test/main + +go 1.15 -- main.go -- package main diff --git a/testdata/scripts/literals.txt b/testdata/scripts/literals.txt index a816c52..6a7d944 100644 --- a/testdata/scripts/literals.txt +++ b/testdata/scripts/literals.txt @@ -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 diff --git a/testdata/scripts/modinfo.txt b/testdata/scripts/modinfo.txt index 8d7cc09..614f2dc 100644 --- a/testdata/scripts/modinfo.txt +++ b/testdata/scripts/modinfo.txt @@ -14,6 +14,8 @@ binsubstr main$exe '(devel)' -- go.mod -- module test/main + +go 1.15 -- main.go -- package main diff --git a/testdata/scripts/plugin.txt b/testdata/scripts/plugin.txt index 08d1ea4..11a677d 100644 --- a/testdata/scripts/plugin.txt +++ b/testdata/scripts/plugin.txt @@ -28,6 +28,8 @@ cmp stderr main.stderr -- go.mod -- module test/main + +go 1.15 -- plugin/main.go -- package main diff --git a/testdata/scripts/seed.txt b/testdata/scripts/seed.txt index ccd8592..4dfd755 100644 --- a/testdata/scripts/seed.txt +++ b/testdata/scripts/seed.txt @@ -39,6 +39,8 @@ stderr . -- go.mod -- module test/main + +go 1.15 -- main.go -- package main diff --git a/testdata/scripts/syntax.txt b/testdata/scripts/syntax.txt index 8e45c42..83e1300 100644 --- a/testdata/scripts/syntax.txt +++ b/testdata/scripts/syntax.txt @@ -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 @@ -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 @@ -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 diff --git a/testdata/scripts/test.txt b/testdata/scripts/test.txt index 80a1d39..beff578 100644 --- a/testdata/scripts/test.txt +++ b/testdata/scripts/test.txt @@ -19,6 +19,8 @@ stdout 'PASS.*TestFoo' -- go.mod -- module test/bar + +go 1.15 -- bar.go -- package bar diff --git a/testdata/scripts/tiny.txt b/testdata/scripts/tiny.txt index c1df88b..e19f3df 100644 --- a/testdata/scripts/tiny.txt +++ b/testdata/scripts/tiny.txt @@ -22,6 +22,8 @@ stderr 'panic: oh noes' -- go.mod -- module test/main + +go 1.15 -- main.go -- package main