diff --git a/cmd/go-contrib-init/contrib_test.go b/cmd/go-contrib-init/contrib_test.go index c151f020dd..94764b0138 100644 --- a/cmd/go-contrib-init/contrib_test.go +++ b/cmd/go-contrib-init/contrib_test.go @@ -1,7 +1,13 @@ +// Copyright 2017 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + package main import ( + "errors" "os" + "os/exec" "runtime" "testing" ) @@ -33,3 +39,21 @@ func TestExpandUser(t *testing.T) { } } } + +func TestCmdErr(t *testing.T) { + tests := []struct { + input error + want string + }{ + {input: errors.New("cmd error"), want: "cmd error"}, + {input: &exec.ExitError{ProcessState: nil, Stderr: nil}, want: ""}, + {input: &exec.ExitError{ProcessState: nil, Stderr: []byte("test")}, want: ": test"}, + } + + for i, tt := range tests { + got := cmdErr(tt.input) + if got != tt.want { + t.Fatalf("%d. got %q, want %q", i, got, tt.want) + } + } +}