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

Comments

Projects
None yet
5 participants
@sgerhardt
Copy link

commented Sep 26, 2016

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

This comment has been minimized.

Copy link
Member

commented Sep 26, 2016

@adg

This comment has been minimized.

Copy link
Contributor

commented Sep 26, 2016

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

@minux

This comment has been minimized.

Copy link
Member

commented Sep 27, 2016

@sgerhardt

This comment has been minimized.

Copy link
Author

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

This comment has been minimized.

Copy link
Contributor

commented Sep 27, 2016

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

@seangerhardt-wf

This comment has been minimized.

Copy link

commented Sep 28, 2016

@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

This comment has been minimized.

Copy link
Contributor

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

This comment has been minimized.

Copy link
Author

commented Sep 28, 2016

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

This comment has been minimized.

Copy link
Contributor

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

This comment has been minimized.

Copy link
Author

commented Sep 28, 2016

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

@adg

This comment has been minimized.

Copy link
Contributor

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

This comment has been minimized.

Copy link

commented Sep 28, 2016

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

@gopherbot gopherbot closed this in 594cddd Sep 28, 2016

@golang golang locked and limited conversation to collaborators Sep 28, 2017

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.