Sav*_*nel 6 haskell unit-testing haskell-stack
这是一件令人愤怒的事情,因为我已经构建了基于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
...
Run Code Online (Sandbox Code Playgroud)
然后我的SpecMain.hs文件(相同)包含:
{-# OPTIONS_GHC -F -pgmF hspec-discover #-}
Run Code Online (Sandbox Code Playgroud)
因此,当我运行时,我的stack test
所有测试都会运行,但输出没有着色.如果我运行stack build --file-watch --test
,测试运行,但如果有任何故障,则所有输出都显示为红色.最后,如果我跑stack test weblog:unit
或者stack test weblog:integration
,那么颜色最终会完全按照它们的样子结束.标题为白色,通过测试为绿色,失败测试为红色,待定测试为黄色.
当我正在积极开发时,我倾向于依赖stack build --file-watch --test
,但我真的需要颜色是正确的.
你们有没有人知道发生了什么,我如何解决这个问题,或者我需要提供哪些其他信息?
默认情况下,当在示出了输出hspec将仅使用颜色的终端,并且当环境变量TERM
不是"dumb"
(或不设置)。除非您将环境变量设置为"dumb"
,否则终端检测很可能会发生问题。
无论哪种方式,stack build
您都可以使用--test-arguments
, 和来使用测试套件的参数,并hspec
解释几个命令行参数,包括--color
和--no-color
覆盖默认行为。因此,您可以强制使用颜色:
stack test --file-watch --test-arguments "--color"
Run Code Online (Sandbox Code Playgroud)