12

I have a cabal package for which I have a test-suite set up using the exitcode-stdio-1.0 type, like so:

When I run it using cabal test, cabal does not print the standard output/standard error of the executable; it only prints its own logging information:

$ cabal test

Running 1 test suites...
Test suite test-foo: RUNNING...
Test suite test-foo: PASS
Test suite logged to: dist/test/foo-0.0.1-test-foo.log
1 of 1 test suites (1 of 1 test cases) passed.
$ 

The output that I want is in that log file:

$ cat dist/test/foo-0.0.1-test-fo.log 
Test suite test-foo: RUNNING...
HUnit group 1:
  Expected connect: [OK]

         Test Cases  Total      
 Passed  1           1          
 Failed  0           0          
 Total   1           1          
Test suite test-foo: PASS
Test suite logged to: dist/test/foo-0.0.1-test-foo.log
$ 

How do I get cabal to print this output to its own standard output? I can't find it in the documentation.

jameshfisher
  • 34,029
  • 31
  • 121
  • 167
  • Thank you for this post. I would have thought directing to standard output would be the most common use case. – sdasdadas Mar 15 '14 at 18:47
  • For new-build: https://stackoverflow.com/questions/51488620/how-can-i-stream-test-results-with-cabal-new-test – jberryman Aug 05 '19 at 01:36

3 Answers3

19

If you are using Cabal new-test (defualt on Cabal 3+):

$ cabal new-test --test-show-details=streaming

Older Cabal versions allow the output to be streamed using:

$ cabal test --show-details=streaming

--show-details=filter

Determines if the results of individual test cases are shown on the terminal. May be always (always show), never (never show), failures (show only failed results), or streaming (show all results in real time).

Read more in the Cabal User Guide.

Janus Troelsen
  • 20,267
  • 14
  • 135
  • 196
macron
  • 1,816
  • 13
  • 14
4

There has been a new way for a few months, and tests results are even written to stdout on the file, not flushed at the end

cabal test --show-details=streaming
gbataille
  • 43
  • 5
-1

When using exitcode-stdio-1.0 cabal will only report the test log if the test program returns an exit code (explictly "fails"). A solution would be to make your test program return an error code when any of the tests fail:

import System.Exit (exitFailure, exitSuccess)

main :: IO ()
main = do
  result <- runTests
  if result
    then exitSuccess
    else exitFailure

runTests :: IO Bool
runTests = do
  ...
  return True/False

You only need that when writing a "manual" testing program: most test reporting frameworks (e.g.: tasty, test-framework, hspec) already do to that automatically.

If you really want to always see the results, you can always use either:

  • cabal test --log=/dev/stdout (given in another answer)
  • exitFailure at the end of execution
Community
  • 1
  • 1
Rudy Matela
  • 6,310
  • 2
  • 32
  • 37