Added cool output to failed tests

This commit is contained in:
Sasha Koshka 2024-01-27 18:07:49 -05:00
parent 839178d1d2
commit 7bc24eabe0
1 changed files with 32 additions and 2 deletions

View File

@ -42,12 +42,42 @@ func testReader (test *testing.T, correct string, inputs ...io.Reader) {
test.Error("generator returned error:", err)
return
}
printColumns := func (left, right string) {
test.Logf("%-80v | %v", left, right)
}
printColumnsStyle := func (left, right string, style string) {
test.Logf("\033[%s%-80v - %v\033[0m", style, left, right)
}
got := output.String()
if got != correct {
test.Logf("results do not match")
test.Logf("got:\n%v", got)
test.Logf("correct:\n%v", correct)
got = strings.ReplaceAll(got, "\t", " ")
correct = strings.ReplaceAll(correct, "\t", " ")
got := strings.Split(got, "\n")
correct := strings.Split(correct, "\n")
length := len(got)
if len(correct) > len(got) { length = len(correct) }
printColumns("CORRECT:", "GOT:")
test.Log()
for index := 0; index < length; index ++ {
left := ""
right := ""
if index < len(got) { left = got[index] }
if index < len(correct) { right = correct[index] }
if left != right {
printColumnsStyle(left, right, "31m")
} else {
printColumns(left, right)
}
}
test.Fail()
}
}