Skip to content

Commit

Permalink
update modinfo.txt test for 1.18's build and VCS info
Browse files Browse the repository at this point in the history
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 burrowers#385.
  • Loading branch information
mvdan authored and capnspacehook committed Nov 11, 2021
1 parent 29356f3 commit 64cbbba
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 24 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ func TestScripts(t *testing.T) {
"binsubstr": binsubstr,
"bincmp": bincmp,
"generate-literals": generateLiterals,
"setenvfile": setenvfile,
},
UpdateScripts: *update,
}
Expand Down Expand Up @@ -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 {
Expand Down
45 changes: 24 additions & 21 deletions testdata/scripts/modinfo.txt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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") }

0 comments on commit 64cbbba

Please sign in to comment.