@@ -19,7 +19,7 @@ func TestRun(t *testing.T) {
1919 outBytes , _ := ioutil .ReadFile ("testdata/out.txt" )
2020 wantOut := bytes .NewBuffer (outBytes )
2121
22- err := runner .Run (in , & gotOut , false , false )
22+ err := runner .Run (in , & gotOut , false , false , false )
2323
2424 if err != nil {
2525 t .Errorf ("Error should be nil, got %s" , err .Error ())
@@ -38,11 +38,59 @@ func TestRunWithError(t *testing.T) {
3838 inBytes , _ := ioutil .ReadFile ("testdata/err.txt" )
3939 in := bytes .NewBuffer (inBytes )
4040
41- gotErr := runner .Run (in , & out , false , false )
41+ gotErr := runner .Run (in , & out , false , false , false )
4242 wantErr := errors .New ("unexpected EOF" )
4343
4444 if gotErr .Error () != wantErr .Error () {
4545 t .Errorf ("Wanted %s, got %s" , wantErr , gotErr )
4646 }
4747
4848}
49+
50+ func TestRunExitWithNonZero (t * testing.T ) {
51+ var out bytes.Buffer
52+
53+ inBytes , _ := ioutil .ReadFile ("testdata/in.txt" )
54+ in := bytes .NewBuffer (inBytes )
55+
56+ oldOsExit := runner .OsExit
57+ defer func () { runner .OsExit = oldOsExit }()
58+
59+ var got int
60+ testExit := func (code int ) {
61+ got = code
62+ }
63+
64+ runner .OsExit = testExit
65+ err := runner .Run (in , & out , false , false , true )
66+ if err != nil {
67+ t .Errorf ("Error should be nil, got %s" , err .Error ())
68+ }
69+ if exp := 1 ; got != exp {
70+ t .Errorf ("Expected exit code: %d, got: %d" , exp , got )
71+ }
72+ }
73+
74+ func TestRunExitWithNonZeroIndirectsOnly (t * testing.T ) {
75+
76+ inBytes , _ := ioutil .ReadFile ("testdata/update_indirect.txt" )
77+ in := bytes .NewBuffer (inBytes )
78+
79+ oldOsExit := runner .OsExit
80+ defer func () { runner .OsExit = oldOsExit }()
81+
82+ var got int
83+ testExit := func (code int ) {
84+ got = code
85+ }
86+
87+ runner .OsExit = testExit
88+ var out bytes.Buffer
89+ err := runner .Run (in , & out , false , true , true )
90+ if err != nil {
91+ t .Errorf ("Error should be nil, got %s" , err .Error ())
92+ }
93+ if exp := 0 ; got != exp {
94+ t .Errorf ("Expected exit code: %d, got: %d" , exp , got )
95+ }
96+ }
0 commit comments