elliotchance / tf

✔️ tf is a microframework for parameterized testing of functions and HTTP in Go.
MIT License
137 stars 3 forks source link

Add Errors() #1

Closed elliotchance closed 6 years ago

elliotchance commented 6 years ago

Based on the fact many functions return result, error it can test for the existence of an error or even further with a message:

Divide(5, 0).Errors() // pass
Divide(5, 0).Errors("divide-by-zero") // pass
Divide(5, 0).Errors("foo") // fail
m1ome commented 6 years ago

In Golang errors are values, more comfortable to provide error with a particular message and type, and check them

elliotchance commented 6 years ago

What do you mean by error type?

m1ome commented 6 years ago

type MyError struct {
    Err error
}

func (e MyError) Error() string {
    return err.Error()
}

customErr := MyError{
    Err: errors.New("i am an error wrapper")
}

r := tf.Function(t, ReturnError() error {
    return customError
})

// This wil pass
r().Errors("i am an error wrapper")
r().Errors(customError)
r().Errors()

// This will fail
r().Errors(errors.New("i am an error wrapper"))
elliotchance commented 6 years ago

Ah yes, I understand what you mean now. I agree.

m1ome commented 6 years ago

Currently on it, but it's harder than i think. Need to have some refactoring to make works properly.

m1ome commented 6 years ago

@elliotchance this one solved by #12

elliotchance commented 6 years ago

Thanks Pavel.