3

I have problems setting up unit-tests with Test-Framework and HUnit.
I have the following imports in my testfile:

import Test.Framework
import Test.Framework.Providers.QuickCheck2
import Test.Framework.Providers.HUnit

When I try to load the file in ghci I get the error-message:

test/MainTestSuite.hs:3:8:
    Could not find module ‘Test.Framework.Providers.HUnit’
    Perhaps you meant
      Test.Framework.Providers.API (from test-framework-0.8.1.1)
    Use -v to see a list of the files searched for.
Failed, modules loaded: none.

Only loading Test.Framework and Test.Framework.Providers.QuickCheck2 works and can run the tests. According to cabal test-framework-hunit is installed:

$ cabal install test-framework-hunit
Resolving dependencies...
All the requested packages are already installed:
test-framework-hunit-0.3.0.1
Use --reinstall if you want to reinstall anyway.
Notice: installing into a sandbox located at
/home/XXX/projects/my_project/.cabal-sandbox

Also test-framework-hunit is listed as a dependency in the my_project.cabal-file:

test-suite tests
    main-is:           
        MainTestSuite.hs
    type:              
    exitcode-stdio-1.0
    hs-source-dirs:    
        test, 
        src
    build-depends:     
        base,
        HUnit,
        QuickCheck,
        test-framework,
        test-framework-hunit,
        test-framework-quickcheck2,
        containers >=0.5 && <0.6
    default-language:
        Haskell2010

What am I doing wrong? If that matters: I'm installing everything into a cabal-sandbox.

jules
  • 1,897
  • 2
  • 16
  • 19
  • 1
    How are you running `ghci`? Did you pass it the [`-package-db` flag](http://stackoverflow.com/a/24840899/414413) to tell `ghci` where to find the sandbox installed packages? – Cirdec Mar 29 '15 at 16:03
  • No this was the problem ... i wasn't aware that ghci is not aware of sandboxes by default. – jules Mar 29 '15 at 17:58

1 Answers1

0

Sandboxed packages are visible to cabal but not to ghc or ghci without additional flags. But you can alter your environment in general for a process by executing it with cabal exec myCmd -- and even better, for ghci in particular, cabal repl is a more full-featured solution that opens "stuff you want" in a variety of situations, both with and without sandboxes.

sclv
  • 38,665
  • 7
  • 99
  • 204