Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
sgerhardt opened this issue Sep 26, 2016 · 12 comments
Closed

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

sgerhardt opened this issue Sep 26, 2016 · 12 comments

Comments

@sgerhardt
Copy link

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.

@minux minux added the Proposal label Sep 26, 2016
@minux
Copy link
Member

minux commented Sep 26, 2016 via email

@adg
Copy link
Contributor

adg commented Sep 26, 2016

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

@minux
Copy link
Member

minux commented Sep 27, 2016 via email

@sgerhardt
Copy link
Author

sgerhardt commented Sep 27, 2016

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.

@adg
Copy link
Contributor

adg commented Sep 27, 2016

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

@seangerhardt-wf
Copy link

@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

@adg
Copy link
Contributor

adg commented Sep 28, 2016

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
.

@sgerhardt
Copy link
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.

@adg
Copy link
Contributor

adg commented Sep 28, 2016

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?

@sgerhardt
Copy link
Author

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

@adg
Copy link
Contributor

adg commented Sep 28, 2016

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.

@adg adg self-assigned this Sep 28, 2016
@gopherbot
Copy link

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

@golang golang locked and limited conversation to collaborators Sep 28, 2017
@rsc rsc unassigned adg Jun 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants