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.
18 func TestAppendPath(t *testing.T) {
19 tmpd, err := ioutil.TempDir("", "go")
23 defer os.RemoveAll(tmpd)
25 if err := os.Setenv("HOME", tmpd); err != nil {
29 GOPATH := os.Getenv("GOPATH")
30 if err := appendToPATH(filepath.Join(GOPATH, "bin")); err != nil {
34 shellConfig, err := shellConfigFile()
38 b, err := ioutil.ReadFile(shellConfig)
43 expected := "export PATH=" + pathVar + envSeparator + filepath.Join(GOPATH, "bin")
44 if strings.TrimSpace(string(b)) != expected {
45 t.Fatalf("expected: %q, got %q", expected, strings.TrimSpace(string(b)))
48 // Check that appendToPATH is idempotent.
49 if err := appendToPATH(filepath.Join(GOPATH, "bin")); err != nil {
52 b, err = ioutil.ReadFile(shellConfig)
56 if strings.TrimSpace(string(b)) != expected {
57 t.Fatalf("expected: %q, got %q", expected, strings.TrimSpace(string(b)))