Skip to content

Instantly share code, notes, and snippets.

@23Skidoo
Last active December 31, 2015 17:19
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 23Skidoo/8019225 to your computer and use it in GitHub Desktop.
Save 23Skidoo/8019225 to your computer and use it in GitHub Desktop.
module Main
where
main = undefined
name: rose
version: 0.1
cabal-version: >= 1.10
build-type: Simple
executable one
main-is: Main.hs
build-depends: base
default-language: Haskell2010
ghc-options: -Wall
Test-Suite test-one
type: exitcode-stdio-1.0
main-is: Tests.hs
build-depends: base, HUnit
default-language: Haskell2010
ghc-options: -Wall
module Main (
main
) where
import Test.HUnit
import Data.Char
four :: Int
four = 4
tests, test1, test2, test3 :: Test
test1 = TestCase $ assertEqual "test upCase" "FOO" (map toUpper "foo")
test2 = TestCase $ assertEqual "testing that the result is 4" 4 (4::Int)
test3 = TestCase $ assertEqual "testing that 4 is 4" four 4
tests = TestList [TestLabel "test1" test1, TestLabel "test2" test2, TestLabel "test3" test3]
main :: IO ()
main = do _ <- runTestTT $ tests
return ()
@lucamolteni
Copy link

Many thanks.
Here's the step I used to build it

cabal sandbox init
cabal install --enable-tests
cabal configure --enable-tests
cabal test

@sevko
Copy link

sevko commented Jun 24, 2015

Note that you need to manually set a failing exit code when tests fail for Cabal to know (otherwise, cabal test would assume that everything passed), like so:

import qualified System.Exit as Exit

main = do
    count <- HUnit.runTestTT tests
    if HUnit.failures count > 0 then Exit.exitFailure else return ()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment