I guess this PR is a little bikesheddy, but I've been wanting to perform these changes for a while now, and every now and then I come across these issues. Changes:
Ensure that all calls to assert_equal get the optional printer argument, so that when there is a failure we can actually see what went wrong. Exception to this rule is the call to assert_equal in test_all_permutations, because it's very tight and it timeouts if we do.
Instead of replicating the assert_equal ~printer:(...) ~cmp:(...) expected real pattern, define separate functions per type, like this:
let assert_ratio_equal ~expected ~real = OUnit2.assert_equal ~printer:Ratio.show_ratio ~cmp:Ratio.eq_ratio_ratio expected real
This has several advantages:
The code is shorter (this PR takes ~100 LOC away)
The order of real and expected cannot be gotten wrong (we had several instances where the arguments were flipped, giving misleading errors).
The use of the default (=) is avoided. If we don't pass the cmp parameter explicitly, (=) is implicitly used, which is wrong for several of our types, such as bigmaps, ratios, and every type that includes them. In fact, there are a few cases in the codebase were (=) is still used while it shouldn't, but I'll fix that in a separate PR.
I guess this PR is a little bikesheddy, but I've been wanting to perform these changes for a while now, and every now and then I come across these issues. Changes:
assert_equal
get the optionalprinter
argument, so that when there is a failure we can actually see what went wrong. Exception to this rule is the call toassert_equal
intest_all_permutations
, because it's very tight and it timeouts if we do.assert_equal ~printer:(...) ~cmp:(...) expected real
pattern, define separate functions per type, like this:This has several advantages:
real
andexpected
cannot be gotten wrong (we had several instances where the arguments were flipped, giving misleading errors).(=)
is avoided. If we don't pass thecmp
parameter explicitly,(=)
is implicitly used, which is wrong for several of our types, such as bigmaps, ratios, and every type that includes them. In fact, there are a few cases in the codebase were(=)
is still used while it shouldn't, but I'll fix that in a separate PR.