Reputation: 1693
I have a Haskell project that is built using Stack (therefore Cabal). Right now I have src/ directory and tests/ directory, however I would like to mix tests together with the source files, which means everything would go to src/ directory.
For that, I would need to define my tests
build-info source files to be files in src/ that have .test.hs extension.
However, it seems that only choice for defining source files is source-dirs
in stack or hs-source-dirs
in cabal, meaning that I have to put src
as source-dirs
, which seems wrong because it is also capturing the normal source files then.
This is what part of my package.yaml:
tests:
myapp-test:
main: Main.hs
source-dirs: test
...
While I would like it to be smth like:
tests:
myapp-test:
main: Main.hs
source-files: src/**/*.test.hs
...
Is there any option like that, like source-files, or any other way to do this? Thanks!
Upvotes: 3
Views: 1927
Reputation: 3501
Separate src
and tests
dir is convention, but not a must.
hs-source-dirs
defaults to .
.
Cabal finds all source files by itself.
Otherwise there is extra-source-files
.
Your choice is on the module level: exposed-modules
, other-modules
.
You can use them for libraries and executables.
In your .cabal
file:
executable <name>
entry per executable.
main-is
is the file with module Main where ...
.library <name>
per library.Use one test-suite <name>
entry per test app.
type
is required (e.g. type: exitcode-stdio-1.0
).main-is
is the test file.ghc-options: -main-is <your.hs>
main :: IO ()
main = hspec spec -- or: spec1 >> spec2
Cabal usage:
cabal new-build
cabal new-test [<which test>]
cabal new-run <file without path>
Deep in dist-newstyle
you will find
x
directoryt
directory.so
files under a l
directoryLinks:
*.cabal
, cabal/Cabal/doc/buildinfo-fields-reference.rst
Upvotes: 1