阴谋:如何停止在测试失败构建? [英] cabal: how to stop the build on test failure?

查看:135
本文介绍了阴谋:如何停止在测试失败构建?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在HUnit(Tests.hs)中创建的测试。我连他们主要的:主要= runTestTT测试。当我这样做 runhaskell测试我看到

i created tests in HUnit (Tests.hs). i connected them to main: main = runTestTT tests. when i do runhaskell Tests i see

### Failure in: 0                          
T(1)
expected: 145
 but got: 45
Cases: 10  Tried: 10  Errors: 0  Failures: 1
Counts {cases = 10, tried = 10, errors = 0, failures = 1}

预计。在阴谋文件,我没有

which is expected. in cabal file i did

test-suite xxx
  type: exitcode-stdio-1.0
  main-is: Tests.hs
  build-depends: base ==4.5.*, HUnit ==1.2.5.2, containers == 0.5.5.1

当我做小集团测试相同的测试记录写入到一个文件 - 所以我敢肯定,测试执行和失败(如预期),但在控制台中我看到

and when i do cabal test same test logs are written to a file - so i'm sure tests are executed and failing (as expected) but in console i see:

1 of 1 test suites (1 of 1 test cases) passed.

和退出code为0。

所以我的问题是:为什么小集团声称通过了测试,如何让它正确地报告错误

so my question is: why cabal claims tests passed and how to make it report errors correctly?

推荐答案

我必须想出解决办法我自己,这是我终于得到了工作....

I just had to figure this out myself, this is what I finally got to work....

module Main where

import Data.Monoid
import Test.Framework
import Test.Framework.Providers.HUnit
import Test.HUnit

firstTest::Assertion --This one passes                                                                                                                                                                      
firstTest = do
  assertEqual "reward state root doesn't match" (1::Int) 1

secondTest::IO () --This one fails  (note, Assertion is just "IO()", so you can use either)                                                                                                                 
secondTest = do
  assertEqual "empty db didn't match" (1::Int) 2

main::IO ()
main =
  defaultMainWithOpts
  [
   testCase "ShortcutNodeData Insert" firstTest,
   testCase "FullNodeData Insert" secondTest
  ] mempty

在我.cabal文件

Test-Suite test-program
  type:               exitcode-stdio-1.0
  main-is:            Main.hs
  hs-source-dirs:     test
  build-depends:      base
                , test-framework
                , test-framework-hunit
                , HUnit
                , containers

然后用阴谋试运行

这是棘手的,因为阴谋着眼于出口code(见上式),但HUnit输出自己的消息....所以,如果你不返回正确的值,你可以看到输出像测试失败,其次是测试通过。显然,解决方法是使用内置的 defaultMainWithOpts ,它正确地做一切。

It is tricky, because cabal looks at the exitcode (see the type above), but the HUnit outputs its own messages.... So if you don't return the correct value, you can see output like "test failed" followed by "test passed". Obviously, the solution is to use the builtin defaultMainWithOpts, which does everything correctly.

这篇关于阴谋:如何停止在测试失败构建?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆