Skip to content

[#233] Put testing library code into its own package

Diogo Castro requested to merge diogo/#233-test-package into master

Description

Problem

We currently have test-related modules scattered across multiple packages:

  • Michelson.Test and Michelson.Doc.Test in morley
  • Lorentz.Test in lorentz
  • morley-nettest
  • Hegdehog generators defined in multiple modules in morley and lorentz

We should move them to one single package, cleveland.

Solution

The overall strategy was this:

  1. Since the morley-nettest only contains test-related stuff, we could move everything here, and then
  2. Rename this package to cleveland.

However, this would lead to 3 cyclic dependencies at the package-level that had to be resolved first in order to make this strategy feasible. These were discussed in detail here, but here's a summary:

  1. There would be a cyclic dependency between morley and cleveland:
    • morley:test:morley-test/bench would depend on cleveland:lib, and cleveland:lib on morley:lib.
    • We solved this by moving morley-test/bench to the cleveland package
  2. There would be a cyclic dependency between lorentz and cleveland:
    • lorentz:test:lorentz-test would depend on cleveland:lib, and cleveland:lib on lorentz:lib.
    • We solved this by moving lorentz-test to the cleveland package
  3. There would be a cyclic dependency between indigo and cleveland:
    • indigo:test:indigo-test would depend on cleveland:lib (source) and cleveland:test:nettest on indigo:lib (source)
    • We solved this by rewriting the ContractAllocator test to use lorentz instead of indigo.

Outstanding issues

~Because I moved genMText out of Michelson.Text, I also had to export minBoundMChar and maxBoundMChar to make them accessible to Hedgehog.Gen.Michelson. These were previously internal, and I'm personally not very fond of having these in the public interface. I see these possible solutions:

  1. Do not reuse min/maxBoundMChar, and simply duplicate them in Hedgehog.Gen.Michelson
  2. Replace min/maxBoundMChar with a bounded newtype and accompanying functions, and expose these instead. E.g.:
    newtype MChar = MChar Char
    instance Bounded MChar where ...
    instance Enum MChar where ...
    mkMChar :: Char -> Either String MChar
    mkMTextFromMChars :: [MChar] -> Either String MText
  3. Leave min/maxBoundMChar in the public interface, not a big deal.~

Package dependency graph

The package dependency graph now looks like this (excluding morley-prelude and tasty-hunit-compat for simplicity): package dependency graph

(Generated using stack dot --test --bench --prune "morley-prelude,tasty-hunit-compat" | dot -T png -o a.png)

Related issue(s)

Resolves #233 (closed)

Checklist for your Merge Request

Related changes (conditional)

  • Tests (see short guidelines)

    • If I added new functionality, I added tests covering it.
    • If I fixed a bug, I added a regression test to prevent the bug from silently reappearing again.
  • Documentation

    • I checked whether I should update the docs and did so if necessary:
    • I updated changelog files of all affected packages released to Hackage if my changes are externally visible.

Stylistic guide (mandatory)

Edited by Diogo Castro

Merge request reports