typelevel / typelevel/cats

Built-in test suites for typeclass instances

Open
#168 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

meta testing
Dominant language
Scala
Stars
5.5k
Forks
1.2k
Avg merge
2d 10h
Merged PRs (30d)
5

Description

In #160 I almost suggested a test that lmap f is consistent with dimap f idenity and that rmap g is consistent with dimap identity g but I realized that would just be testing against the default implementations.

I think it could be handy to easily be able to test that all methods for an instance are consistent with the default implementation. For example if you override foldMap in your Foldable instance for performance reasons, you want to make sure that your implementation is consistent with the default.

There are some other tests unrelated to default implementations that could be handy. For example, we may want to test that Foldable.exists (which I don't believe actually currently...exists) is lazy.

I don't think these things really qualify as laws, but we probably want to make sure they hold for all Cats implementations, and other people may want to use them for their custom structures.

This would probably lead to quite a bit of boilerplate somewhere inside cats that would probably be difficult to keep up to date, but I think it could pay for itself in bug prevention.

If people are interested, I could put together a code example of one possible approach to this sort of thing. Let me know what you think.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing issue #160 and the existing Cats typeclass default implementations. The issue does not name files, tests, or an entry point, so first determine where shared instance tests could live and which consistency and laziness checks are in scope. Done means a defined, maintainable approach that can be applied to Cats implementations and custom structures.

Written by the indexing model from the issue text.

Assessment

Tech stack
scala
Domain
testing
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.