Skip to content

testing: support unordered output in Examples. #10149

@liquidgecka

Description

@liquidgecka

Ideally tests should support unordered output as well as regular output in testing so that every example that uses maps doesn't need to make an output array and sort it (therefor adding complexity to unrelated example code.) This is very useful when dealing with maps which by design return unordered iteration patterns.

An example of the syntax I am proposing (Or something like that):

func Example() {
    x := map[string]int{"a": 1, "b": 2, "c", 3}
    for key, value := range x {
        fmt.Printf("key=%s value=%d\n", key, value)
    }

    // Unordered output:
    // key=a value=1
    // key=b value=2
    // key=c value=3
}

In this case the output on godoc would show the above, while the test would pass regardless of which order the lines were outputted.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeSuggestedIssues that may be good for new contributors looking for work to do.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions