| 1 |
# This test checks that VCS information is stamped into Go binaries by default, |
| 2 |
# controlled with -buildvcs. This test focuses on Bazaar specifics. |
| 3 |
# The Git test covers common functionality. |
| 4 |
|
| 5 |
[short] skip |
| 6 |
[!bzr] skip 'requires a working bzr client' |
| 7 |
env GOBIN=$WORK/gopath/bin |
| 8 |
env oldpath=$PATH |
| 9 |
env HOME=$WORK |
| 10 |
cd repo/a |
| 11 |
exec bzr whoami 'J.R. Gopher <[email protected]>' |
| 12 |
|
| 13 |
# If there's no local repository, there's no VCS info. |
| 14 |
go install |
| 15 |
go version -m $GOBIN/a$GOEXE |
| 16 |
! stdout bzrrevision |
| 17 |
stdout '^\tmod\texample.com/a\t\(devel\)' |
| 18 |
rm $GOBIN/a$GOEXE |
| 19 |
|
| 20 |
# If there is a repository, but it can't be used for some reason, |
| 21 |
# there should be an error. It should hint about -buildvcs=false. |
| 22 |
cd .. |
| 23 |
mkdir .bzr |
| 24 |
env PATH=$WORK${/}fakebin${:}$oldpath |
| 25 |
chmod 0755 $WORK/fakebin/bzr |
| 26 |
! exec bzr help |
| 27 |
cd a |
| 28 |
! go install |
| 29 |
stderr '^error obtaining VCS status: exit status 1\n\tUse -buildvcs=false to disable VCS stamping.$' |
| 30 |
rm $GOBIN/a$GOEXE |
| 31 |
cd .. |
| 32 |
env PATH=$oldpath |
| 33 |
rm .bzr |
| 34 |
|
| 35 |
# If there is an empty repository in a parent directory, only "modified" is tagged. |
| 36 |
exec bzr init |
| 37 |
cd a |
| 38 |
go install |
| 39 |
go version -m $GOBIN/a$GOEXE |
| 40 |
stdout '^\tbuild\tvcs=bzr$' |
| 41 |
! stdout vcs.revision |
| 42 |
! stdout vcs.time |
| 43 |
stdout '^\tbuild\tvcs.modified=true$' |
| 44 |
cd .. |
| 45 |
|
| 46 |
# Revision and commit time are tagged for repositories with commits. |
| 47 |
exec bzr add a README go.mod |
| 48 |
exec bzr commit -m 'initial commit' |
| 49 |
cd a |
| 50 |
go install |
| 51 |
go version -m $GOBIN/a$GOEXE |
| 52 |
stdout '^\tbuild\tvcs=bzr$' |
| 53 |
stdout '^\tbuild\tvcs.revision=' |
| 54 |
stdout '^\tbuild\tvcs.time=' |
| 55 |
stdout '^\tbuild\tvcs.modified=false$' |
| 56 |
stdout '^\tmod\texample.com/a\tv0.0.0-\d+-\d+\t+' |
| 57 |
rm $GOBIN/a$GOEXE |
| 58 |
|
| 59 |
# Tag is reflected in the version. |
| 60 |
cd .. |
| 61 |
cp README README2 |
| 62 |
exec bzr add a README2 |
| 63 |
exec bzr commit -m 'second commit' |
| 64 |
exec bzr tag a/v1.2.3 |
| 65 |
cd a |
| 66 |
go install |
| 67 |
go version -m $GOBIN/a$GOEXE |
| 68 |
stdout '^\tbuild\tvcs=bzr$' |
| 69 |
stdout '^\tbuild\tvcs.revision=' |
| 70 |
stdout '^\tbuild\tvcs.time=' |
| 71 |
stdout '^\tbuild\tvcs.modified=false$' |
| 72 |
stdout '^\tmod\texample.com/a\tv1.2.3\t+' |
| 73 |
rm $GOBIN/a$GOEXE |
| 74 |
|
| 75 |
# Building an earlier commit should still build clean. |
| 76 |
cp ../../outside/empty.txt ../NEWS |
| 77 |
exec bzr add ../NEWS |
| 78 |
exec bzr commit -m 'add NEWS' |
| 79 |
exec bzr update -r1 |
| 80 |
go install |
| 81 |
go version -m $GOBIN/a$GOEXE |
| 82 |
stdout '^\tbuild\tvcs=bzr$' |
| 83 |
stdout '^\tbuild\tvcs.revision=' |
| 84 |
stdout '^\tbuild\tvcs.time=' |
| 85 |
stdout '^\tbuild\tvcs.modified=false$' |
| 86 |
|
| 87 |
# Building with -buildvcs=false suppresses the info. |
| 88 |
go install -buildvcs=false |
| 89 |
go version -m $GOBIN/a$GOEXE |
| 90 |
! stdout vcs.revision |
| 91 |
rm $GOBIN/a$GOEXE |
| 92 |
|
| 93 |
# An untracked file is shown as modified, even if it isn't part of the build. |
| 94 |
cp ../../outside/empty.txt . |
| 95 |
go install |
| 96 |
go version -m $GOBIN/a$GOEXE |
| 97 |
stdout '^\tbuild\tvcs.modified=true$' |
| 98 |
rm empty.txt |
| 99 |
rm $GOBIN/a$GOEXE |
| 100 |
|
| 101 |
# An edited file is shown as modified, even if it isn't part of the build. |
| 102 |
cp ../../outside/empty.txt ../README |
| 103 |
go install |
| 104 |
go version -m $GOBIN/a$GOEXE |
| 105 |
stdout '^\tbuild\tvcs.modified=true$' |
| 106 |
exec bzr revert ../README |
| 107 |
rm $GOBIN/a$GOEXE |
| 108 |
|
| 109 |
-- $WORK/fakebin/bzr -- |
| 110 |
#!/bin/sh |
| 111 |
exit 1 |
| 112 |
-- $WORK/fakebin/bzr.bat -- |
| 113 |
exit 1 |
| 114 |
-- repo/README -- |
| 115 |
Far out in the uncharted backwaters of the unfashionable end of the western |
| 116 |
spiral arm of the Galaxy lies a small, unregarded yellow sun. |
| 117 |
-- repo/go.mod -- |
| 118 |
module example.com |
| 119 |
|
| 120 |
go 1.18 |
| 121 |
-- repo/a/go.mod -- |
| 122 |
module example.com/a |
| 123 |
|
| 124 |
go 1.18 |
| 125 |
-- repo/a/a.go -- |
| 126 |
package main |
| 127 |
|
| 128 |
func main() {} |
| 129 |
-- outside/empty.txt -- |