Can I use the Haskell stack to compile and run _only_ tests?

When I run stack test or stack test <package>:<test-suite> , then the output looks something like this:

 package: configure (lib + exe + test) package: build (lib + exe + test) package: copy/register package: test (suite: tests) 

And it ends up basically compiling all my changes twice: once for exe or lib and second time for the test.

I would like a command like stack test --test-only create something like:

 package: configure (test) package: build (test) package: copy/register package: test (suite: tests) 

I already looked at the available command line flags and documentation on the stack. I also tried to find a google search to find out if anyone was talking about something like this.

So my questions are:
1. What is currently the best way to compile and run tests only? My best guess is to try passing tests in a separate swap package.
2. Is there any reason why the stack does not or cannot do this?

+6
source share
1 answer

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:

Use stack to compile and run tests only # 2710

+4
source

All Articles