Skip to content

ediffGolden fails with ToExpr instances that don't preserve Eq, such as HashMap #67

Closed
@PiDelport

Description

@PiDelport

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 ]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions