Reputation: 2563
I am trying to structure my simple project in a way that it's easy for me to develop in the future. Basically I've used cabal init
to get the basic stuff, then I created a src folder, inside that i created a main folder and a test folder, the main is for holding all source code and the test is to put all 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. The Methods.hs is imported in Main.hs to get executed, and the Test.hs imports Methods.hs and tests the methods. My goal is to be able to do cabal --enable-tests configure
then cabal build
then cabal test
then cabal install
. But at the build stage I'm getting the error
src/test/Test.hs:2:8:
Could not find module `Methods`
Use -v to see a list of the files search for.
How do I let cabal know where Methods.hs is? Also, is there a better way to set the project up?
Upvotes: 4
Views: 2014
Reputation: 13876
Looks like you just need to add src/main
to hs-source-dirs
for test suit.
Also you can create a library with Methods
module and make both the executable and test suite depend on the library.
There are tons of examples on hackage, e.g. doctest It's test suit "spec" uses hs-source-dirs
and test suit "doctests" uses a library. The first approach allows to test interval functions, that are not exported by the library.
Upvotes: 3