1 // Copyright 2017 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.
17 func TestAppendPath(t *testing.T) {
18 tmpd, err := ioutil.TempDir("", "go")
22 defer os.RemoveAll(tmpd)
24 if err := os.Setenv("HOME", tmpd); err != nil {
28 GOPATH := os.Getenv("GOPATH")
29 if err := appendToPATH(filepath.Join(GOPATH, "bin")); err != nil {
33 shellConfig, err := shellConfigFile()
37 b, err := ioutil.ReadFile(shellConfig)
42 expected := "export PATH=" + pathVar + envSeparator + filepath.Join(GOPATH, "bin")
43 if strings.TrimSpace(string(b)) != expected {
44 t.Fatalf("expected: %q, got %q", expected, strings.TrimSpace(string(b)))
47 // Check that appendToPATH is idempotent.
48 if err := appendToPATH(filepath.Join(GOPATH, "bin")); err != nil {
51 b, err = ioutil.ReadFile(shellConfig)
55 if strings.TrimSpace(string(b)) != expected {
56 t.Fatalf("expected: %q, got %q", expected, strings.TrimSpace(string(b)))