goparsec
goparsec copied to clipboard
Thoughts on an assertion library?
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.
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,