[英]When using “stack test”, my hspec tests output is not colorized
This is an infuriating thing since I have built Hspec-based test suites in which colors all behave normally. 因为我已经建立了基于Hspec的测试套件,其中所有颜色均正常运行,所以这真是令人发指。 But on this project, I cannot get colors to appear when I run all of the test suites at once. 但是在这个项目中,当我同时运行所有测试套件时,无法显示颜色。
My project.cabal is set up like this: 我的project.cabal设置如下:
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 this: 然后我的SpecMain.hs文件(相同)包含以下内容:
{-# OPTIONS_GHC -F -pgmF hspec-discover #-}
So, when I run stack test
, all of my tests run, but the output is not colorized. 因此,当我运行stack test
,所有的测试都将运行,但是输出未着色。 If I run stack build --file-watch --test
, the tests run, but if there is any failure at all then all of the output is colored red. 如果我运行stack build --file-watch --test
,则测试将运行,但是如果完全失败,则所有输出都将显示为红色。 Finally, if I run stack test weblog:unit
or stack test weblog:integration
, then the colors end up exactly as they should be. 最后,如果我运行stack test weblog:unit
或stack test weblog:integration
,那么颜色最终将按其应有的状态结束。 Headers are white, passing tests are green, failing tests are red, and pending tests are yellow. 标头为白色,通过测试为绿色,失败测试为红色,未决测试为黄色。
When I'm doing active development I tend to depend on stack build --file-watch --test
, but I really need the colors to be right. 当我进行主动开发时,我倾向于依靠stack build --file-watch --test
,但是我确实需要正确的颜色。
Have any of you any idea what is going on, how I can fix this, or what additional information I need to provide? 你们中的任何人知道发生了什么事,如何解决此问题或需要提供哪些其他信息吗?
By default, hspec will only use colors when the output is shown on a terminal and when the environment variable TERM
is not "dumb"
(or isn't set). 默认情况下,仅当终端上显示输出并且环境变量TERM
不是"dumb"
(或未设置)时,hspec才会使用颜色。 Unless you set an environment variable to "dumb"
, it's likely that there is something going on with the terminal detection. 除非将环境变量设置为"dumb"
,否则终端检测可能会发生某些情况。
Either way, stack build
enables 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 behaviour. 无论哪种方式, stack build
可以使您将参数用于带有--test-arguments
测试套件,并且hspec
解释几个命令行参数,包括--color
和--no-color
,它们会覆盖默认行为。 Therefore, you can force the colors: 因此,您可以强制使用颜色:
stack test --file-watch --test-arguments "--color"
Stack uses the behavior you are seeing when you give it more than one package to test at a time. 当您一次给多个软件包测试时,Stack会使用您所看到的行为。 Typically, this happens because you have more than one location listed in the packages stanza of your stack.yaml
file. 通常,发生这种情况是因为您在stack.yaml
文件的软件包节中列出了多个位置。
Recent versions of stack mention the following in the auto-generated stack.yaml
file: 堆栈的最新版本在自动生成的stack.yaml
文件中提到以下内容:
# A package marked 'extra-dep: true' will only be built if demanded by a
# non-dependency (i.e. a user package), and its test suites and benchmarks
# will not be run. This is useful for tweaking upstream packages.
If you mark all but one location in the packages stanza as an extra-dep
, stack will revert to its single-package behavior when testing, and show your colorized test results as you expect. 如果将软件包节中除一个位置之外的所有位置都标记为extra-dep
,则在测试时,堆栈将恢复为单包行为,并按预期显示彩色测试结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.