繁体   English   中英

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

[英]When using “stack test”, my hspec tests output is not colorized

因为我已经建立了基于Hspec的测试套件,其中所有颜色均正常运行,所以这真是令人发指。 但是在这个项目中,当我同时运行所有测试套件时,无法显示颜色。

我的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
  ...

然后我的SpecMain.hs文件(相同)包含以下内容:

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

因此,当我运行stack test ,所有的测试都将运行,但是输出未着色。 如果我运行stack build --file-watch --test ,则测试将运行,但是如果完全失败,则所有输出都将显示为红色。 最后,如果我运行stack test weblog:unitstack test weblog:integration ,那么颜色最终将按其应有的状态结束。 标头为白色,通过测试为绿色,失败测试为红色,未决测试为黄色。

当我进行主动开发时,我倾向于依靠stack build --file-watch --test ,但是我确实需要正确的颜色。

你们中的任何人知道发生了什么事,如何解决此问题或需要提供哪些其他信息吗?

默认情况下,仅当终端上显示输出并且环境变量TERM不是"dumb" (或未设置)时,hspec才会使用颜色。 除非将环境变量设置为"dumb" ,否则终端检测可能会发生某些情况。

无论哪种方式, stack build可以使您将参数用于带有--test-arguments测试套件,并且hspec解释几个命令行参数,包括--color--no-color ,它们会覆盖默认行为。 因此,您可以强制使用颜色:

stack test --file-watch --test-arguments "--color"

当您一次给多个软件包测试时,Stack会使用您所看到的行为。 通常,发生这种情况是因为您在stack.yaml文件的软件包节中列出了多个位置。

堆栈的最新版本在自动生​​成的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.

如果将软件包节中除一个位置之外的所有位置都标记为extra-dep ,则在测试时,堆栈将恢复为单包行为,并按预期显示彩色测试结果。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM