简体   繁体   English

使用“堆栈测试”时,我的hspec测试输出未着色

[英]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:unitstack 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.

相关问题 当测试文件被定义为模块时,使用堆栈调用的 hspec 定义的测试会引发错误 - hspec defined tests invoked with stack throw an error when test file is defined as a module 如何使用 --match 和 cabal 测试特定的 hSpec 属性 - How to test specific hSpec property using `--match` and cabal 在使用Resharper测试运行器时,如何在我的qunit测试中设置断点 - How can I set breakpoints in my qunit tests when using the Resharper test runner 使用 CMake 和 C++ 时,我的测试从未停止。 如何在不启动其主要功能的情况下测试程序? - My tests never stop when using CMake and C++. How to test a program without starting its main function? 使用Kotlin时在单元测试和仪器测试之间共享代码 - Share code between unit test and instrumentation tests when using kotlin Rails单元测试:如何将我自己的输出添加到单元测试结果中 - Rails unit tests: How to add my own output to unit test results 如何从`lein test`输出成功的测试? - How to output successful tests from `lein test`? 当输出相同时,为什么我对Object的assertEquals()的测试失败? - Why my test to assertEquals() for Object fails when output is same? 使用单元测试和测试数据库 - Using unit tests and a test database Rails测试错误时抑制堆栈跟踪 - Suppressing stack trace when Rails tests error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM