When using the "stack test" my hspec test output is not colorized

This is an unreasonable thing, since I built tests based on Hspec, in which colors all behave normally. But in this project, I cannot make the colors appear when I run all the test packages at once.

My project.cabal is configured as follows:

test-suite unit type: exitcode-stdio-1.0 main-is: SpecMain.hs hs-source-dirs: tests/unit other-modules: WikiSpec default-language: Haskell2010 ghc-options: -Wall -fno-warn-orphans -threaded build-depends: base >=4.6 ... test-suite integration type: exitcode-stdio-1.0 main-is: SpecMain.hs hs-source-dirs: tests/integration, webapp other-modules: ApiSpec default-language: Haskell2010 ghc-options: -Wall -fno-warn-orphans -threaded build-depends: base >=4.6 ... 

And then my SpecMain.hs files (identical) contain the following:

 {-# OPTIONS_GHC -F -pgmF hspec-discover #-} 

So, when I run the stack test , all my tests run, but the output is not colorized. If I run stack build --file-watch --test , the tests are executed, but if there is any failure at all, then all the output will be painted red. Finally, if I run stack test weblog:unit or stack test weblog:integration , then the colors end exactly as they should be. The headings are white, passing tests are green, failed tests are red, and pending tests are yellow.

When I'm active, I tend to depend on stack build --file-watch --test , but I really need colors to be right.

Do you have any ideas on what is happening, how can I fix it or what additional information do I need to provide?

+6
source share
2 answers

By default, hspec will only use colors when the output is displayed on the terminal and when the TERM environment variable is not "dumb" (or not set). If you do not set the environment variable to "dumb" , something is likely to happen with terminal discovery.

In any case, the stack build allows you to use arguments for test suites with --test-arguments , and hspec interprets several command line arguments, including --color and --no-color , which overwrite the default behavior. Therefore you can force colors:

 stack test --file-watch --test-arguments "--color" 
+4
source

The stack uses the behavior that you see when you give it more than one package for testing at a time. This usually happens because there is more than one place in the package lines of your stack.yaml file.

Recent versions of the stack mention the following in the auto- stack.yaml file:

 # A package marked 'extra-dep: true' will only be built if demanded by a # non-dependency (ie a user package), and its test suites and benchmarks # will not be run. This is useful for tweaking upstream packages. 

If you mark all the places in the package lines as extra-dep , the stack will return to its single-packet behavior during testing and show your colored test results as you expect.

0
source

All Articles