From 64cbbbaa0feaa2cbc5dda77bb85f7e1c89851e25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Thu, 11 Nov 2021 00:10:18 +0000 Subject: [PATCH] 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. --- .github/workflows/test.yml | 5 ++-- main_test.go | 12 ++++++++++ testdata/scripts/modinfo.txt | 45 +++++++++++++++++++----------------- 3 files changed, 38 insertions(+), 24 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e24dbfa..26e4cf4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 diff --git a/main_test.go b/main_test.go index 12af7d0..c3816b0 100644 --- a/main_test.go +++ b/main_test.go @@ -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 { diff --git a/testdata/scripts/modinfo.txt b/testdata/scripts/modinfo.txt index fe5c261..3a432fc 100644 --- a/testdata/scripts/modinfo.txt +++ b/testdata/scripts/modinfo.txt @@ -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") }