posener / goreadme

Generate readme file from Go doc. Now available as a Github action!
MIT License
213 stars 33 forks source link

Goreadme doesn't render ExampleT_M typed examples without -types -methods #135

Open breadnette opened 2 months ago

breadnette commented 2 months ago

Unless supplying -types -methods, goreadme fails to include ExampleT_M-typed examples. The documentation is not clear about this behavior or the needed remedy.

The testing package mentions that there are several naming conventions for typical test types:

The naming convention to declare examples for the package, a function F, a type T and method M on type T are:

func Example() { ... }
func ExampleF() { ... }
func ExampleT() { ... }
func ExampleT_M() { ... }

Multiple example functions for a package/type/function/method may be provided by appending a distinct suffix to the name. The suffix must start with a lower-case letter.

func Example_suffix() { ... }
func ExampleF_suffix() { ... }
func ExampleT_suffix() { ... }
func ExampleT_M_suffix() { ... }

Examples of the form ExampleT_M() do not render in the generated readme by default. Our package has the type Client struct which has the methods Evaluate and BulkEvaluate. When I have my example func ExampleClient_Evaluate, that example is not added to the readme. When I change it to ExampleClient_evaluate, it is then rendered in the readme with the Evaluate header (Client is excluded).

When supplying the -types parameter alone, this behavior remains (though, when providing -types, ExampleClient_evaluate is then correctly placed under the Client header as expected).

While I tried to figure out where I was going wrong with my example names to make them not be included, I ran a local godoc server to see if godoc itself was failing to parse the examples. This confirmed to me that the examples were named correctly and goreadme was failing to find them:

The ExampleT_M_suffix() cases are similarly ignored.

It would be nice if the documentation was a bit clearer about the need to specify -types -methods to force these examples to be included; additionally, it would also be nice to [have an option to] be able to just render all of the method examples without having to include all -types -methods in the readme, as doing so can bring with a fair amount of extra information which doesn't otherwise need to be in the readme.