1{-# LANGUAGE OverloadedStrings #-}
3module ExceptionSpec (main, spec) where
5import Control.Applicative
9import Network.HTTP.Types hiding (Header)
10import Network.Wai hiding (Response)
11import Network.Wai.Internal (Request(..))
12import Network.Wai.Handler.Warp
14import Control.Exception
15import qualified Data.Streaming.Network as N
16import Control.Concurrent.Async (withAsync)
17import Network.Socket (sClose)
22withTestServer :: (Int -> IO a) -> IO a
23withTestServer inner = bracket
24 (N.bindRandomPortTCP "127.0.0.1")
26 $ \(prt, lsocket) -> do
27 withAsync (runSettingsSocket defaultSettings lsocket testApp)
31testApp (Network.Wai.Internal.Request {pathInfo = [x]}) f
32 | x == "statusError" =
33 f $ responseLBS undefined [] "foo"
34 | x == "headersError" =
35 f $ responseLBS ok200 undefined "foo"
36 | x == "headerError" =
37 f $ responseLBS ok200 [undefined] "foo"
39 f $ responseLBS ok200 [] undefined
40 | x == "ioException" = do
41 void $ fail "ioException"
42 f $ responseLBS ok200 [] "foo"
44 f $ responseLBS ok200 [] "foo"
47spec = describe "responds even if there is an exception" $ do
48 {- Disabling these tests. We can consider forcing evaluation in Warp.
50 sc <- rspCode <$> sendGET "http://127.0.0.1:2345/statusError"
52 it "headersError" $ do
53 sc <- rspCode <$> sendGET "http://127.0.0.1:2345/headersError"
56 sc <- rspCode <$> sendGET "http://127.0.0.1:2345/headerError"
59 sc <- rspCode <$> sendGET "http://127.0.0.1:2345/bodyError"
62 it "ioException" $ withTestServer $ \prt -> do
63 sc <- rspCode <$> sendGET (concat $ ["http://127.0.0.1:", show prt, "/ioException"])
66----------------------------------------------------------------
68sendGET :: String -> IO (Response String)
69sendGET url = sendGETwH url []
71sendGETwH :: String -> [Header] -> IO (Response String)
72sendGETwH url hdr = unResult $ simpleHTTP $ (getRequest url) { rqHeaders = hdr }
74unResult :: IO (Result (Response String)) -> IO (Response String)
78 Right rsp -> return rsp
79 Left _ -> error "Connection error"
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list