GoPLS Viewer

Home|gopls/cmd/go-contrib-init/contrib_test.go
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.
4
5package main
6
7import (
8    "errors"
9    "os"
10    "os/exec"
11    "runtime"
12    "testing"
13)
14
15func TestExpandUser(t *testing.T) {
16    env := "HOME"
17    if runtime.GOOS == "windows" {
18        env = "USERPROFILE"
19    } else if runtime.GOOS == "plan9" {
20        env = "home"
21    }
22
23    oldenv := os.Getenv(env)
24    os.Setenv(env"/home/gopher")
25    defer os.Setenv(envoldenv)
26
27    tests := []struct {
28        input string
29        want  string
30    }{
31        {input"~/foo"want"/home/gopher/foo"},
32        {input"${HOME}/foo"want"/home/gopher/foo"},
33        {input"/~/foo"want"/~/foo"},
34    }
35    for _tt := range tests {
36        got := expandUser(tt.input)
37        if got != tt.want {
38            t.Fatalf("want %q, but %q"tt.wantgot)
39        }
40    }
41}
42
43func TestCmdErr(t *testing.T) {
44    tests := []struct {
45        input error
46        want  string
47    }{
48        {inputerrors.New("cmd error"), want"cmd error"},
49        {input: &exec.ExitError{ProcessStatenilStderrnil}, want"<nil>"},
50        {input: &exec.ExitError{ProcessStatenilStderr: []byte("test")}, want"<nil>: test"},
51    }
52
53    for itt := range tests {
54        got := cmdErr(tt.input)
55        if got != tt.want {
56            t.Fatalf("%d. got %q, want %q"igottt.want)
57        }
58    }
59}
60
MembersX
errors
TestCmdErr
TestExpandUser.RangeStmt_680.BlockStmt.got
TestCmdErr.RangeStmt_1127.i
TestCmdErr.tests
TestCmdErr.RangeStmt_1127.tt
TestExpandUser.env
TestExpandUser.oldenv
TestExpandUser.tests
TestExpandUser.RangeStmt_680.tt
TestCmdErr.t
testing
TestExpandUser
TestExpandUser.t
TestCmdErr.RangeStmt_1127.BlockStmt.got
Members
X