【问题标题】:cabal test does not print executable outputcabal 测试不打印可执行输出
【发布时间】:2021-11-05 06:53:03
【问题描述】:

我有一个使用 exitcode-stdio-1.0 类型设置的 test-suite 的 cabal 包,如下所示:

当我使用cabal test 运行它时,cabal 不会打印可执行文件的标准输出/标准错误;它只打印自己的日志信息:

$ cabal test

Running 1 test suites...
Test suite test-foo: RUNNING...
Test suite test-foo: PASS
Test suite logged to: dist/test/foo-0.0.1-test-foo.log
1 of 1 test suites (1 of 1 test cases) passed.
$ 

我想要的输出在那个日志文件中:

$ cat dist/test/foo-0.0.1-test-fo.log 
Test suite test-foo: RUNNING...
HUnit group 1:
  Expected connect: [OK]

         Test Cases  Total      
 Passed  1           1          
 Failed  0           0          
 Total   1           1          
Test suite test-foo: PASS
Test suite logged to: dist/test/foo-0.0.1-test-foo.log
$ 

如何让 cabal 将此输出打印到它自己的标准输出?我在文档中找不到它。

【问题讨论】:

标签: testing stdout cabal


【解决方案1】:

如果您使用的是 Cabal 新测试(Cabal 3+ 上默认):

$ cabal new-test --test-show-details=streaming

较旧的 Cabal 版本允许使用以下方式流式传输输出:

$ cabal test --show-details=streaming

--show-details=过滤器

确定单个测试用例的结果是否显示在 终端。可能是 always(总是显示)、never(从不显示)、failures(仅显示失败的结果)或 streaming em>(实时显示所有结果)。

Cabal User Guide 中了解更多信息。

【讨论】:

    【解决方案2】:

    有几个月的新方法,测试结果甚至写入文件的stdout,最后不刷新

    cabal test --show-details=streaming
    

    【讨论】:

      【解决方案3】:

      当使用exitcode-stdio-1.0 时,cabal 只会在测试程序返回退出代码(显式“失败”)时报告测试日志。一个解决方案是让您的测试程序在任何测试失败时返回错误代码:

      import System.Exit (exitFailure, exitSuccess)
      
      main :: IO ()
      main = do
        result <- runTests
        if result
          then exitSuccess
          else exitFailure
      
      runTests :: IO Bool
      runTests = do
        ...
        return True/False
      

      您只需要在编写“手动”测试程序时这样做:大多数测试报告框架(例如:tastytest-frameworkhspec)已经自动执行此操作。

      如果你真的想总是看到结果,你可以随时使用:

      • cabal test --log=/dev/stdout(在另一个答案中给出)
      • exitFailure 在执行结束时

      【讨论】:

        猜你喜欢
        • 2018-08-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-12-22
        • 2016-08-20
        • 1970-01-01
        相关资源
        最近更新 更多