Skip to content

benjaminheng/go-test-example-diff

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 

Repository files navigation

go-test-example-diff

Reads go test output, looks for failed examples, and prints a diff for each one.

go install github.com/benjaminheng/go-test-example-diff

Usage

Pipe go test output to the program.

$ go test ./... | go-test-example-diff

Demo

Given an failing example:

func ExampleMain() {
	fmt.Println(`{
  "name": "bob",
  "date_of_birth": "1970",
}`)
	// Output: {
	//   "name": "bob",
	//   "date_of_birth": "1970"
	// }
}

When we execute the tests, it fails with the following output:

$ go test ./...
--- FAIL: ExampleMain (0.00s)
got:
{
  "name": "bob",
  "date_of_birth": "1970",
}
want:
{
  "name": "bob",
  "date_of_birth": "1970"
}
FAIL
FAIL    github.com/benjaminheng/go-test-example-diff    0.005s
FAIL

If we pipe the test output to the program, a diff is added for each failing example:

$ go test ./... | go-test-example-diff
--- FAIL: ExampleMain (0.00s)
got:
{
  "name": "bob",
  "date_of_birth": "1970",
}
want:
{
  "name": "bob",
  "date_of_birth": "1970"
}
diff:
@@ -1,4 +1,4 @@
 {
   "name": "bob",
-  "date_of_birth": "1970",
+  "date_of_birth": "1970"
 }
FAIL
FAIL    github.com/benjaminheng/go-test-example-diff    0.005s
FAIL

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published