I am looking for help on how to write tests for Haskell code that are defined in the main module.
The project I want to test is a package in which I defined several executables. Each executable code is declared from only one file (one for each project Euler problem), and I usually run them separately using the cabal run command.
I tried to write a test, also in the main module, but when compiling, the function that I am trying to test was not found ("Out of scope" error).
What is the correct way to write tests in this case?
For information, below is the layout of my project directory:
pe/
The following is an excerpt from pe.cabal:
test-suite test-all hs-source-dirs: test type: exitcode-stdio-1.0 main-is: TestProblem001.hs build-depends: base, HUnit, Cabal >= 1.9.2 executable problem-001 hs-source-dirs: src main-is: Problem001.hs build-depends: base ghc-options: -Wall -Werror -O2
[edit]
Since I could not find any resource for this exact requirement, I chose a project architecture that is easier to test: problems are more defined as a library, rather than individual executables.
haskell testing cabal
killy971
source share