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: Assert(...error) #7009

Closed
lukescott opened this issue Dec 23, 2013 · 1 comment
Closed

testing: Assert(...error) #7009

lukescott opened this issue Dec 23, 2013 · 1 comment

Comments

@lukescott
Copy link

@lukescott lukescott commented Dec 23, 2013

I have some helper functions that do certain tests and return helpful output as en
error. To preserve helpful line numbers I have to do this every time:

if e := test.Equals(obtained, expected); e != nil {
    t.Fatal(e)
}

Something like this would be helpful:

t.Assert(test.Equals(obtained, expected))

Could look something like this:

func (c *common) Assert(err ...error) {
    args := make([]error, 0, len(errs))
    for _, e := range err {
        if e != nil {
            args = append(args, e)
        }
    }
    if len(args) > 0 {
        c.log(fmt.Sprintln(args...))
        c.FailNow()
    }
}

Or even this:

func (c *common) Assert(err error) {
    if err != nil {
        c.log(err.Error())
        c.FailNow()
    }
}
@robpike

This comment has been minimized.

Copy link
Contributor

@robpike robpike commented Dec 26, 2013

Comment 1:

http://golang.org/doc/faq#testing_framework

Status changed to WorkingAsIntended.

@golang golang locked and limited conversation to collaborators Jun 25, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

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