cdsmith / HMock

Mock framework for testing in Haskell
BSD 3-Clause "New" or "Revised" License
23 stars 4 forks source link

Mocking polymorphic return values with a Typeable constraint #2

Closed cdsmith closed 3 years ago

cdsmith commented 3 years ago

Migrated from TODO file.

This doesn't work.

class MonadFoo m where
    foo :: forall a. Typeable a => a -> m a

makeMockable ''MonadFoo

foo is considered unmockable, because matching the method is no longer enough to prove equality of the return types, so we cannot be sure that the response has the right type for the actual call. But there is a Typeable constraint, so we should be able to check this at runtime instead! That is, one should be able to write something like:

expectAny $ Foo_ (typed @Bool anything) |-> True

Unifying the return types requires a cast in the generated matchAction, but we should have the constraints that we would need to implement this.