Skip to content

Instantly share code, notes, and snippets.

@Risto-Stevcev
Created December 6, 2014 02:19
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Risto-Stevcev/a9798abc898fba99235b to your computer and use it in GitHub Desktop.
Save Risto-Stevcev/a9798abc898fba99235b to your computer and use it in GitHub Desktop.
Adding HUnit to Cabal packages
module Main where
main = undefined
-- Initial SampleTest.cabal generated by cabal init. For further
-- documentation, see http://haskell.org/cabal/users-guide/
name: SampleTest
version: 0.1.0.0
-- synopsis:
-- description:
-- license:
author: Risto Stevcev
maintainer: risto1@gmail.com
-- copyright:
-- category:
build-type: Simple
-- extra-source-files:
cabal-version: >=1.10
executable SampleTest
main-is: Main.hs
-- other-modules:
-- other-extensions:
build-depends: base, Cabal
-- hs-source-dirs:
default-language: Haskell2010
Test-Suite SampleTestSuite
type: exitcode-stdio-1.0
main-is: Tests.hs
build-depends: base,
test-framework,
test-framework-hunit,
HUnit
default-language: Haskell2010
module Main where
import Test.Framework
import Test.Framework.Providers.HUnit
import Test.HUnit
testfoo = TestCase $ assertEqual "Foo == Foo"
"Foo" "Foo"
testfoo2 = TestCase $ assertEqual "Foo != Bar"
"Foo" "Bar"
-- hUnitTestToTests: Adapt an existing HUnit test into a list of test-framework tests
tests = hUnitTestToTests $ TestList [TestLabel "testfoo" testfoo,
TestLabel "testfoo2" testfoo2]
main = defaultMain tests
@Risto-Stevcev
Copy link
Author

To kick things off, just do:
cabal install && cabal configure --enable-tests && cabal test

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