update modinfo.txt test for 1.18's build and VCS info

That is, use a very specific build tag and git commit,
and ensure that neither ends up in the binary.

Luckily, we have nothing to do here.
We were already removing _gomod_.go from the build entirely,
and that is still the mechanism that "go build" uses to bundle the data.

Note that the test will still work if git is not installed,
but it will simply not check the VCS side.

Finally, we use "go version -m" to check the existing fields,
which is easier than calling the Go APIs directly.

It seems like "go test" passes on yesterday's Go master, now.
So, enable test-gotip again with that commit hash.

Fixes #385.
pull/418/head
Daniel Martí 3 years ago committed by Andrew LeFevre
parent 29356f30f7
commit 64cbbbaa0f

@ -32,13 +32,12 @@ jobs:
go test -race ./... go test -race ./...
test-gotip: test-gotip:
if: ${{ false }} # TODO: support Go 1.18, see https://github.com/burrowers/garble/issues/385
runs-on: ubuntu-latest runs-on: ubuntu-latest
continue-on-error: true # master breaks sometimes continue-on-error: true # master may not be as stable
steps: steps:
- name: Install Go - name: Install Go
env: env:
GO_COMMIT: 46fd547d899286982971474b329d7a95da4f2a6b # 2021-08-11 GO_COMMIT: 578ada410de8065dbca46bca08a5993d1307f423 # 2021-11-09
run: | run: |
cd $HOME cd $HOME
mkdir $HOME/gotip mkdir $HOME/gotip

@ -91,6 +91,7 @@ func TestScripts(t *testing.T) {
"binsubstr": binsubstr, "binsubstr": binsubstr,
"bincmp": bincmp, "bincmp": bincmp,
"generate-literals": generateLiterals, "generate-literals": generateLiterals,
"setenvfile": setenvfile,
}, },
UpdateScripts: *update, UpdateScripts: *update,
} }
@ -216,6 +217,17 @@ func generateLiterals(ts *testscript.TestScript, neg bool, args []string) {
} }
} }
func setenvfile(ts *testscript.TestScript, neg bool, args []string) {
if neg {
ts.Fatalf("unsupported: ! setenvfile")
}
if len(args) != 2 {
ts.Fatalf("usage: setenvfile name file")
}
ts.Setenv(args[0], ts.ReadFile(args[1]))
}
func TestSplitFlagsFromArgs(t *testing.T) { func TestSplitFlagsFromArgs(t *testing.T) {
t.Parallel() t.Parallel()
tests := []struct { tests := []struct {

@ -1,16 +1,31 @@
env GOPRIVATE=test/main env GOPRIVATE=test/main
garble build [exec:git] exec git init -q
exec ./main [exec:git] exec git config user.name "name"
cmp stderr main.stderr [exec:git] exec git config user.email "name@email.local"
! binsubstr main$exe '(devel)' [exec:git] exec git add go.mod main.go
[exec:git] exec git commit -q -m 'very unique commit message'
[exec:git] exec git rev-parse HEAD
[exec:git] setenvfile HEAD_COMMIT_SHA stdout
garble build -tags veryuniquebuildtag
! binsubstr main$exe '(devel)' 'veryuniquebuildtag' ${HEAD_COMMIT_SHA}
go version -m main$exe
stdout 'main(\.exe)?: unknown'
stdout -count=1 '^.+$' # expect just one line
[short] stop # no need to verify this with -short [short] stop # no need to verify this with -short
go build go build -tags veryuniquebuildtag
exec ./main [!go1.18] binsubstr main$exe '(devel)'
cmp stderr main.stderr-orig [go1.18] binsubstr main$exe '(devel)' 'veryuniquebuildtag' ${HEAD_COMMIT_SHA}
binsubstr main$exe '(devel)'
go version -m main$exe
stdout 'path\s*test/main'
stdout 'mod\s*test/main\s*\(devel\)'
[go1.18] stdout 'build\s*tags.*veryuniquebuildtag'
[go1.18] stdout 'build\s*gitrevision.*'${HEAD_COMMIT_SHA}
-- go.mod -- -- go.mod --
module test/main module test/main
@ -19,16 +34,4 @@ go 1.17
-- main.go -- -- main.go --
package main package main
import "runtime/debug" func main() { println("hello world") }
func main() {
if info, ok := debug.ReadBuildInfo(); ok {
println("version", info.Main.Version)
} else {
println("no version")
}
}
-- main.stderr-orig --
version (devel)
-- main.stderr --
no version

Loading…
Cancel
Save