Why does my HUnit test suite fail but pass successfully in Cabal?

orome

If I have test/Test.hs with

module Main where

import Test.HUnit

test1 :: Test
test1 = TestCase $ assertEqual "Should be one" 1 5

test2 :: Test
test2 = TestCase $ assertEqual "Shold both be zero" 0 0

main :: IO Counts
main = runTestTT $ TestList [test1, test2, test1]

and a .cabal with

test-suite my-test
    type:               exitcode-stdio-1.0
    hs-source-dirs:     test
    main-is:            Test.hs
    build-depends:      base >= 4.8.1.0 && <4.9,
                        HUnit >= 1.3
    default-language:   Haskell2010

and I run cabal test --show-details='always' then I get

Test suite my-test: RUNNING...
### Failure in: 0
test/Test.hs:6
Should be one
expected: 1
 but got: 5
### Failure in: 2
test/Test.hs:6
Should be one
expected: 1
 but got: 5
Cases: 3  Tried: 3  Errors: 0  Failures: 2
Test suite my-test: PASS

Why does my test suite pass when I've had failures? Likewise, if I cabal sdist I get no warning that my tests have failed.

dfeuer

According to the Cabal users' guide,

Test suites using the exitcode-stdio-1.0 interface are executables that indicate test failure with a non-zero exit code when run; they may provide human-readable log information through the standard output and error channels.

You've defined

main :: IO Counts
main = runTestTT $ TestList [test1, test2, test1]

This runs tests, prints out test information, and then always exits successfully. If you want Cabal to know the test has failed, you need to capture the Counts, check for errors and failures, and exit with a non-zero status if you find such.

import System.Exit

main :: IO ()
main = do
  results <- runTestTT $ TestList [test1, test2, test1]
  if (errors results + failures results == 0)
    then
      exitWith ExitSuccess
    else
      exitWith (ExitFailure 1)

The test-framework package provides convenient defaultMain functions that do this sort of thing; you may want to consider that approach.

You should note that the exitcode-stdio-1.0 interface is considered semi-deprecated; the Cabal maintainers recommend switching to their rather more Haskellian detailed-0.9 interface.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Why does my django test suite fail to refresh the database between tests when I alter my table during a test?

From Dev

Finding my executable in a Cabal test suite

From Dev

Finding my executable in a Cabal test suite

From Dev

Why does my rspec test fail?

From Dev

Python: Why does my 'less than' test fail?

From Dev

why my failing Ruby Unit Test does not fail?

From Dev

Why does my Interceptor Fail in a Weld SE unit test?

From Dev

Why does my unit test fail when I refactor

From Dev

Why does my flask test client fail about 60% of the time?

From Dev

Why my rspec test fail?

From Dev

Why does my NSMutableURLRequest fail?

From Dev

Why my XPath assertion test does pass in eXist-db?

From Dev

I pass the test case, but fail to verify, why?

From Dev

Using cabal to compile but not run the test suite?

From Dev

Why does py.test pass a unittest when Pyunit and nosetest fail it (as expected)?

From Dev

Why does JUnit test pass when invoked directly but fail when invoked using Maven?

From Dev

Why does panda fail to install my module when all tests pass locally?

From Dev

Why does my Rspec post :create invalid parameter controller test fail?

From Dev

Why does this integration test with post request fail?

From Dev

Why does this Jasmine test fail occasionally in Firefox

From Dev

Why does Peterson's lock fail in this test?

From Dev

Flask-testing - why the test does fail

From Dev

Why does this integration test with post request fail?

From Dev

ghc-mod does not use my cabal sandbox. why?

From Java

Why does assembly binding fail in my project?

From Dev

Why does my cross-compiling fail?

From Dev

Why does my redirected CORS request fail?

From Dev

Why does my kernel fail to build?

From Dev

Why does my linq to sql query fail?

Related Related

  1. 1

    Why does my django test suite fail to refresh the database between tests when I alter my table during a test?

  2. 2

    Finding my executable in a Cabal test suite

  3. 3

    Finding my executable in a Cabal test suite

  4. 4

    Why does my rspec test fail?

  5. 5

    Python: Why does my 'less than' test fail?

  6. 6

    why my failing Ruby Unit Test does not fail?

  7. 7

    Why does my Interceptor Fail in a Weld SE unit test?

  8. 8

    Why does my unit test fail when I refactor

  9. 9

    Why does my flask test client fail about 60% of the time?

  10. 10

    Why my rspec test fail?

  11. 11

    Why does my NSMutableURLRequest fail?

  12. 12

    Why my XPath assertion test does pass in eXist-db?

  13. 13

    I pass the test case, but fail to verify, why?

  14. 14

    Using cabal to compile but not run the test suite?

  15. 15

    Why does py.test pass a unittest when Pyunit and nosetest fail it (as expected)?

  16. 16

    Why does JUnit test pass when invoked directly but fail when invoked using Maven?

  17. 17

    Why does panda fail to install my module when all tests pass locally?

  18. 18

    Why does my Rspec post :create invalid parameter controller test fail?

  19. 19

    Why does this integration test with post request fail?

  20. 20

    Why does this Jasmine test fail occasionally in Firefox

  21. 21

    Why does Peterson's lock fail in this test?

  22. 22

    Flask-testing - why the test does fail

  23. 23

    Why does this integration test with post request fail?

  24. 24

    ghc-mod does not use my cabal sandbox. why?

  25. 25

    Why does assembly binding fail in my project?

  26. 26

    Why does my cross-compiling fail?

  27. 27

    Why does my redirected CORS request fail?

  28. 28

    Why does my kernel fail to build?

  29. 29

    Why does my linq to sql query fail?

HotTag

Archive