Black Lives Matter. Support the Equal Justice Initiative.

Source file src/cmd/go/go_unix_test.go

Documentation: cmd/go

     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  
     5  //go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris
     6  // +build darwin dragonfly freebsd linux netbsd openbsd solaris
     7  
     8  package main_test
     9  
    10  import (
    11  	"os"
    12  	"syscall"
    13  	"testing"
    14  )
    15  
    16  func TestGoBuildUmask(t *testing.T) {
    17  	// Do not use tg.parallel; avoid other tests seeing umask manipulation.
    18  	mask := syscall.Umask(0077) // prohibit low bits
    19  	defer syscall.Umask(mask)
    20  	tg := testgo(t)
    21  	defer tg.cleanup()
    22  	tg.tempFile("x.go", `package main; func main() {}`)
    23  	// Make sure artifact will be output to /tmp/... in case the user
    24  	// has POSIX acl's on their go source tree.
    25  	// See issue 17909.
    26  	exe := tg.path("x")
    27  	tg.creatingTemp(exe)
    28  	tg.run("build", "-o", exe, tg.path("x.go"))
    29  	fi, err := os.Stat(exe)
    30  	if err != nil {
    31  		t.Fatal(err)
    32  	}
    33  	if mode := fi.Mode(); mode&0077 != 0 {
    34  		t.Fatalf("wrote x with mode=%v, wanted no 0077 bits", mode)
    35  	}
    36  }
    37  

View as plain text