@@ -22,11 +22,7 @@ func TestCommand_Execute(t *testing.T) {
2222
2323 assert .Nil (t , err )
2424 assert .True (t , cmd .Executed ())
25- if runtime .GOOS == "windows" {
26- assert .Equal (t , cmd .Stdout (), "hello\r \n " )
27- } else {
28- assert .Equal (t , cmd .Stdout (), "hello\n " )
29- }
25+ assertEqualWithLineBreak (t , "hello" , cmd .Stdout ())
3026}
3127
3228func TestCommand_ExitCode (t * testing.T ) {
@@ -48,7 +44,7 @@ func TestCommand_WithEnvVariables(t *testing.T) {
4844
4945 _ = cmd .Execute ()
5046
51- assert . Equal (t , cmd .Stdout (), "hey \n " )
47+ assertEqualWithLineBreak (t , "hey" , cmd .Stdout ())
5248}
5349
5450func TestCommand_Executed (t * testing.T ) {
@@ -81,7 +77,7 @@ func TestCommand_AddEnvWithShellVariable(t *testing.T) {
8177 err := c .Execute ()
8278
8379 assert .Nil (t , err )
84- assert . Equal (t , "test from shell\n " , c .Stdout ())
80+ assertEqualWithLineBreak (t , "test from shell" , c .Stdout ())
8581}
8682
8783func TestCommand_AddMultipleEnvWithShellVariable (t * testing.T ) {
@@ -101,7 +97,7 @@ func TestCommand_AddMultipleEnvWithShellVariable(t *testing.T) {
10197 err := c .Execute ()
10298
10399 assert .Nil (t , err )
104- assert . Equal (t , "Hello world, I am Simon\n " , c .Stdout ())
100+ assertEqualWithLineBreak (t , "Hello world, I am Simon" , c .Stdout ())
105101}
106102
107103func getCommand () string {
@@ -153,5 +149,15 @@ func TestCommand_SetOptions(t *testing.T) {
153149
154150 assert .Nil (t , err )
155151 assert .Equal (t , time .Duration (1000000000 ), c .Timeout )
156- assert .Equal (t , "test\n " , writer .String ())
152+ assertEqualWithLineBreak (t , "test" , writer .String ())
153+ }
154+
155+ func assertEqualWithLineBreak (t * testing.T , expected string , actual string ) {
156+ if runtime .GOOS == "windows" {
157+ expected = expected + "\r \n "
158+ } else {
159+ expected = expected + "\n "
160+ }
161+
162+ assert .Equal (t , expected , actual )
157163}
0 commit comments