CPPUNIT_ASSERT会导致系统冻结或挂起

时间:2017-04-10 14:09:08

标签: c++ testing assert freeze cppunit

如果没有提供太多的上下文(正如我在许多不同的单元测试中看到过这个问题),任何人都可以向我解释为什么CPPUNIT_ASSERT调用失败有时会导致程序冻结/挂起?

例如,我经常会使用一个测试程序,我会看到这个电话......

condition

如果condition的计算结果为true,或者引发崩溃并打印一条表明此断言发生故障的语句,那么这个调用当然会理所当然。我的问题是,有时,当{-# LANGUAGE OverloadedStrings, DeriveGeneric, DeriveAnyClass #-} module BoardToJSON where import GHC.Generics import Data.Aeson import Data.Aeson.Text (encodeToLazyText) import Data.Text import Control.Applicative import Control.Monad import qualified Data.ByteString.Lazy as B import GHC.Generics import Data.Text.Lazy.IO as I import Foreign.C.Types import Foreign.C.String import Data.Maybe import Data.List import Data.Ix import Data.List import Data.Maybe --foreign export ccall writef :: IO () data Piece = Piece { _type :: !Text, _color :: !Text, _x :: Int, _y :: Int } deriving (Eq, Show, Generic, ToJSON, FromJSON) piecesList::[Piece] piecesList = [Piece "Rook" "White" 1 1, Piece "Knight" "White" 2 1, Piece "Bishop" "White" 3 1, Piece "Queen" "White" 4 1, Piece "King" "White" 5 1, Piece "Bishop" "White" 6 1, Piece "Knight" "White" 7 1, Piece "Rook" "White" 8 1, Piece "Pawn" "White" 1 2, Piece "Pawn" "White" 2 2, Piece "Pawn" "White" 3 2, Piece "Pawn" "White" 4 2, Piece "Pawn" "White" 5 2, Piece "Pawn" "White" 6 2, Piece "Pawn" "White" 7 2, Piece "Pawn" "White" 8 2, Piece "Rook" "Black" 1 8, Piece "Knight" "Black" 2 8, Piece "Bishop" "Black" 3 8, Piece "Queen" "Black" 4 8, Piece "King" "Black" 5 8, Piece "Bishop" "Black" 6 8, Piece "Knight" "Black" 7 8, Piece "Rook" "Black" 8 8, Piece "Pawn" "Black" 1 7, Piece "Pawn" "Black" 2 7, Piece "Pawn" "Black" 3 7, Piece "Pawn" "Black" 4 7, Piece "Pawn" "Black" 5 7, Piece "Pawn" "Black" 6 7, Piece "Pawn" "Black" 7 7, Piece "Pawn" "Black" 8 7] jsonFile :: FilePath jsonFile = "pieces.json" writef = I.writeFile jsonFile (encodeToLazyText piecesList) getJSON :: IO B.ByteString getJSON = B.readFile jsonFile getPieces :: IO (Either String [Piece]) getPieces = (eitherDecode <$> getJSON) :: IO (Either String [Piece]) 评估为false时,这些断言将导致程序挂起。

我已经看到了许多功能测试,其中失败将表现得恰当,但是我现在使用的测试最终会遇到这个问题。这变得令人讨厌,因为它需要我调试代码只是为了弄清楚测试是否应该失败。有没有其他人看过这个问题,或者任何人都可以煽动为什么会发生这种情况?

0 个答案:

没有答案