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

Value diffs #154

Open TysonMN opened 3 years ago

TysonMN commented 3 years ago

This talk about Haskell's Hedgehog (only need to watch from that starting point for 30 seconds) mentions "value diffs". When some equality expression is false, instead of printing both sides separately, they are printed together except with diff notation to highlight the difference. Here is a screenshot from that talk.

2020-07-15_08-25-49_179

I asked about if F# Hedgehog has this feature in https://github.com/hedgehogqa/fsharp-hedgehog/issues/211, and it does not.

Does it make sense for Unquote to consider a feature like value diffs?

akhansari commented 3 years ago

This feature would be a real time and life saver 🙏 🙏

Currently at each failure we need to copy/past the two part and compare them in a diff tool.\ It's very painful!

stephen-swensen commented 3 years ago

I agree something like this would be a nice addition to Unquote. I often run into the same issue, namely with equality comparison between two record types that contain many properties. I wonder if a first iteration that might go a long way would be to have a second reduction step after {record1 of type 'T} = {record2 of type 'T}) like {properties of record1 that aren't equal to corresponding record2 properties} = {properties of record2 that aren't equal to corresponding record1 properties}) e.g.

given

let x = { A=1; B=2; C=3; D=4 }
let y = { A=2; B=2; C=3; D=3 }

test <@ x = y @>

instead of failure output like

x = y
{ A=1; B=2; C=3; D=4 } = { A=2; B=2; C=3; D=3 }
false

we could have something like

x = y
{ A=1; B=2; C=3; D=4 } = { A=2; B=2; C=3; D=3 }
{ A=1; D=4; ... } = { A=2; D=3; ... }
false
natalie-o-perret commented 3 years ago

Guess starting from there and trying to see where the exact differences can be represented.

Wondering if the issue is all about making a copycat of this particular Hedgehog feature (ie. colours and whatnot?) or nawt.

baronfel commented 3 years ago

Expecto went through this and eventually added an integration with DiffSharp, outsourcing the creation of the diff: https://github.com/haf/expecto/blob/master/Expecto.Diff/Library.fs

natalie-o-perret commented 3 years ago

Expecto went through this and eventually added an integration with DiffSharp, outsourcing the creation of the diff: https://github.com/haf/expecto/blob/master/Expecto.Diff/Library.fs

Thanks, might worth looking at their impl.

stephen-swensen commented 6 months ago

Someone (Urz Enzler) using Diffract to augment Unquote output (it's limited to quality expressions and coded specifically for Xunit assertions): https://www.planetgeek.ch/2023/02/20/todays-random-f-code-nice-test-error-messages-with-unquote-and-diffract/