1 # This test checks that VCS information is stamped into Go binaries by default,
2 # controlled with -buildvcs. This test focuses on Subversion specifics.
3 # The Git test covers common functionality.
4
5 [!exec:svn] skip
6 [!exec:svnadmin] skip
7 [short] skip
8 env GOBIN=$WORK/gopath/bin
9 env oldpath=$PATH
10 cd repo/a
11
12 # If there's no local repository, there's no VCS info.
13 go install
14 go version -m $GOBIN/a$GOEXE
15 ! stdout vcs.revision
16 stdout '\s+mod\s+example.com/a\s+\(devel\)'
17 rm $GOBIN/a$GOEXE
18
19 # If there is a repository, but it can't be used for some reason,
20 # there should be an error. It should hint about -buildvcs=false.
21 cd ..
22 mkdir .svn
23 env PATH=$WORK${/}fakebin${:}$oldpath
24 chmod 0755 $WORK/fakebin/svn
25 ! exec svn help
26 cd a
27 ! go install
28 stderr '^error obtaining VCS status: exit status 1\n\tUse -buildvcs=false to disable VCS stamping.$'
29 rm $GOBIN/a$GOEXE
30 cd ..
31 env PATH=$oldpath
32 rm .svn
33
34 # Untagged repo.
35 exec svnadmin create repo
36 exec svn checkout file://$PWD/repo workingDir
37 cd workingDir
38 cp ../a/a.go .
39 cp ../a/go.mod .
40 cp ../README .
41 exec svn status
42 exec svn add a.go go.mod README
43 exec svn commit -m 'initial commit'
44 exec svn update
45 go install
46 go version -m $GOBIN/a$GOEXE
47 stdout '^\tbuild\tvcs=svn$'
48 stdout '^\tbuild\tvcs.revision=1$'
49 stdout '^\tbuild\tvcs.time='
50 stdout '^\tbuild\tvcs.modified=false$'
51 stdout '^\tmod\texample.com/a\tv0.0.0-\d+-\d+\t+'
52 rm $GOBIN/a$GOEXE
53
54 # Building with -buildvcs=false suppresses the info.
55 go install -buildvcs=false
56 go version -m $GOBIN/a$GOEXE
57 ! stdout vcs.revision
58 stdout '\s+mod\s+example.com/a\s+\(devel\)'
59 rm $GOBIN/a$GOEXE
60
61 # An untracked file is shown as uncommitted, even if it isn't part of the build.
62 cp ../../outside/empty.txt extra.txt
63 go install
64 go version -m $GOBIN/a$GOEXE
65 stdout '^\tbuild\tvcs.modified=true$'
66 stdout '\s+mod\s+example.com/a\s+v0.0.0-\d+-\d+\+dirty\s+'
67 rm extra.txt
68 rm $GOBIN/a$GOEXE
69
70 # An edited file is shown as uncommitted, even if it isn't part of the build.
71 cp ../../outside/empty.txt README
72 go install
73 go version -m $GOBIN/a$GOEXE
74 stdout '^\tbuild\tvcs.modified=true$'
75 stdout '\s+mod\s+example.com/a\s+v0.0.0-\d+-\d+\+dirty\s+'
76 exec svn revert README
77 rm $GOBIN/a$GOEXE
78
79 -- $WORK/fakebin/svn --
80 #!/bin/sh
81 exit 1
82 -- $WORK/fakebin/svn.bat --
83 exit 1
84 -- repo/README --
85 Far out in the uncharted backwaters of the unfashionable end of the western
86 spiral arm of the Galaxy lies a small, unregarded yellow sun.
87 -- repo/a/go.mod --
88 module example.com/a
89
90 go 1.18
91 -- repo/a/a.go --
92 package main
93
94 func main() {}
95
96 -- outside/empty.txt --
97
View as plain text