Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
PiDelport opened this issue Jan 10, 2023 · 0 comments

Comments

@PiDelport
Copy link

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 ]
phadej added a commit that referenced this issue Jan 10, 2023
phadej added a commit that referenced this issue Jan 10, 2023
@phadej phadej closed this as completed in 53ec7f5 Jan 28, 2023
phadej added a commit that referenced this issue Jan 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant