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: add Test function #32067

Closed
rogpeppe opened this issue May 15, 2019 · 5 comments
Closed

proposal: testing: add Test function #32067

rogpeppe opened this issue May 15, 2019 · 5 comments
Labels
Milestone

Comments

@rogpeppe
Copy link
Contributor

@rogpeppe rogpeppe commented May 15, 2019

The testing package has long contained the Benchmark function, which allows code in a non-testing source file to run benchmarks.

It is sometimes useful to be able to run test code in a non-testing context too; for example to demonstrate a failing test in the Go playground.

Perhaps something like this?

// Test runs f as a test with the given name. Any test output
// is written to w. Test reports whether the test has succeeded.
func Test(w io.Writer, name string, f func(t *testing.T)) bool
@gopherbot gopherbot added this to the Proposal milestone May 15, 2019
@gopherbot gopherbot added the Proposal label May 15, 2019
@josharian

This comment has been minimized.

Copy link
Contributor

@josharian josharian commented May 15, 2019

See also #6511

There is work in progress now to allow multiple files in the playground, which should make this better yet.

@rsc

This comment has been minimized.

Copy link
Contributor

@rsc rsc commented May 28, 2019

I had no idea that https://play.golang.org/p/LnHfX2yF4Oe worked, but it does. (We should write clearer docs for the playground - @bradfitz will file a bug.)

Given that https://play.golang.org/p/LnHfX2yF4Oe does work, @rogpeppe, is there still much rationale for adding testing.Test?

@rsc rsc closed this May 28, 2019
@bradfitz

This comment has been minimized.

Copy link
Contributor

@bradfitz bradfitz commented May 28, 2019

I filed #32294

@rsc

This comment has been minimized.

Copy link
Contributor

@rsc rsc commented May 29, 2019

Looking at this again I am surprised that GitHub says I closed this. I suspect I clicked the wrong button again. I intended to leave it open for @rogpeppe to respond.

@rsc rsc reopened this May 29, 2019
@rogpeppe

This comment has been minimized.

Copy link
Contributor Author

@rogpeppe rogpeppe commented May 29, 2019

Thanks Russ - the close did feel a little sudden :) The playground was my main motivation behind raising this issue, so I think it's OK to close this issue. I might remember another use case in time though.

@rogpeppe rogpeppe closed this May 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.