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

testing: add `assert` function #21015

Closed
jmeridth opened this issue Jul 15, 2017 · 6 comments

Comments

Projects
None yet
5 participants
@jmeridth
Copy link

commented Jul 15, 2017

Please answer these questions before submitting your issue. Thanks!

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

1.8.3

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

GOARCH="amd64"
GOHOSTOS="linux"
Ubuntu 17.04

I'd like to make the func assert available in the testing standard library package. I see it being used in multiple places already and it makes sense to centralize it and DRY up the usage.

Examples:
https://github.com/golang/go/blob/master/test/const.go#L39
https://github.com/golang/go/blob/master/test/iota.go#L11
https://github.com/golang/go/blob/master/test/typeswitch.go#L38

@jmeridth jmeridth changed the title Add `assert` function to testing standard library testing: add `assert` function Jul 15, 2017

@bradfitz

This comment has been minimized.

Copy link
Member

commented Jul 15, 2017

I don't think we'd do this before Go had generics (#15292) even if we did. I don't know what's changed from previous times when this has been rejected. (usual argument I see is that testing assertion libraries become little DSLs and medium DSLs and then it's a whole new language you're using instead of using the language that the rest of your program is written in)

I'm going to place this on hold until #15292 makes some progress, though.

In the meantime you can use https://github.com/stretchr/testify etc.

@jmeridth

This comment has been minimized.

Copy link
Author

commented Jul 15, 2017

@bradfitz I'm new to the language and looked through the current issues. I should have looked through the closed ones.😄 example

Thank you for the polite and informational response. I look forward to seeing where this goes.

Cheers 🍻

@bradfitz

This comment has been minimized.

Copy link
Member

commented Jul 15, 2017

Right, thanks. I forgot this was in the FAQ, as you've found: https://golang.org/doc/faq#testing_framework

@jmeridth

This comment has been minimized.

Copy link
Author

commented Jul 15, 2017

@bradfitz ah, thanks. I shall read all of that before filing future issues. 😄

@bronze1man

This comment has been minimized.

Copy link
Contributor

commented Jul 19, 2017

I also think *test.Testing is too complex to use.
Why not just use panic when something is wrong?
Understand stack trace has less job then write right error message.

I think following function prototypes are better than the one is suggested.

func Assert(t bool, s ...string)  
func AssertEqual(a interface{},b interface{},s ...string) // a and b should have the same json.Marshal output.

https://github.com/bronze1man/kmg/blob/master/kmgTest/testV2.go#L11

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Apr 13, 2018

Nothing to do here.

@golang golang locked and limited conversation to collaborators Apr 13, 2019

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.