Skip to content

Commit 6cf2d5f

Browse files
committed
Fix windows tests
1 parent 75539ff commit 6cf2d5f

3 files changed

Lines changed: 17 additions & 8 deletions

File tree

pkg/app/test_command_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ func Test_TestCommand(t *testing.T) {
1010
err := TestCommand("commander.yaml", "", AddCommandContext{})
1111

1212
if runtime.GOOS == "windows" {
13-
assert.Equal(t, "Error open commander.yaml: The system cannot find the file specified.", err.Error())
13+
assert.Contains(t, err.Error(), "Error open commander.yaml:")
1414
} else {
1515
assert.Equal(t, "Error open commander.yaml: no such file or directory", err.Error())
1616
}
@@ -20,7 +20,7 @@ func Test_TestCommand_ShouldUseCustomFile(t *testing.T) {
2020
err := TestCommand("my-test.yaml", "", AddCommandContext{})
2121

2222
if runtime.GOOS == "windows" {
23-
assert.Equal(t, "Error open my-test.yaml: The system cannot find the file specified.", err.Error())
23+
assert.Contains(t, err.Error(), "Error open my-test.yaml: ")
2424
} else {
2525
assert.Equal(t, "Error open my-test.yaml: no such file or directory", err.Error())
2626
}

pkg/runtime/runtime.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,17 +195,26 @@ func runTest(test TestCase) TestResult {
195195
// Write test result
196196
test.Result = CommandResult{
197197
ExitCode: cut.ExitCode(),
198-
Stdout: strings.TrimSpace(cut.Stdout()),
199-
Stderr: strings.TrimSpace(cut.Stderr()),
198+
Stdout: strings.TrimSpace(strings.Replace(cut.Stdout(), "\r\n", "\n", -1)),
199+
Stderr: strings.TrimSpace(strings.Replace(cut.Stderr(), "\r\n", "\n", -1)),
200200
}
201201

202-
log.Println("title: '"+test.Title+"'", " ExitCode: ", test.Result.ExitCode)
203-
log.Println("title: '"+test.Title+"'", " Stdout: ", test.Result.Stdout)
204-
log.Println("title: '"+test.Title+"'", " Stderr: ", test.Result.Stderr)
202+
log.Println("title: '" + test.Title + "'", " ExitCode: ", test.Result.ExitCode)
203+
log.Println("title: '" + test.Title + "'", " Stdout: ", test.Result.Stdout)
204+
log.Println("title: '" + test.Title + "'", " Stderr: ", test.Result.Stderr)
205205

206206
return Validate(test)
207207
}
208208

209+
// trimSpace implementation to trim CLRF off
210+
func trimSpace(s string) string {
211+
result := strings.TrimSpace(s)
212+
if runtime.GOOS == "windows" {
213+
return strings.Trim(s, "\r\n")
214+
}
215+
return result
216+
}
217+
209218
func createEnvVarsOption(test TestCase) func(c *cmd.Command) {
210219
return func(c *cmd.Command) {
211220
// Add all env variables from parent process

pkg/runtime/runtime_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func Test_runTestShouldReturnError(t *testing.T) {
9999
got := runTest(test)
100100

101101
if runtime.GOOS == "windows" {
102-
assert.Contains(t, got.TestCase.Result.Error.Error(), "chdir /home/invalid: The system cannot find the path specified.")
102+
assert.Contains(t, got.TestCase.Result.Error.Error(), "chdir /home/invalid")
103103
} else {
104104
assert.Equal(t, "chdir /home/invalid: no such file or directory", got.TestCase.Result.Error.Error())
105105
}

0 commit comments

Comments
 (0)