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.
15 func TestExpandUser(t *testing.T) {
17 if runtime.GOOS == "windows" {
19 } else if runtime.GOOS == "plan9" {
23 oldenv := os.Getenv(env)
24 os.Setenv(env, "/home/gopher")
25 defer os.Setenv(env, oldenv)
31 {input: "~/foo", want: "/home/gopher/foo"},
32 {input: "${HOME}/foo", want: "/home/gopher/foo"},
33 {input: "/~/foo", want: "/~/foo"},
35 for _, tt := range tests {
36 got := expandUser(tt.input)
38 t.Fatalf("want %q, but %q", tt.want, got)
43 func TestCmdErr(t *testing.T) {
48 {input: errors.New("cmd error"), want: "cmd error"},
49 {input: &exec.ExitError{ProcessState: nil, Stderr: nil}, want: "<nil>"},
50 {input: &exec.ExitError{ProcessState: nil, Stderr: []byte("test")}, want: "<nil>: test"},
53 for i, tt := range tests {
54 got := cmdErr(tt.input)
56 t.Fatalf("%d. got %q, want %q", i, got, tt.want)