How to configure a .cabal test package when the test file and the test file are in a different folder

I am trying to structure my simple project so that it is easy for me to develop in the future. Basically, I used cabal init to get the basic material, then created the src folder, inside which I created the main folder and the test folder, the main task is to save the entire source code, and the test is to put the entire test source code. Inside .cabal, I have the following:

 . . . . test-suit Test type: exitcode-stdio-1.0 hs-source-dirs: src/test main-is: Test.hs build-depends: base executable Finance hs-source-dirs: src/main main-is: Main.hs build-depends: base 

There are only three files Main.hs, Methods.hs, Test.hs. Methods.hs is imported into Main.hs for execution, and Test.hs imports Methods.hs and checks the methods. My goal is to do cabal --enable-tests configure , then cabal build , then cabal test , then cabal install . But at the build stage, I get an error

 src/test/Test.hs:2:8: Could not find module `Methods` Use -v to see a list of the files search for. 

How can I tell cabal where Methods.hs is located? Also, is there a better way to set up a project?

+4
source share
1 answer

It looks like you just need to add src/main to hs-source-dirs for the test suit.

You can also create a library with the Methods module and make both the executable and the test suite dependent on the library.

There are many examples for hacking, for example. doctest The spec test suit uses hs-source-dirs , and the doctests test suit uses the library. The first approach allows you to test interval functions that are not exported by the library.

+3
source

All Articles