title: "Could not find module ‘Test.HUnit’" Error when executing Haskell's unittest (HUnit) in CodeRunner
body: <p>I have simple unit test code for Haskell's HUnit. I use Mac OS X 10.10, and I installed HUnit with <code>cabal install hunit</code>. </p>
  
  <pre><code>module TestSafePrelude where
  
  import SafePrelude( safeHead )
  import Test.HUnit
  
  testSafeHeadForEmptyList :: Test
  testSafeHeadForEmptyList = 
      TestCase $ assertEqual "Should return Nothing for empty list"
                             Nothing (safeHead ([]::[Int]))
  
  testSafeHeadForNonEmptyList :: Test
  testSafeHeadForNonEmptyList =
      TestCase $ assertEqual "Should return (Just head) for non empty list" (Just 1)
                 (safeHead ([1]::[Int]))
  
  main :: IO Counts
  main = runTestTT $ TestList [testSafeHeadForEmptyList, testSafeHeadForNonEmptyList]
  </code></pre>
  
  <p>I can execute it with <code>runhaskell TestSafePrelude.hs</code> to get the results:</p>
  
  <pre><code>Cases: 2  Tried: 2  Errors: 0  Failures: 0
  Counts {cases = 2, tried = 2, errors = 0, failures = 0}
  </code></pre>
  
  <p>However, when I run it in <a href="https://coderunnerapp.com" rel="nofollow noreferrer">Code Runner</a>, I have error message that can't find the HUnit module. </p>
  
  <p><img src="https://i.stack.imgur.com/ULB5D.png" alt="enter image description here"></p>
  
  <p>CodeRunner launches the test on a different shell environment, and this seems to be the issue. If so, what environment variables need to be added? If not, what might be causing the problem? </p>
  
  <p><img src="https://i.stack.imgur.com/CkjLr.png" alt="enter image description here"></p>
  
  <p>I also find that <code>ghc-pkg list</code> from the CodeRunner does not search  for the directories in <code>~/.ghc</code> which contains the HUnit.</p>
  
  <pre><code>/usr/local/Cellar/ghc/7.8.3/lib/ghc-7.8.3/package.conf.d:
      Cabal-1.18.1.4
      array-0.5.0.0
      ...
      xhtml-3000.2.1
  </code></pre>
  
  <p>This is the results when executed in shell:</p>
  
  <pre><code>/usr/local/Cellar/ghc/7.8.3/lib/ghc-7.8.3/package.conf.d
     Cabal-1.18.1.4
     array-0.5.0.0
     ...
  /Users/smcho/.ghc/x86_64-darwin-7.8.3/package.conf.d
     ...
     HUnit-1.2.5.2
     ...
     zlib-0.5.4.2
  </code></pre>
  
  <p>I added both <code>~/.cabal</code> and <code>~/.ghc</code> in the path, but it doesn't work. </p>