Description
Problem
I have some tests using tasty-golden
+ ediffGolden
with data structures containing HashMap
values. These tests work locally, but fail on CI due to the CI server generating Expr
values for the HashMap
values with the items in a different order than was captured in the golden snapshot.
Analysis
ediffGolden
assumes (?) that a == b
implies toExpr a == toExpr b
.
However, the ToExpr
instance for HashMap
(source) captures the raw ordering returned by HM.toList
, which isn't reliable across platforms (or in the presence of collisions and insert reordering), so the above property doesn't hold.
(This also affects the ToExpr
instance of HashSet
.)
Workaround
I'm already using a Expr
construction in the affected code, so for the time being, I'm just using this variation of toExpr
for HashMap
sorts the items:
toExpr_HM :: (ToExpr k, ToExpr v, Ord k, Ord v) => HM.HashMap k v -> Expr
toExpr_HM x = App "HM.fromList" [ toExpr $ sort $ HM.toList x ]