DanielG / ghc-mod

Happy Haskell Hacking for editors. DEPRECATED
Other
677 stars 175 forks source link

stack and test-suite #640

Open rikvdkleij opened 9 years ago

rikvdkleij commented 9 years ago

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 commented 9 years ago

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

rikvdkleij commented 9 years ago

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

rikvdkleij commented 9 years ago

If you need more information let me know.

DanielG commented 9 years ago

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 commented 9 years ago

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.

rikvdkleij commented 9 years ago

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

rikvdkleij commented 9 years ago

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.

alanz commented 9 years ago

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

alanz commented 9 years ago

@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

rikvdkleij commented 9 years ago

@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 commented 9 years ago

stack test is running without problems.

alanz commented 9 years ago

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 notifications@github.com 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 commented 9 years ago

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

rikvdkleij commented 9 years ago

@alanz No difference

alanz commented 9 years ago

Then I can't help

On Tue, Oct 6, 2015 at 10:30 PM, Rik notifications@github.com 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 .

rikvdkleij commented 9 years ago

@alanz as well thanks for your help

DanielG commented 9 years ago

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

rikvdkleij commented 9 years ago

@DanielG Let me know if I can help you.

mcfilib commented 9 years ago

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.

kritzcreek commented 9 years ago

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 :)

rikvdkleij commented 9 years ago

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

ilyagr commented 8 years ago

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 commented 8 years ago

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
daniel-chambers commented 8 years ago

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
rasendubi commented 8 years ago

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.

daniel-chambers commented 8 years ago

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.

rasendubi commented 8 years ago

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.

daniel-chambers commented 8 years ago

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 :(

rasendubi commented 8 years ago

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

cocreature commented 8 years ago

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

enolan commented 8 years ago

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.

DanielG commented 8 years ago

@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.

1gmar commented 6 years ago

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'