Skip to content

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

@breadnette

Description

@breadnette

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:

  • ExampleClient_evaluate is marked as an Evaluate example on Client. Likewise, ExampleClient_bulkEvaluate is marked as a BulkEvaluate example on Client.
    Screenshot 2024-09-16 at 5 49 12 PM
    • these are the examples which goreadme is able to parse
  • ExampleClient_Evaluate is marked as an example of Client.Evaluate, and ExampleClient_BulkEvaluate is marked as an example of Client.BulkEvaluate.
    Screenshot 2024-09-16 at 5 48 00 PM

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions