SwensenSoftware / unquote

Write F# unit test assertions as quoted expressions, get step-by-step failure messages for free
http://www.swensensoftware.com/unquote
Apache License 2.0
285 stars 26 forks source link

Implement `testSimple` assertion operator that only outputs head expression #148

Closed stephen-swensen closed 5 years ago

stephen-swensen commented 5 years ago

The output from test can be verbose and distracting, especially when it includes large object graphs. Provide a "simple" assertion operator (call it testSimple) that provides a less noisy alternative. The behavior of test should not be changed, because it is generally useful.

See discussion in https://github.com/SwensenSoftware/unquote/pull/134

Depends on https://github.com/SwensenSoftware/unquote/issues/133 - decompiling and reducing ValueWithName expressions - to be effective

Given a test setup and assertion like the following

type Foo = { Foo : string ; Bar : int }
let x = { Foo = "foo" ; Bar = 41 }
testSimple <@ x.Bar = 42 @>

Produce output like the following:

Option A (just output the head expression)

Test failed:

x.Bar = 42

Option B (just output the head and last expression; skip intermediate reductions)

Test failed:

x.Bar = 42
41 = 42
false
stephen-swensen commented 5 years ago

@eiriktsarpalis any preference on Option A vs. Option B? I'm partial to Option B because to me it appears to provide the two most important pieces of information given by the regular test operator but without the noise of the intermediate reduction steps: the source assertion expression and the final reduction (well, the final two reduction - the second to last one is the interesting one here; we'd preserve false just for closer symmetry to test). I suppose the appeal of Option A would be just to have a truly stripped down, source assertion only decompilation.

eiriktsarpalis commented 5 years ago

The main issue with B seems to be that it can blow up in certain cases, e.g. performing structural equality checks on large values. Just emitting the initial tree should provide sufficient context to the test author for establishing what went wrong.

stephen-swensen commented 5 years ago

@eiriktsarpalis that's fair - Option A it is. Thinking about it more, anyone who'd be more interested in Option B would probably just go with the usual test in the first place.

stephen-swensen commented 5 years ago

https://github.com/SwensenSoftware/unquote/pull/146/commits/d6712d096337446f39773b339ccdf96588e03f1d

stephen-swensen commented 5 years ago

@eiriktsarpalis FYI - this is released as part of Unquote 5.0.0 today!