Skip to main content

HMock Compatibility

As I mentioned in a previous blog entry, I am excited to use the new HMock library but am concerned about compatibility. I investigated the compatibility further this afternoon.

GHC 8.2 and 8.4

I initially figured that HMock supports GHC versions 8.4 and higher because of the base version constraints (>=4.11.0) as well as a recent commit titled “Revert ‘Drop GHC 8.4 support’”.

I confirmed that it does not work with GHC 8.2, but I also found that it does not work with GHC 8.4 due to the constraints of the explainable-predicates dependency. I unsuccessfully tried to get explainable-predicates to work with GHC 8.4 (but I did not put too much time into it, so do not let me discourage you from trying).

GHC 8.6

Moving onto GHC 8.6, I was unable to get it to work with Stack. I was able to construct a build plan using the following configuration:

resolver: lts-14.27

packages:
  - .

extra-deps:
  - binary-0.8.6.0
  - constraints-0.13
  - containers-0.6.5.1
  - explainable-predicates-0.1.2.0
  - extra-1.7.10
  - HMock-0.5.0.0
  - regex-base-0.94.0.1
  - regex-tdfa-1.3.1.1
  - syb-0.7.2.1
  - text-1.2.3.1
  - type-equality-1
  - unliftio-0.2.20

Unfortunately, the build of HMock fails with the following error:

/tmp/stack-b8726112c6310f6a/HMock-0.5.0.0/src/Test/HMock/Internal/State.hs:202:7: error:
    • Couldn't match type ‘MockT m’ with ‘ReaderT (MockState m) m’
        arising from the coercion of the method ‘unliftio-core-0.1.2.0:Control.Monad.IO.Unlift.askUnliftIO’
          from type ‘ReaderT
                       (MockState m)
                       m
                       (unliftio-core-0.1.2.0:Control.Monad.IO.Unlift.UnliftIO
                          (ReaderT (MockState m) m))’
            to type ‘MockT
                       m
                       (unliftio-core-0.1.2.0:Control.Monad.IO.Unlift.UnliftIO (MockT m))’
    • When deriving the instance for (MonadUnliftIO (MockT m))
    |
202 |       MonadUnliftIO
    |       ^^^^^^^^^^^^^

I submitted a pull request to fix some documentation earlier, and the CI test for GHC 8.6.5 ran successfully, so I tried using the package versions from the successful test. Unfortunately, I was unable to construct a build plan with newer packages due to dependency cycle errors.

GHC 8.8

Moving onto GHC 8.8, I was unable to construct a build plan using the following configuration but got the same coercion error.

resolver: lts-16.31

packages:
  - .

extra-deps:
  - constraints-0.13
  - explainable-predicates-0.1.2.0
  - HMock-0.5.0.0
  - syb-0.7.2.1
  - unliftio-0.2.20

GHC 8.10

With GHC 8.10, HMock builds without issue and the tests for my project pass. I used the following Stack configuration:

resolver: lts-18.12

packages:
  - .

extra-deps:
  - explainable-predicates-0.1.2.0
  - HMock-0.5.0.0

GHC 9.0

With GHC 9.0, HMock builds without issue and the tests for my project pass. I used the following Stack configuration:

resolver: nightly-2021-09-30

packages:
  - .

extra-deps:
  - explainable-predicates-0.1.2.0
  - HMock-0.5.0.0

Overview

My current goal is to support five years of the Haskell ecosystem in open source projects. The following table is an overview of the versions involved:

GHC Version base Version cabal-install Version Release Date Years Ago
8.0 4.9 1.24 2016-05-21 5.36
8.2 4.10 1.24 2017-07-22 4.19
8.4 4.11 2.2 2018-03-08 3.57
8.6 4.12 2.4 2018-09-21 3.03
8.8 4.13 3.0 2019-08-25 2.10
8.10 4.14 3.2 2020-03-24 1.52
9.0 4.15 3.4 2021-02-04 0.65

When using Cabal, HMock supports GHC 8.6 and later: three years. When using Stack, I was only able to get it to work with GHC 8.10 and later: one and a half years. These are both uncomfortably short for me. This is unfortunate because I really like HMock and want to use it!

One idea that I am considering is to write tests so that HMock is only used when a supported version of GHC is used. When running tests with an unsupported version of GHC, it would simply not run the HMock tests. This will likely involve both Cabal conditionals and CPP macros. I will likely give it a try.