vendredi 6 juillet 2018

How should I go about testing a monolithic executable package?

I have a monolithic executable package with several modules. (What I mean by "monolithic" is that it only has one clause in its cabal file, and that is executable.) It is currently tested with shell scripts, in a black box manner. I thought I would like to write unit tests for some individual functions, but cabal does not agree:

% cabal new-test
cabal: Cannot test the package x-0.0.0.0 because none of the
components are available to build: the test suite 'x-test' is not
available because the solver did not find a plan that included the test suites

Here are the relevant sections of package.cabal:

executable x
  ...
  other-modules: ...
  ...

test-suite x-test
    type: exitcode-stdio-1.0
    main-is: Test.hs
    build-depends: base, x
    hs-source-dirs: test

My understanding is that I should move as many modules as possible to an internal library, which would make it possible for the test suite to depend on them. However, I am not sure the maintainers will approve of such radical change. Is there a less invasive way?

My other concern is that at least one module (Main.hs) will have to remain unexposed to the test suite. How should I go about testing it, beside shell scripts?

Aucun commentaire:

Enregistrer un commentaire