Open
Description
Many test code are something like:
func TestAAA(t *testing.T) {
if got != want {
t.Errorf("got %v, want %v")
}
}
However, these kind of code are pretty useless when we expected multi-line values.
For example,
--- FAIL: TestExamples (0.00s)
example_test.go:186: Import: got Play == "package main\n\nimport (\n\t\"fmt\"\n\t\"log\"\n\t\"os/exec\"\n)\n\nfunc main() {\n\tout, err := exec.Command(\"date\").Output()\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\tfmt.Printf(\"The date is %s\\n\", out)\n}\n", want "package main\n\nimport (\n\t\"fmt\"\n\t\"log\"\n\t\"os/exec\"\n)\n\n// aaa\n\nfunc main() {\n out, err := exec.Command(\"date\").Output()\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\tfmt.Printf(\"The date is %s\\n\", out)\n}\n"
FAIL
So, I propose to support diff algorithm for making error messages human-readable.
The simplest implementation is executing the diff
command. It doesn't work on windows.
But we can use fallback, so it can be a good starting point.
I'm not sure that supporting the "diff" package officially is worth doing.
But "internal" packages seem harmless.