diff --git a/warp/ChangeLog.md b/warp/ChangeLog.md index f634ff14e..6e4ac7a9a 100644 --- a/warp/ChangeLog.md +++ b/warp/ChangeLog.md @@ -1,3 +1,8 @@ +## 3.3.16 + +* Add `testWithApplication'` function + Same as `testWithApplication` but accepts pure `Application` instead of `IO Application` + ## 3.3.15 * Using http2 v3. diff --git a/warp/Network/Wai/Handler/Warp.hs b/warp/Network/Wai/Handler/Warp.hs index ef1caf13a..245c468ad 100644 --- a/warp/Network/Wai/Handler/Warp.hs +++ b/warp/Network/Wai/Handler/Warp.hs @@ -103,6 +103,7 @@ module Network.Wai.Handler.Warp ( , withApplication , withApplicationSettings , testWithApplication + , testWithApplication' , testWithApplicationSettings , openFreePort -- * Version diff --git a/warp/Network/Wai/Handler/Warp/WithApplication.hs b/warp/Network/Wai/Handler/Warp/WithApplication.hs index d69879081..0ee5eda2a 100644 --- a/warp/Network/Wai/Handler/Warp/WithApplication.hs +++ b/warp/Network/Wai/Handler/Warp/WithApplication.hs @@ -3,6 +3,7 @@ module Network.Wai.Handler.Warp.WithApplication ( withApplication, withApplicationSettings, testWithApplication, + testWithApplication', testWithApplicationSettings, openFreePort, withFreePort, @@ -48,6 +49,20 @@ withApplicationSettings settings' mkApp action = do Left () -> throwIO $ ErrorCall "Unexpected: runSettingsSocket exited" Right x -> return x +-- | Same as 'testWithApplication' +-- but accepts @app :: 'Application'@ as a first argument instead of @mkApp :: 'IO' 'Application'@. +-- +-- Except for the purity of its first argument, the behaviour of this function is identical to 'testWithApplication'. +-- +-- 'testWithApplication' can be expressed via 'testWithApplication'' as: +-- +-- >>> testWithApplication mkApp action = mkApp >>= flip testWithApplication' action +-- +-- @since 3.3.16 +testWithApplication' :: Application -> (Port -> IO a) -> IO a +testWithApplication' = + testWithApplication . return + -- | Same as 'withApplication' but with different exception handling: If the -- given 'Application' throws an exception, 'testWithApplication' will re-throw -- the exception to the calling thread, possibly interrupting the execution of diff --git a/warp/test/WithApplicationSpec.hs b/warp/test/WithApplicationSpec.hs index 113e11eac..587459b4d 100644 --- a/warp/test/WithApplicationSpec.hs +++ b/warp/test/WithApplicationSpec.hs @@ -36,6 +36,13 @@ spec = do readProcess "curl" ["-s", "localhost:" ++ show port] "") `shouldThrow` (errorCall "foo") + describe "testWithApplication'" $ do + it "propagates exceptions from the server to the executing thread" $ do + let mkApp _request _respond = throwIO $ ErrorCall "foo" + (testWithApplication' mkApp $ \ port -> do + readProcess "curl" ["-s", "localhost:" ++ show port] "") + `shouldThrow` (errorCall "foo") + {- The future netwrok library will not export MkSocket. describe "withFreePort" $ do it "closes the socket before exiting" $ do diff --git a/warp/warp.cabal b/warp/warp.cabal index d08cabad4..d59848bdc 100644 --- a/warp/warp.cabal +++ b/warp/warp.cabal @@ -1,5 +1,5 @@ Name: warp -Version: 3.3.15 +Version: 3.3.16 Synopsis: A fast, light-weight web server for WAI applications. License: MIT License-file: LICENSE