I did some experiments using stack build <pkgname>:test:<testsuite> and didn't find anything really nice when you have all your / src / main application in one directory cabal-project.
Now I have not investigated whether this is a problem due to a stack using Cabal as a library, or is it a stack problem.
here are some issues that may be related
But I think you will have to write down the error if no one gives a better answer.
Perhaps, but a rather ugly solution (in my opinion) is to separate the test package, application and library into separate Kabbalah projects - this is an example of the folder structure that I used for testing.
myproject ├── stackapp │ ├── app │ │ └── Main.hs │ ├── ChangeLog.md │ ├── LICENSE │ ├── Setup.hs │ └── stackapp.cabal ├── stacksrc │ ├── ChangeLog.md │ ├── LICENSE │ ├── Setup.hs │ ├── src │ │ └── Lib.hs │ └── stacksrc.cabal ├── stacktest │ ├── ChangeLog.md │ ├── LICENSE │ ├── Setup.hs │ ├── src │ ├── stacktest.cabal │ └── tst │ └── Spec.hs └── stack.yaml
stack.yaml
resolver: lts-7.3 packages: - './stacksrc' - './stacktest' - './stackapp' extra-deps: [] flags: {} extra-package-dbs: []
Note that you need to include the "dummy" library section so that it compiles. Cabal is picky about cabal files that have neither lib nor exe.
stacktest.cabal
... library -- dummy build-depends: base >=4.9 && <4.10 hs-source-dirs: src default-language: Haskell2010 test-suite tests type: exitcode-stdio-1.0 main-is: Spec.hs hs-source-dirs: tst build-depends: base , stacksrc , hspec , hspec-expectations-pretty-diff default-language: Haskell2010
You can then modify the tests and run stack stacktests:test:tests without reinstalling the lib and / or part of the application, but the stacks are smart enough to rebuild the lib part if you change it before running the tests.
UPDATE
In the future, here is a link to an open ticket:
source share