@@ -1,5 +1,6 @@
11{-# LANGUAGE OverloadedStrings #-}
22{-# LANGUAGE CPP #-}
3+{-# LANGUAGE DeriveDataTypeable #-}
34module Network.Wai.Test
45 ( -- * Session
56 Session
@@ -19,13 +20,17 @@ module Network.Wai.Test
1920 , assertBodyContains
2021 , assertHeader
2122 , assertNoHeader
23+ , WaiTestFailure (..)
2224 ) where
2325
2426import Network.Wai
25−import qualified Test.HUnit.Base as H
2627import Control.Monad.IO.Class (liftIO)
2728import Control.Monad.Trans.State (StateT, evalStateT)
2829import Control.Monad.Trans.Reader (ReaderT, runReaderT, ask)
30+import Control.Monad (unless)
31+import Control.DeepSeq (deepseq)
32+import Control.Exception (throwIO, Exception)
33+import Data.Typeable (Typeable)
2934import Data.Map (Map)
3035import qualified Data.Map as Map
3136import Data.ByteString (ByteString)
@@ -108,10 +113,17 @@ runResponse res = do
108113 toBuilder C.Flush = flush
109114
110115assertBool :: String -> Bool -> Session ()
111−assertBool s b = liftIO $ H.assertBool s b
116+assertBool s b = unless b $ assertFailure s
112117
113118assertString :: String -> Session ()
114−assertString s = liftIO $ H.assertString s
119+assertString s = unless (null s) $ assertFailure s
120+
121+assertFailure :: String -> Session ()
122+assertFailure msg = msg `deepseq` liftIO (throwIO (WaiTestFailure msg))
123+
124+data WaiTestFailure = WaiTestFailure String
125+ deriving (Show, Eq, Typeable)
126+instance Exception WaiTestFailure
115127
116128assertContentType :: ByteString -> SResponse -> Session ()
117129assertContentType ct SResponse{simpleHeaders = h} =