Can't find module Test.HUnit
Asked Answered
M

1

6

I am trying to make some unit tests in Haskell and this is basically what I have done in my code:

module Test where
import Test.HUnit
test = TestList [TestLabel "running all the tests!"
$ TestList [
. . . . .
]]  

run = runTestTT tests   

When I try to compile it with the gchi I get this message:

 Could not find module ‘Test.HUnit’
Use -v to see a list of the files searched for.
Failed, modules loaded: none

How can I make HUnit work?

I am using GHCi version 7.8.3

Thanks

Edit:

I tried installing HUnit through cabal as an answer suggested but then I got the error:

Could not find module ‘Test.HUnit’ Perhaps you haven't installed the "dyn" libraries for 
package ‘HUnit-1.2.5.2’? 
Use -v to see a list of the files searched for.

Then I used the command:

cabal install base

and I got this message:

Resolving dependencies...
All the requested packages are already installed:
base-4.7.0.1
Use --reinstall if you want to reinstall anyway.

So I used the command:

cabal install base -reinstall

to reinstall just in case and I got the message:

Resolving dependencies...
cabal: Could not resolve dependencies:
rejecting: base-4.7.0.1, 4.7.0.0, 4.6.0.1, 4.6.0.0, 4.5.1.0, 4.5.0.0, 4.4.1.0,
4.4.0.0, 4.3.1.0, 4.3.0.0, 4.2.0.2, 4.2.0.1, 4.2.0.0, 4.1.0.0, 4.0.0.0 (only
already installed instances can be used)
rejecting: base-3.0.3.2 (conflict: base => base>=4.0 && <4.3)
rejecting: base-3.0.3.1 (conflict: base => base>=4.0 && <4.2)

What should I do?

Morrell answered 1/11, 2014 at 11:45 Comment(23)
Well, have you installed HUnit yet?Hottentot
I have to install it? I thought if i had ghc installed I would have it tooMorrell
How can I install it? I just found that I somehow need to use cabal to install some dependencies but they don't explain how to do itMorrell
Haskell is just like any other language - it has libraries and you need to install those libraries to use their functionality..Brawley
Normally cabal install HUnit works but you seem to be having some trouble I'm not sure how to resolve. You might get more mileage from installing ghc via installing the Haskell Platform which includes a good consistent set of packages to get you going. There's a binary distribution for Ubuntu 12 or 14.Electroanalysis
@Electroanalysis The GHC version that you are suggesting to install is 7.6.3 but I would like to have 7.8.3 cause there is some minor syntax difference that I got used to. At least that's what i thinkMorrell
Hmmm. The binary version claims to be 2014.2.0.0, which has ghc 7.8.3.Electroanalysis
Make a cabal project, add HUnit to dependencies, then do cabal sandbox init && cabal install --only-dependencies && cabal build. Anyway, constraints on base are hell, because its not like you can reinstall base. So I'm not sure why people put upper bounds on it, its stupid.Buerger
ummm.. thank you for your comment but I don't know how to make a cabal project or how to add dependencies. Could you give more details?Morrell
@Morrell cabal init will make the skeleton for the file, and then you just need to set your Main-is and Build-dependenciesBuerger
@Buerger how do I set these? a .cabal file was generated but none of these options is written in the file :/Morrell
@Morrell did you select to make an executable?Buerger
@Buerger ok i made an executable and the option main-is is commented out or something because it is written as --main-is:, also is the option build-depends the option Build-dependencies that you mention in your previous comment? What should I set these two options to?Morrell
@Morrell Oops, yea, its build-depends. Set main-is to whatever your haskell file is, ie, TestFile.hs, and set build-depends to your list of dependencies, ie, base, HUnit, ...Buerger
@Buerger after setting these options what do I do ?Morrell
@Morrell cabal sandbox init && cabal install --only-dependencies && cabal buildBuerger
@Buerger it says that sandbox is an unrecognised commandMorrell
@Morrell What version of cabal install do you have? Run cabal --versionBuerger
@Buerger cabal-install version 1.16.0.2 using version 1.16.0 of the Cabal libraryMorrell
@Morrell Didn't you say you are using ghc-7.8.3? I would think you would have a more recent cabal if you have that version of ghc. Can you update your cabal somehow?Buerger
@Morrell You should, but normally cabal is something you have from your package manager. How did you install all of this stuff in the first place? Having ghc-7.8.3 and cabal-1.16 is weirdBuerger
@Buerger I followed this tutorial: (gist.github.com/yantonov/10083524)Morrell
@Morrell possibly incorrectly, since it implies that you should get cabal 1.20.3Buerger
M
1

Turns out I had mistakenly installed two versions of ghc (7.6.3 and 7.8.3) so I removed them both along with cabal and reinstalled everything. Now it works!

Morrell answered 2/11, 2014 at 14:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.