Skip to content

proposal: testing: Export Name of Test or Benchmark #17231

Closed

Description

@sgerhardt

What version of Go are you using (go version)?

1.7

What operating system and processor architecture are you using (go env)?

windows/amd64

What did you do?

Can't get a test name without using reflection or hard-coding name.
Test name is not exported https://github.com/golang/go/blob/master/src/testing/testing.go#L269.

What did you expect to see?

The test name exported.
e.g.

func TestSomething(t *testing.T) {
    t.Log(t.Name())
...
}

What did you see instead?

Non-exported test name.

Activity

  1. minux commented on Sep 26, 2016

    @minux
    Member
  2. adg commented on Sep 26, 2016

    @adg
    Contributor

    This makes sense, but what's your use case?

  3. minux commented on Sep 27, 2016

    @minux
    Member
  4. sgerhardt commented on Sep 27, 2016

    @sgerhardt
    Author

    My use cases are simple. I want to know what test is running when I pass test functions to utility functions, and/or want to log the name of a test for recording to external services.

  5. adg commented on Sep 27, 2016

    @adg
    Contributor

    Ok, sounds good to me. Please write up a brief proposal document.

  6. seangerhardt-wf commented on Sep 28, 2016

    @seangerhardt-wf

    @adg Did you want a design document? As far as proposals go, it looks like this issue should be enough if I've understood the directions correctly.

    The change should be very simple - don't feel like a design document is really necessary, but let me know.

    Thanks,
    Sean

  7. adg commented on Sep 28, 2016

    @adg
    Contributor

    Well, just spec out here what the method looks like.

    On 28 September 2016 at 10:35, Sean Gerhardt notifications@github.com
    wrote:

    @adg https://github.com/adg Did you want a design document? As far as
    proposals go, it looks like this issue should be enough if I've understood
    the directions correctly.

    The change should be very simple - don't feel like a design document is
    really necessary, but let me know.

    Thanks,
    Sean

    —
    You are receiving this because you were mentioned.
    Reply to this email directly, view it on GitHub
    #17231 (comment), or mute
    the thread
    https://github.com/notifications/unsubscribe-auth/AIDilSrVkbWga5qAwTbEVShdZc8R-crrks5qubZogaJpZM4KGFsB
    .

  8. sgerhardt commented on Sep 28, 2016

    @sgerhardt
    Author

    I was thinking we could export the field. https://github.com/golang/go/blob/master/src/testing/testing.go#L269 change nameto Name

    e.g. Name string // Name of test or benchmark.

  9. adg commented on Sep 28, 2016

    @adg
    Contributor

    I'd be wary of doing that, lest people change the Name in a test.
    Safer would be to add a Name() string method to *testing.T and *testing.B, I think.
    Care to send a CL?

  10. sgerhardt commented on Sep 28, 2016

    @sgerhardt
    Author

    That does sound like a safer approach. What's a CL?

  11. adg commented on Sep 28, 2016

    @adg
    Contributor

    A "change list" (see the contribution docs). But this is so simple that I'll do it, to save you the trouble of setting up a dev environment.

  12. self-assigned this
    on Sep 28, 2016
  13. gopherbot commented on Sep 28, 2016

    @gopherbot
    Contributor

    CL https://golang.org/cl/29970 mentions this issue.

  14. locked and limited conversation to collaborators on Sep 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions