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
4 participants
@jmeridth

jmeridth 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 from Add `assert` function to testing standard library to testing: add `assert` function Jul 15, 2017

@bradfitz

This comment has been minimized.

Show comment
Hide comment
@bradfitz

bradfitz Jul 15, 2017

Member

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.

Member

bradfitz 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.

Show comment
Hide comment
@jmeridth

jmeridth 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 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.

Show comment
Hide comment
@bradfitz

bradfitz Jul 15, 2017

Member

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

Member

bradfitz 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.

Show comment
Hide comment
@jmeridth

jmeridth Jul 15, 2017

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

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

@bronze1man

This comment has been minimized.

Show comment
Hide comment
@bronze1man

bronze1man 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

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.

Show comment
Hide comment
@ianlancetaylor

ianlancetaylor Apr 13, 2018

Contributor

Nothing to do here.

Contributor

ianlancetaylor commented Apr 13, 2018

Nothing to do here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment