Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8882131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:30:03+00:00 2026-06-14T20:30:03+00:00

I’m new to Haskell and I’m trying to structure a program under test. I

  • 0

I’m new to Haskell and I’m trying to structure a program under test. I have decided to use HUnit and Cabal.

From what I have seen a well strucutred project looks the following:

src/
  AppName/
  Appname.hs
testsuite/
  tests/
    AppName/
  TestRunner.hs
AppName.cabal
Setup.hs

The parts that are a mystery to me are the TestRunner.hs and the AppName.cabal.

What would a testrunner look like that runs all of the test under the testsuite/tests directory and sub directories? And how can it be integrated with Cabal?

Also, how do you put the hackage dependencies in the AppName.cabal and build them from the command line?

I am having a hard time finding a full example building an application from scratch with tests and dependencies.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T20:30:04+00:00Added an answer on June 14, 2026 at 8:30 pm

    Here’s a fragment of the .cabal file I used for one of my recent libraries.

    ...
    Library
      Build-depends:        base >= 4 && < 5, bytestring, directory, filepath, hslogger,
                            SHA, zlib
      Ghc-options:          -Wall
      Exposed-modules:      Ltc.Store
    
    Test-suite reference
      Hs-Source-Dirs:       Test, .
      Main-Is:              ReferenceProps.hs
      Type:                 exitcode-stdio-1.0
    
      Build-Depends:        base >= 4 && < 5, bytestring, directory, filepath, hslogger,
                            SHA, zlib
      Ghc-Options:          -Wall
    
      Build-Depends:        test-framework, test-framework-hunit, test-framework-quickcheck2,
                            HUnit, QuickCheck
    

    As we can see the cabal file defines a library and a testsuite. The library defines the modules it exports, the packages it depends on, and sets some custom GHC options.

    We can easily build and package the library for distribution with:

    % cabal configure
    % cabal build
    % cabal sdist
    

    The testsuite looks a lot like the the library: first off, it has the same dependencies as the library (see the first Build-Depends line), and it then adds some extra test dependencies (see the second Build-Depends line). The testsuite here is a combination of HUnit and QuickCheck tests, and it uses Test-Framework as the runner. The test proper is Test/ReferenceProps.hs. It’s a exitcode-stdio type test. This means that cabal will say that the tests pass if ReferenceProps exits with code 0. Otherwise, it will say the tests failed.

    The testsuite looks like this (but, here, we’re going to use some simple tests for list reversals):

    import Data.Monoid
    import Test.Framework
    import Test.Framework.Providers.HUnit
    import Test.Framework.Providers.QuickCheck2
    import Test.HUnit
    import Test.QuickCheck
    
    main :: IO ()
    main = defaultMainWithOpts
           [ testCase "rev" testRev
           , testProperty "listRevRevId" propListRevRevId
           ] mempty
    
    testRev :: Assertion
    testRev = reverse [1, 2, 3] @?= [3, 2, 1]
    
    propListRevRevId :: [Int] -> Property
    propListRevRevId xs = not (null xs) ==> reverse (reverse xs) == xs
    

    The main is just a harness. You can also set various options for test-framework by replacing the mempty. The function testRev is a HUnit test, and propListRevRevId is a QuickCheck test; see the relevant docs on how to write these.

    Finally, we can run the tests:

    % cabal configure --enable-tests
    % cabal test
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I have a text area in my form which accepts all possible characters from
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a view passing on information from a database: def serve_article(request, id): served_article
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I have a bunch of posts stored in text files formatted in yaml/textile (from
I am trying to loop through a bunch of documents I have to put
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.