Skip to content

Commit

Permalink
test: enhance failure output
Browse files Browse the repository at this point in the history
Printing the actual expected string makes it easier to run a diff, something
that we cannot do here automatically because we cannot depend on testify or
go-cmp.
  • Loading branch information
pohly committed Nov 22, 2024
1 parent 1fcaaa9 commit 15e9f9d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions test/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -575,9 +575,9 @@ func Output(t *testing.T, config OutputConfig) {
expected = strings.ReplaceAll(expected, "<WITH-VALUES-3>", fmt.Sprintf("%d", expectedLine-12))
if actual != expected {
if expectedWithPlaceholder == test.expectedOutput {
t.Errorf("Output mismatch. Expected:\n%s\nActual:\n%s\n", expectedWithPlaceholder, actual)
t.Errorf("Output mismatch.\n\nExpected with placeholders:\n%s\nExpected without placeholders:\n%s\nActual:\n%s\n", expectedWithPlaceholder, expected, actual)
} else {
t.Errorf("Output mismatch. klog:\n%s\nExpected:\n%s\nActual:\n%s\n", test.expectedOutput, expectedWithPlaceholder, actual)
t.Errorf("Output mismatch. klog:\n%s\n\nExpected with placeholders:\n%s\nExpected without placeholders:\n%s\nActual:\n%s\n", test.expectedOutput, expectedWithPlaceholder, expected, actual)
}
}
}
Expand Down Expand Up @@ -843,9 +843,9 @@ func Output(t *testing.T, config OutputConfig) {
expected = strings.ReplaceAll(expected, "<LINE>", fmt.Sprintf("%d", callLine))
if actual != expected {
if expectedWithPlaceholder == test.output {
t.Errorf("Output mismatch. Expected:\n%s\nActual:\n%s\n", expectedWithPlaceholder, actual)
t.Errorf("Output mismatch. Expected with placeholders:\n%s\nExpected without placeholders:\n%s\nActual:\n%s\n", expectedWithPlaceholder, expected, actual)
} else {
t.Errorf("Output mismatch. klog:\n%s\nExpected:\n%s\nActual:\n%s\n", test.output, expectedWithPlaceholder, actual)
t.Errorf("Output mismatch. klog:\n%s\nExpected with placeholders:\n%s\nExpected without placeholders:\n%s\nActual:\n%s\n", test.output, expectedWithPlaceholder, expected, actual)
}
}
})
Expand Down

0 comments on commit 15e9f9d

Please sign in to comment.