Accepted proposal: Go examples with any signature 0 ▲ Redowan's Reflections 118 days ago · Tech · hide · Fediverse post Go’s proposal to allow examples with any signature was accepted on July 8. Today, an example must look like func ExampleXxx(). go/doc skips the function as soon as it sees a parameter or result. The example doesn’t appear in go doc or on pkg.go.dev. The restriction comes from the two jobs an example can do: appear in documentation and run as a test. The test behavior starts when the function has a trailing // Output: comment. The generated test harness can call ExampleXxx() because it needs no arguments and returns nothing. go test captures the function’s stdout, then compares that text with the comment. Without an output comment, the example is compiled but isn’t executed. The zero-argument signature gets in the way when an API expects a value supplied by the caller. For example, testing/synctest.Test takes a *testing.T as its first argument. An example of a normal call needs the same parameter: func ExampleTest(t *testing.T) { synctest.Test(t, func(t *testing.T) { start :=… Commenting on Bubbles has been removed. Why? If you want to talk about this post, write to the author, use the comments on their blog if it has them, or reply with a "RE:" post on your own blog. Suggestions? feedback@bubbles.town