Skip to content

testing: Assert(...error) #7009

Closed
Closed

Description

@lukescott
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()
    }
}

Activity

  1. robpike commented on Dec 26, 2013

    @robpike
    Contributor

    Comment 1:

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

    Status changed to WorkingAsIntended.

  2. locked and limited conversation to collaborators on Jun 25, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions