Accepted proposal: Go examples with any signature 0 ▲ Redowan's Reflections 1 hour ago · Tech · hide · 0 comments 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 :=… No comments yet. Log in to reply on the Fediverse. Comments will appear here.