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?
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. – Electroanalysis2014.2.0.0
, which has ghc 7.8.3. – ElectroanalysisHUnit
to dependencies, then docabal sandbox init && cabal install --only-dependencies && cabal build
. Anyway, constraints onbase
are hell, because its not like you can reinstallbase
. So I'm not sure why people put upper bounds on it, its stupid. – Buergercabal init
will make the skeleton for the file, and then you just need to set yourMain-is
andBuild-dependencies
– Buergermain-is
is commented out or something because it is written as--main-is:
, also is the optionbuild-depends
the optionBuild-dependencies
that you mention in your previous comment? What should I set these two options to? – Morrellbuild-depends
. Setmain-is
to whatever your haskell file is, ie,TestFile.hs
, and setbuild-depends
to your list of dependencies, ie,base, HUnit, ...
– Buergercabal sandbox init && cabal install --only-dependencies && cabal build
– Buergercabal install
do you have? Runcabal --version
– Buergerghc-7.8.3
? I would think you would have a more recent cabal if you have that version ofghc
. Can you update yourcabal
somehow? – Buergercabal
is something you have from your package manager. How did you install all of this stuff in the first place? Havingghc-7.8.3
andcabal-1.16
is weird – Buergercabal 1.20.3
– Buerger