Test.Exceptions

This commit is contained in:
Michael 2011-03-04 15:56:36 +02:00
parent 2b70aeb2b3
commit c556a19feb
2 changed files with 49 additions and 0 deletions

47
Test/Exceptions.hs Normal file
View File

@ -0,0 +1,47 @@
{-# LANGUAGE QuasiQuotes, TypeFamilies, TemplateHaskell, MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE FlexibleInstances #-}
module Test.Exceptions (exceptionsTest) where
import Yesod.Core
import Yesod.Content
import Yesod.Dispatch
import Yesod.Handler (Route, ErrorResponse (InternalError))
import Test.Framework (defaultMain, testGroup, Test)
import Test.Framework.Providers.HUnit
import Test.HUnit hiding (Test)
import Network.Wai
import Network.Wai.Test
import qualified Data.ByteString.Lazy.Char8 as L8
data Y = Y
mkYesod "Y" [$parseRoutes|
/ RootR GET
|]
instance Yesod Y where
approot _ = "http://test"
errorHandler (InternalError e) = return $ chooseRep $ RepPlain $ toContent e
errorHandler x = defaultErrorHandler x
getRootR = error "FOOBAR" >> return ()
exceptionsTest :: Test
exceptionsTest = testGroup "Test.Exceptions"
[ testCase "500" case500
]
runner f = toWaiApp Y >>= runSession f
defaultRequest = Request
{ pathInfo = ""
, requestHeaders = []
, queryString = ""
, requestMethod = "GET"
}
case500 = runner $ do
res <- request defaultRequest
assertStatus 500 res
assertBody "FOOBAR" res

View File

@ -1,7 +1,9 @@
import Test.Framework (defaultMain)
import Test.CleanPath
import Test.Exceptions
main :: IO ()
main = defaultMain
[ cleanPathTest
, exceptionsTest
]