OS: Ubuntu 18.04.4 LTS (Bionic Beaver)
hie: Version 1.1, Git revision c584f9821cf348907305706faf8b945899409811 (3811 commits) x86_64 ghc-8.6.5
stack: Version 2.1.3, Git revision 636e3a759d51127df2b62f90772def126cdf6d1f (7735 commits) x86_64 hpack-0.31.2
IDE: VS Code
Could not load module ‘Test.Hspec’
It is a member of the hidden package ‘hspec-2.7.1’.
You can run ‘:set -package hspec’ to expose it.
(Note: this unloads all the modules in the current scope.)
Use -v to see a list of the files searched for.
Could not load module ‘Test.QuickCheck’
It is a member of the hidden package ‘QuickCheck-2.13.2’.
You can run ‘:set -package QuickCheck’ to expose it.
(Note: this unloads all the modules in the current scope.)
Use -v to see a list of the files searched for.
$ stack new my-projectstack.yaml's resolver to resolver: lts-14.0test/Spec.hs (from https://hspec.github.io/)import Test.Hspec
import Test.QuickCheck
import Control.Exception ( evaluate )
main :: IO ()
main = hspec $ do
describe "Prelude.head" $ do
it "returns the first element of a list" $ do
head [23 ..] `shouldBe` (23 :: Int)
it "returns the first element of an *arbitrary* list" $ property $ \x xs ->
head (x : xs) == (x :: Int)
it "throws an exception if used with an empty list" $ do
evaluate (head []) `shouldThrow` anyException
package.yaml tests:
my-project-test:
main: Spec.hs
source-dirs: test
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N
dependencies:
- my-project
+ - hspec
+ - QuickCheck
hie.yamlcradle:
stack:
- path: "./app/"
component: "my-project"
- path: "./src/"
component: "my-project"
- path: "./test/"
component: "my-project"
- path: "./Setup.hs"
component: "Cabal"
dependencies:
- package.yaml
@koowashi Hi! I think this is a manifestation of #1564: try to build the project with stack build --test --no-run-tests and reload the project to check if the error is gone.
I've just tested a similar configuration and it seems once that stack has built the project with stack build --test the module is loaded succesfully even after a stack clean.
stack needs to build the dependencies in the global cache (in the $(stack path --snapshot-install-root) directory) and the error only is reproduced for me if i delete taht dir.
stack build --test --no-run-tests succeeded, but VSCode errors are not gone.
stack test is done correctly.
$ stack test
my-project> test (suite: my-project-test)
Prelude.head
returns the first element of a list
returns the first element of an *arbitrary* list
+++ OK, passed 100 tests.
throws an exception if used with an empty list
Finished in 0.0015 seconds
3 examples, 0 failures
I suspect my hie.yaml is wrong.
If I change hie.yaml like below, HIE can load Test.Hspec (but not Test.QuickCheck).
- path: "./test/"
- component: "my-project"
+ component: "hspec"
Your component looks wrong.
use stack ide targets to find the components of your project. Should be something like `myproject:test:myproject-tests
hie.yaml
cradle:
stack:
- path: "./app/"
component: "my-project:exe:my-project-exe"
- path: "./src/"
component: "my-project:lib"
- path: "./test/"
component: "my-project:test:my-project-test"
- path: "./Setup.hs"
component: "Cabal"
the errors have gone!
Most helpful comment
hie.yaml cradle: stack: - path: "./app/" component: "my-project:exe:my-project-exe" - path: "./src/" component: "my-project:lib" - path: "./test/" component: "my-project:test:my-project-test" - path: "./Setup.hs" component: "Cabal"the errors have gone!