summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2014-09-30 14:30:40 -0400
committerRuss Cox <rsc@golang.org>2014-09-30 14:30:40 -0400
commit04055b67c5bba9aef1ecc6278b8be3f59d10384a (patch)
tree885d2c2bd807767e62d57ce8a250a480cee0bc31
parente45fc3eb4da14641c0124fd3a14a5903794f77a5 (diff)
downloadgo-04055b67c5bba9aef1ecc6278b8be3f59d10384a.tar.gz
cmd/go: sometimes name tmp test binary test.test.exe on Windows
Right now it is always pkgname.test.exe, but if pkgname is patch or install or setup or update, Windows thinks that running it will install new software, so it pops up a dialog box asking for more permission. Renaming the binary avoids the Windows security check. This only applies to the binary that the Go command writes to its temporary work directory. If the user runs 'go test -c' or any of the other ways to generate a test binary, it will continue to use pkgname.test.exe. Fixes issue 8711. LGTM=bradfitz R=golang-codereviews, r CC=alex.brainman, bradfitz, golang-codereviews, iant https://codereview.appspot.com/146580043
-rw-r--r--src/cmd/go/test.go37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/cmd/go/test.go b/src/cmd/go/test.go
index 0962e5bb5..c81e40639 100644
--- a/src/cmd/go/test.go
+++ b/src/cmd/go/test.go
@@ -535,6 +535,13 @@ func contains(x []string, s string) bool {
return false
}
+var windowsBadWords = []string{
+ "install",
+ "patch",
+ "setup",
+ "update",
+}
+
func (b *builder) test(p *Package) (buildAction, runAction, printAction *action, err error) {
if len(p.TestGoFiles)+len(p.XTestGoFiles) == 0 {
build := b.action(modeBuild, modeBuild, p)
@@ -794,6 +801,36 @@ func (b *builder) test(p *Package) (buildAction, runAction, printAction *action,
a.objdir = testDir + string(filepath.Separator)
a.objpkg = filepath.Join(testDir, "main.a")
a.target = filepath.Join(testDir, testBinary) + exeSuffix
+ if goos == "windows" {
+ // There are many reserved words on Windows that,
+ // if used in the name of an executable, cause Windows
+ // to try to ask for extra permissions.
+ // The word list includes setup, install, update, and patch,
+ // but it does not appear to be defined anywhere.
+ // We have run into this trying to run the
+ // go.codereview/patch tests.
+ // For package names containing those words, use test.test.exe
+ // instead of pkgname.test.exe.
+ // Note that this file name is only used in the Go command's
+ // temporary directory. If the -c or other flags are
+ // given, the code below will still use pkgname.test.exe.
+ // There are two user-visible effects of this change.
+ // First, you can actually run 'go test' in directories that
+ // have names that Windows thinks are installer-like,
+ // without getting a dialog box asking for more permissions.
+ // Second, in the Windows process listing during go test,
+ // the test shows up as test.test.exe, not pkgname.test.exe.
+ // That second one is a drawback, but it seems a small
+ // price to pay for the test running at all.
+ // If maintaining the list of bad words is too onerous,
+ // we could just do this always on Windows.
+ for _, bad := range windowsBadWords {
+ if strings.Contains(testBinary, bad) {
+ a.target = filepath.Join(testDir, "test.test") + exeSuffix
+ break
+ }
+ }
+ }
buildAction = a
if testC || testNeedBinary {