Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load tests in ghci with stack

I created a very simple project with stack. It contains: an executable, a library and test targets in the associated cabal file. When I load the code to ghci via stack ghci, I can't access test there, even if they are in separate module. Is there any way to use it in such a way?

like image 423
Konstantin Solomatov Avatar asked Oct 08 '16 22:10

Konstantin Solomatov


People also ask

What is stack Ghci?

stack ghci allows you to load components and files of your project into ghci . It uses the same TARGET syntax as stack build , and can also take options like --test , --bench , and --flag . Similarly to stack build , the default is to load up ghci with all libraries and executables in the project.

How do I know if stack is installed?

html -> click on system information-> login with admin rights -> you can get all details about the installed server.


1 Answers

Try stack ghci (your project name):(the test suite name). Then you should be able to enter main and your tests will run.

Example:

If your .cabal project file had the following values:

name: ExampleProject
...
test-suite Example-test

Then the command to run would be stack ghci ExampleProject:Example-test

(edit suggested by @Chris Stryczynski)

To watch the test and src directories so they are updated when you reload with :r, run:

stack ghci --ghci-options -isrc --ghci-options -itest ExampleProduct:Example-test
like image 98
Libby Avatar answered Oct 06 '22 06:10

Libby