Skip to content

Commit ee0fe61

Browse files
author
nate smith
committed
test nonzero exit code
1 parent ab115ef commit ee0fe61

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

git/git_test.go

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,29 @@ import (
77
"testing"
88
)
99

10-
var _outputs map[string]string
10+
type outputSpec struct {
11+
Stdout string
12+
ExitCode int
13+
}
14+
15+
var _outputs map[string]outputSpec
1116

1217
func init() {
13-
_outputs = map[string]string{
14-
"no changes": "",
15-
"one change": ` M poem.txt
16-
`,
17-
"untracked file": ` M poem.txt
18+
_outputs = map[string]outputSpec{
19+
"no changes": outputSpec{"", 0},
20+
"one change": outputSpec{` M poem.txt
21+
`, 0},
22+
"untracked file": outputSpec{` M poem.txt
1823
?? new.txt
19-
`,
24+
`, 0},
25+
"boom": outputSpec{"", 1},
2026
}
2127
}
2228

2329
func TestHelperProcess(*testing.T) {
2430
if os.Getenv("GO_WANT_HELPER_PROCESS") != "1" {
2531
return
2632
}
27-
defer os.Exit(0)
2833
args := os.Args
2934
for len(args) > 0 {
3035
if args[0] == "--" {
@@ -33,7 +38,9 @@ func TestHelperProcess(*testing.T) {
3338
}
3439
args = args[1:]
3540
}
36-
fmt.Println(_outputs[args[0]])
41+
output := _outputs[args[0]]
42+
defer os.Exit(output.ExitCode)
43+
fmt.Println(output.Stdout)
3744
}
3845

3946
func StubGit(desiredOutput string) func(...string) *exec.Cmd {
@@ -57,8 +64,6 @@ func Test_UncommittedChangeCount(t *testing.T) {
5764
GitCommand = origGitCommand
5865
}()
5966

60-
// TODO handle git status exiting poorly
61-
6267
cases := map[string]int{
6368
"no changes": 0,
6469
"one change": 1,
@@ -73,4 +78,10 @@ func Test_UncommittedChangeCount(t *testing.T) {
7378
t.Errorf("got unexpected ucc value: %d for case %s", ucc, k)
7479
}
7580
}
81+
82+
GitCommand = StubGit("boom")
83+
_, err := UncommittedChangeCount()
84+
if err.Error() != "failed to run git status: exit status 1" {
85+
t.Errorf("got unexpected error message: %s", err)
86+
}
7687
}

0 commit comments

Comments
 (0)