Dan Willemsen | 38f2dba | 2016-07-08 14:54:35 -0700 | [diff] [blame] | 1 | // Copyright 2015 The Go Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
Dan Willemsen | cc753b7 | 2021-08-31 13:25:42 -0700 | [diff] [blame] | 5 | //go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris |
Dan Willemsen | 38f2dba | 2016-07-08 14:54:35 -0700 | [diff] [blame] | 6 | |
| 7 | package main_test |
| 8 | |
| 9 | import ( |
| 10 | "os" |
| 11 | "syscall" |
| 12 | "testing" |
| 13 | ) |
| 14 | |
| 15 | func TestGoBuildUmask(t *testing.T) { |
| 16 | // Do not use tg.parallel; avoid other tests seeing umask manipulation. |
| 17 | mask := syscall.Umask(0077) // prohibit low bits |
| 18 | defer syscall.Umask(mask) |
| 19 | tg := testgo(t) |
| 20 | defer tg.cleanup() |
| 21 | tg.tempFile("x.go", `package main; func main() {}`) |
Dan Willemsen | d279748 | 2017-07-26 13:13:13 -0700 | [diff] [blame] | 22 | // Make sure artifact will be output to /tmp/... in case the user |
| 23 | // has POSIX acl's on their go source tree. |
| 24 | // See issue 17909. |
| 25 | exe := tg.path("x") |
| 26 | tg.creatingTemp(exe) |
| 27 | tg.run("build", "-o", exe, tg.path("x.go")) |
| 28 | fi, err := os.Stat(exe) |
Dan Willemsen | 38f2dba | 2016-07-08 14:54:35 -0700 | [diff] [blame] | 29 | if err != nil { |
| 30 | t.Fatal(err) |
| 31 | } |
| 32 | if mode := fi.Mode(); mode&0077 != 0 { |
| 33 | t.Fatalf("wrote x with mode=%v, wanted no 0077 bits", mode) |
| 34 | } |
| 35 | } |