frictionlessdata / tableschema-go

A Go library for working with Table Schema.
MIT License
46 stars 10 forks source link

Use matryer/is to make tests cleaner #58

Closed danielfireman closed 6 years ago

danielfireman commented 6 years ago

I believe using matryer/is will make tests even more readable. Let's see how it goes.

ThatEric commented 6 years ago

Started looking at this, some of the tests have descriptions, but that isn't really supported by matryer/is. Are you okay ripping those dynamic comments out?

danielfireman commented 6 years ago

Hi @ThatEric, the test descriptions that I can remember are used in subtest descriptions. Does that clarify your question? Could you please point to a specific example?

ThatEric commented 6 years ago

Oh I just mean that the description is sometimes placed in the error message and the matryer/is workflow doesn't allow custom errors like that.

Here is an example of the code in question: t.Errorf("[%s] want:%+v got:%+v", d.Desc, d.Field, f)

That d.Desc is in the error message making a custom error message. In matryer/is you would do this: is.Equal("foo", got) // some static message

There is no option for a dynamic error message as far as I can tell. You could sort of fudge it to work like this, but it sort of semi-defeats the purpose of using matryer/is: if d.Field != f { is.NoErr("[%s] want:%+v got:%+v", d.Desc, d.Field, f))) }

danielfireman commented 6 years ago

Got it.

In those cases, it should be a subtest description. For instance:

t.Errorf("[%s] want:%+v got:%+v", d.Desc, d.Field, f)

Should be:

t.Run(d.Desc, func(t *testing.T) {
     is := is.New(t)
     ...
     is.Equal("foo", got)
})

In that way, we keep code simple/readable but have nice error messages.