goparsec icon indicating copy to clipboard operation
goparsec copied to clipboard

Thoughts on an assertion library?

Open vektah opened this issue 7 years ago • 1 comments

Your tests are littered with assertions that look like this:

node, _ := ast.Parsewith(y, s)
if node.GetValue() != "onetwothree" {
	t.Errorf("unexpected: %v", node.GetValue())
} else if _, ok := node.GetChildren()[2].(MaybeNone); ok == false {
	t.Errorf("expected MaybeNone")
}

they could look like this:

node, _ := ast.Parsewith(y, s)
require.Equal(t, "onetwothree", node.GetValue())
require.IsType(t, MaybeNone{}, node.GetChildren()[2])

which is much, much easier to read.

Personally I'm a fan of https://github.com/stretchr/testify. Unlike some of the other "testing frameworks" it is still just using the standard go testing signatures.

vektah avatar Aug 04 '17 10:08 vektah

The example above is quite tempting to consider, it will cleanup lot of test code. But introduces additional dependency with packages with whom I don't have any line of sight. May be we can leave this issue open, if future contributors start up-voting we will consider refactoring the test code with testify.

Thanks,

prataprc avatar Aug 04 '17 16:08 prataprc