ghc-mod icon indicating copy to clipboard operation
ghc-mod copied to clipboard

stack and test-suite

Open rikvdkleij opened this issue 9 years ago • 33 comments

Build project with stack. Test dependencies in test-suite (for example hspec) are not recognized by ghc-mod. If I put same dependencies in library section, ghc-mod does not complain anymore.

ghc-mod debug Warning: resolveModule "/home/rik/haskell/projects/quicksort/test/Spec.hs": could not execute: hspec-discover Root directory: /home/rik/haskell/projects/quicksort Current directory: /home/rik/haskell/projects/quicksort GHC Package flags: -hide-all-packages -no-user-package-db -package-db /home/rik/.stack/snapshots/x86_64-linux/lts-3.4/7.10.2/pkgdb/ -package-db /home/rik/haskell/projects/quicksort/.stack-work/install/x86_64-linux/lts-3.4/7.10.2/pkgdb/ -package-id QuickCheck-2.8.1-b8cde035baf86e10569b5c8f1da0c941 -package-id base-4.8.1.0-4f7206fd964c629946bb89db72c80011 -package-id hspec-2.1.10-d1430dd5c99e21ed2da59fe60fa379d9 GHC System libraries: /opt/ghc/7.10.2/lib/ghc-7.10.2 GHC user options:

Stack ghc executable: Just "/opt/ghc/7.10.2/bin/ghc" Stack ghc-pkg executable:Just "/opt/ghc/7.10.2/bin/ghc-pkg" Cabal file: Just "/home/rik/haskell/projects/quicksort/quicksort.cabal" Project: StackProject (StackEnv {seDistDir = ".stack-work/dist/x86_64-linux/Cabal-1.22.4.0", seBinPath = ["/home/rik/.stack/snapshots/x86_64-linux/lts-3.4/7.10.2/bin","/home/rik/bin","/usr/local/sbin","/usr/local/bin","/usr/sbin","/usr/bin","/sbin","/bin","/usr/games","/usr/local/games","/home/rik/bin","/home/rik/.local/bin/","/home/rik/.cabal/bin","/opt/ghc/7.10.2/bin","."], seSnapshotPkgDb = "/home/rik/.stack/snapshots/x86_64-linux/lts-3.4/7.10.2/pkgdb", seLocalPkgDb = "/home/rik/haskell/projects/quicksort/.stack-work/install/x86_64-linux/lts-3.4/7.10.2/pkgdb"}) Cabal entrypoints: Setup.hs Main (/home/rik/haskell/projects/quicksort/Setup.hs) library Quicksort (/home/rik/haskell/projects/quicksort/src/Quicksort.hs) test:spec Cabal components: Setup.hs Main (/home/rik/haskell/projects/quicksort/Setup.hs) library Quicksort (/home/rik/haskell/projects/quicksort/src/Quicksort.hs) test:spec GHC Cabal options: Setup.hs library -fbuilding-cabal-package -O -outputdir .stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build -odir .stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build -hidir .stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build -stubdir .stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build -i -i.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build -isrc -i.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/autogen -I.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/autogen -I.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build -optP-include -optP.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/autogen/cabal_macros.h -hide-all-packages -no-user-package-db -package-db /home/rik/.stack/snapshots/x86_64-linux/lts-3.4/7.10.2/pkgdb/ -package-db /home/rik/haskell/projects/quicksort/.stack-work/install/x86_64-linux/lts-3.4/7.10.2/pkgdb/ -package-id base-4.8.1.0-4f7206fd964c629946bb89db72c80011 -XHaskell2010 -Wall test:spec -fbuilding-cabal-package -O -outputdir .stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/spec/spec-tmp -odir .stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/spec/spec-tmp -hidir .stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/spec/spec-tmp -stubdir .stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/spec/spec-tmp -i -i.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/spec/spec-tmp -itest -isrc -i.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/autogen -I.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/autogen -I.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/spec/spec-tmp -optP-include -optP.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/autogen/cabal_macros.h -hide-all-packages -no-user-package-db -package-db /home/rik/.stack/snapshots/x86_64-linux/lts-3.4/7.10.2/pkgdb/ -package-db /home/rik/haskell/projects/quicksort/.stack-work/install/x86_64-linux/lts-3.4/7.10.2/pkgdb/ -package-id QuickCheck-2.8.1-b8cde035baf86e10569b5c8f1da0c941 -package-id base-4.8.1.0-4f7206fd964c629946bb89db72c80011 -package-id hspec-2.1.10-d1430dd5c99e21ed2da59fe60fa379d9 -XHaskell2010 -Wall -Werror GHC search path options: Setup.hs library -i -i.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build -isrc -i.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/autogen -I.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/autogen -I.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build -optP-include -optP.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/autogen/cabal_macros.h test:spec -i -i.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/spec/spec-tmp -itest -isrc -i.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/autogen -I.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/autogen -I.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/spec/spec-tmp -optP-include -optP.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/autogen/cabal_macros.h

rikvdkleij avatar Oct 03 '15 18:10 rikvdkleij

Hmm, I solved problem by removing the Setup.hs file. Do not understand why.....

rikvdkleij avatar Oct 03 '15 18:10 rikvdkleij

It's weird. It was working and suddenly not anymore.

rikvdkleij avatar Oct 03 '15 19:10 rikvdkleij

If you need more information let me know.

rikvdkleij avatar Oct 04 '15 19:10 rikvdkleij

Can you try running stack test before trying to run ghc-mod on any of your test modules. I think that should do the equivalent of cabal configure --enable-tests so cabal-helper can pick up the right dependencies from the Cabal setup-config. I'm not actually sure though since I haven't tested this and no-one has confirmed that this works so far.

DanielG avatar Oct 06 '15 17:10 DanielG

Oh stack test --only-configure should do the trick actually. Regrettably there isn't a way to get the state of the --enable/disable-{tests,benchmarks,..} flags out of LocalBuildInfo so every time ghc-mod decides to reconfigure the project you might have to re-run that.

DanielG avatar Oct 06 '15 17:10 DanielG

Sorry, I tried different combinations but I do not get it solved.

rikvdkleij avatar Oct 06 '15 19:10 rikvdkleij

Hmm, while check is complaining: test/QuicksortSpec.hs:4:18:Could not find module ‘Test.Hspec’Use -v to see a list of the files searched for. test/QuicksortSpec.hs:5:18:Could not find module ‘Test.QuickCheck’Use -v to see a list of the files searched for.

info and type are returning results for identifiers in test file.

rikvdkleij avatar Oct 06 '15 19:10 rikvdkleij

Have you configured to enable the tests? Else ghc-mod will not know about them, or their dependencies

alanz avatar Oct 06 '15 20:10 alanz

@dxld I am beginning to wonder if ghc-mod should not have a private dist directory where it configures with all targets enabled. Perhaps it is just a problem when using it from the API

alanz avatar Oct 06 '15 20:10 alanz

@alanz Which command do I have run to enable the tests? I'm using stack and not cabal. I already tried the ones which @DanielG had proposed.

rikvdkleij avatar Oct 06 '15 20:10 rikvdkleij

stack test is running without problems.

rikvdkleij avatar Oct 06 '15 20:10 rikvdkleij

I do not use stack much, but perhaps run stack test. Not sure if there is an option to configure only

On Tue, Oct 6, 2015 at 10:19 PM, Rik [email protected] wrote:

@alanz https://github.com/alanz Which command do I have run to enable the tests? I'm using stack and not cabal. I already tried the ones which @DanielG https://github.com/DanielG has proposed.

— Reply to this email directly or view it on GitHub https://github.com/kazu-yamamoto/ghc-mod/issues/640#issuecomment-145987462 .

alanz avatar Oct 06 '15 20:10 alanz

What happens if you run the ghc-mod check command after stack test?

alanz avatar Oct 06 '15 20:10 alanz

@alanz No difference

rikvdkleij avatar Oct 06 '15 20:10 rikvdkleij

Then I can't help

On Tue, Oct 6, 2015 at 10:30 PM, Rik [email protected] wrote:

@alanz https://github.com/alanz No difference

— Reply to this email directly or view it on GitHub https://github.com/kazu-yamamoto/ghc-mod/issues/640#issuecomment-145990856 .

alanz avatar Oct 06 '15 20:10 alanz

@alanz as well thanks for your help

rikvdkleij avatar Oct 06 '15 20:10 rikvdkleij

I'll have to give this a closer look at some point then, not sure what's going on.

DanielG avatar Oct 07 '15 10:10 DanielG

@DanielG Let me know if I can help you.

rikvdkleij avatar Oct 07 '15 18:10 rikvdkleij

I'm actually seeing a similar error with ghc-mod but I have no idea how to begin debugging this. Any tips welcome.

[filib@Philips-MacBook-Air:~/Projects/ruby-marshal on master]
% ghc-mod --version
ghc-mod version 5.4.0.0 compiled by GHC 7.10.2
[filib@Philips-MacBook-Air:~/Projects/ruby-marshal on master]
% ghc-mod debug
Warning: resolveModule "/Users/filib/Projects/ruby-marshal/test/Spec.hs":
         could not execute: hspec-discover

Project in question is here.

mcfilib avatar Oct 10 '15 15:10 mcfilib

I got rid of these errors by installing hspec-discover to my global binaries with stack install hspec-discover. It would of course be nice to not have to do that :)

kritzcreek avatar Oct 13 '15 02:10 kritzcreek

@kRITZCREEK Thanks! This also solved the problem with check in hspec test files.

rikvdkleij avatar Oct 13 '15 20:10 rikvdkleij

I have the same problem:

C:\Users\Ilya\Dropbox\__work\haskell-stuff\proj>ghc-mod check test\DiffSpec.hs
Warning: resolveModule "C:\\Users\\Ilya\\Dropbox\\__work\\haskell-stuff\\proj\\test\\Spec.hs":
         could not execute: hspec-discover
test\DiffSpec.hs:4:8:Could not find module `Test.Hspec' It is a member of the hidden package `hspec-2.1.10@hspec_2PJYWWWFDLKJMqtKrTPx5f'. Perhaps you need to add `hspec' to the build-depends in your .cabal file. Use -v to see a list of the files searched for.
test\DiffSpec.hs:5:8:Could not find module `Test.Hspec.QuickCheck' It is a member of the hidden package `hspec-2.1.10@hspec_2PJYWWWFDLKJMqtKrTPx5f'. Perhaps you need to add `hspec' to the build-depends in your .cabal file. Use -v to see a list of the files searched for.
test\DiffSpec.hs:6:8:Could not find module `Test.QuickCheck.Arbitrary' It is a member of the hidden package `QuickCheck-2.8.1@Quick_Hhirlp4kTrmA8XNTfrDStQ'. Perhaps you need to add `QuickCheck' to the build-depends in your .cabal file. Use -v to see a list of the files searched for.
test\DiffSpec.hs:7:8:Could not find module `Test.QuickCheck.Gen' It is a member of the hidden package `QuickCheck-2.8.1@Quick_Hhirlp4kTrmA8XNTfrDStQ'. Perhaps you need to add `QuickCheck' to the build-depends in your .cabal file. Use -v to see a list of the files searched for.

stack test works, but makes no difference to the subsequent behavior of ghc-mod.

Doing stack install hspec-discover fixes the first warning (the first two lines of output are no longer there), but not the others.

ilyagr avatar Dec 26 '15 19:12 ilyagr

Steps to reproduce from scratch:

stack new qq franklinchen --resolver=lts-3
cd qq
stack install ghc-mod cabal-helper hspec-discover
stack test                     # Works fine
ghc-mod check src\Lib.hs       # Works fine, would give a warning if hspec-discover wasn't installed
ghc-mod check test\LibSpec.hs   # Fails
stack exec ghc-mod -- check test\LibSpec.hs  # Also fails

ilyagr avatar Dec 26 '15 20:12 ilyagr

We're having the same problem as @ilyagr above.

An interesting thing we've discovered that this only seems to be an issue when multiple .hs files are involved. For example, if you modify @ilyagr's sample project above and change the qq.cabal file modifying main-is for the test-suite to LibSpec.hs, ghc-mod check test\LibSpec.hs will work okay.

I've also seen some weirdness that I can't reliably reproduce where doing the above to get ghc-mod to work, and then reverting the changes, then trying ghc-mod again results in ghc-mod still working.

The issue doesn't seem to be related to the use of hspec-discover in Spec.hs, because if you modify Spec.hs to to remove hspec-discover (as below), the issue still exists.

module Spec where

import Test.Hspec
import LibSpec

main :: IO ()
main = hspec spec

daniel-chambers avatar Jan 05 '16 02:01 daniel-chambers

I experience the same issue. I have no clue what's really happening, but I suspect the issue with $PATH. Stack modifies it, so GHC can find hspec-discover.

rasendubi avatar May 11 '16 18:05 rasendubi

We've since discovered that we can make this problem go away by listing all the non-exposed modules in the test project (ie almost all of them) in the other-modules section in the cabal file. We didn't need to to get it to compile and run, but since we started doing it, we haven't had this problem with ghc-mod any more.

daniel-chambers avatar May 12 '16 11:05 daniel-chambers

I already have all my test modules in the other-modules section but I do experience the issue. Seems that you've changed something along adding your modules to the section.

rasendubi avatar May 12 '16 13:05 rasendubi

No, that was the only thing that changed for us. But it worked sometimes even before that, so there might be something else in play causing the issue for you. Sorry our workaround didn't work for you :(

daniel-chambers avatar May 12 '16 13:05 daniel-chambers

Don't worry, I've found my own one ;) Just installed hspec-discover globally.

rasendubi avatar May 12 '16 13:05 rasendubi

fwiw I am now getting this issue using cabal new-build --enable-tests on the ghc-mod repo itself.

cocreature avatar May 19 '16 16:05 cocreature

Ghc-mod should launch GHC with PATH set to the value of stack path --bin-path. If someone can point me in the right direction I'll take a crack at a PR.

enolan avatar May 29 '16 20:05 enolan

@enolan that does sound like a reasonable thing to do. I think this would have to go somewhere in runGmlTWith. But the code dealing with Stack is somewhere deep in targetGhcOptions/cabalResolvedComponents/getComponents/chCached/withCabal so doing this nicely might be tricky.

DanielG avatar Jul 17 '16 23:07 DanielG

Hi, are there any updates on this issue?

Currently experiencing this with QuickCheck. I can make ghc-mod happy if I place QuickCheck in library dependencies, but if I keep it in the test section only, I get the 'could not find module QuickCheck'

1gmar avatar Aug 05 '18 15:08 1gmar