Announcing HMock 0.2

Rejecting ambiguous expectations

First, HMock can now reject ambiguous expectations. Suppose had a mock filesystem monad with HMock, and you wrote something like this:

expect $ ReadFile_ anything |-> "some content"
expect $ ReadFile "foo.txt" |-> "foo content"
x <- readFile "foo.txt"

MockSetup monad

Second, I’ve moved setup to a new restricted monad called MockSetup to fix a race condition.

  • Perform arbitrary I/O.
  • Add expectations.

Nesting MockT

Third, I’ve added a new operation called nestMockT, which lets you create a nested semi-independent block within a mock test. This block:

  • Has its own options, such as defaults and ambiguity checking, which are originally the same as the parent. Changing them takes effect in the nested block, but the changes are reverted as soon as the nested block completes.
  • Has its own expectations. The expectations of the nested block may be interleaved with the expectations of its parent, but when the block finishes, its own expectations must be satisfied.

Module Structure

The original HMock release shoved most things into only a couple modules: Test.HMock and Test.HMock.TH. This was too much. I’ve now reorganized the implementation, split up behemoth modules, and divided everything into what I think are logical units. You can import just the parts you need, or import Test.HMock to get almost everything.

HMock 0.2 module structure

Caution! Unstable API

I still have not adapted HMock to work with effect systems or other frameworks, as I want to do eventually. Because of this, the API should still be considered unstable. You’ll be fine if you add upper bounds on your dependency versions a la the PVP; but if not, your code might break with future updates. You’ve been warned!

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Chris Smith

Chris Smith

Software engineer, volunteer K-12 math and computer science teacher, author of the CodeWorld platform, amateur ring theorist, and Haskell enthusiast.