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?

alternative
  • 12,703
  • 5
  • 41
  • 41
sokras
  • 629
  • 1
  • 8
  • 19
  • 3
    Well, have you installed HUnit yet? – Zeta Nov 01 '14 at 11:46
  • 1
    I have to install it? I thought if i had ghc installed I would have it too – sokras Nov 01 '14 at 11:46
  • 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 it – sokras Nov 01 '14 at 11:49
  • Haskell is just like any other language - it has libraries and you need to install those libraries to use their functionality.. – XapaJIaMnu Nov 01 '14 at 11:53
  • 2
    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](https://www.haskell.org/platform/) which includes a good consistent set of packages to get you going. There's a [binary distribution for Ubuntu 12 or 14](https://www.haskell.org/platform/linux.html#binary). – AndrewC Nov 01 '14 at 12:28
  • @AndrewC 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 think – sokras Nov 01 '14 at 12:32
  • Hmmm. The binary version claims to be `2014.2.0.0`, which has ghc 7.8.3. – AndrewC Nov 01 '14 at 12:36
  • 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. – alternative Nov 01 '14 at 13:03
  • 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? – sokras Nov 01 '14 at 13:05
  • @sokras `cabal init` will make the skeleton for the file, and then you just need to set your `Main-is` and `Build-dependencies` – alternative Nov 01 '14 at 13:07
  • @alternative how do I set these? a .cabal file was generated but none of these options is written in the file :/ – sokras Nov 01 '14 at 13:12
  • @sokras did you select to make an executable? – alternative Nov 01 '14 at 13:14
  • @alternative 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? – sokras Nov 01 '14 at 13:20
  • @sokras 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, ...` – alternative Nov 01 '14 at 13:26
  • @alternative after setting these options what do I do ? – sokras Nov 01 '14 at 13:30
  • @sokras `cabal sandbox init && cabal install --only-dependencies && cabal build` – alternative Nov 01 '14 at 14:12
  • @alternative it says that sandbox is an unrecognised command – sokras Nov 01 '14 at 14:16
  • @sokras What version of `cabal install` do you have? Run `cabal --version` – alternative Nov 01 '14 at 14:17
  • @alternative cabal-install version 1.16.0.2 using version 1.16.0 of the Cabal library – sokras Nov 01 '14 at 14:23
  • @sokras 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? – alternative Nov 01 '14 at 14:24
  • @sokras 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 weird – alternative Nov 01 '14 at 14:44
  • @alternative I followed this tutorial: (https://gist.github.com/yantonov/10083524) – sokras Nov 01 '14 at 14:45
  • @sokras possibly incorrectly, since it implies that you should get `cabal 1.20.3` – alternative Nov 01 '14 at 14:50

1 Answers1

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!

sokras
  • 629
  • 1
  • 8
  • 19