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

@ -91,6 +91,7 @@ func TestScripts(t *testing.T) {
"binsubstr": binsubstr,
"bincmp": bincmp,
"generate-literals": generateLiterals,
"setenvfile": setenvfile,
},
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) {
t.Parallel()
tests := []struct {

@ -1,16 +1,31 @@
env GOPRIVATE=test/main
garble build
exec ./main
cmp stderr main.stderr
! binsubstr main$exe '(devel)'
[exec:git] exec git init -q
[exec:git] exec git config user.name "name"
[exec:git] exec git config user.email "name@email.local"
[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
go build
exec ./main
cmp stderr main.stderr-orig
binsubstr main$exe '(devel)'
go build -tags veryuniquebuildtag
[!go1.18] binsubstr main$exe '(devel)'
[go1.18] binsubstr main$exe '(devel)' 'veryuniquebuildtag' ${HEAD_COMMIT_SHA}
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 --
module test/main
@ -19,16 +34,4 @@ go 1.17
-- main.go --
package main
import "runtime/debug"
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
func main() { println("hello world") }

Loading…
Cancel
Save