Skip to content

Commit

Permalink
Support servant-server-0.19.1
Browse files Browse the repository at this point in the history
Since version 0.19.1, `servant-server` requires the type `a` in
combinator `Capture foo a` to be `Typeable`. This commit adds the
constraint in `HasMock` for `Capture'` and `CaptureAll`
  • Loading branch information
nbacquey committed Jan 9, 2023
1 parent f6c354a commit f327a09
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
6 changes: 3 additions & 3 deletions servant-mock.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: >=1.10
name: servant-mock
version: 0.8.7
version: 0.8.8

synopsis: Derive a mock server for free from your servant API types
category: Servant, Web, Testing
Expand Down Expand Up @@ -43,8 +43,8 @@ library
base-compat >=0.10.5 && <0.12,
bytestring >=0.10.8.1 && <0.11,
http-types >=0.12.2 && <0.13,
servant >=0.17 && <0.19,
servant-server >=0.17 && <0.19,
servant >=0.17 && <0.20,
servant-server >=0.17 && <0.20,
transformers >=0.5.2.0 && <0.6,
QuickCheck >=2.12.6.1 && <2.14,
wai >=3.2.1.2 && <3.3
Expand Down
12 changes: 10 additions & 2 deletions src/Servant/Mock.hs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import Prelude.Compat
import Control.Monad.IO.Class
import Data.ByteString.Lazy.Char8 (pack)
import Data.Proxy
import Data.Typeable (Typeable)
import GHC.TypeLits
import Network.HTTP.Types.Status
import Network.Wai
Expand Down Expand Up @@ -118,10 +119,10 @@ instance (HasMock a context, HasMock b context) => HasMock (a :<|> b) context wh
instance (KnownSymbol path, HasMock rest context) => HasMock (path :> rest) context where
mock _ = mock (Proxy :: Proxy rest)

instance (KnownSymbol s, FromHttpApiData a, HasMock rest context, SBoolI (FoldLenient mods)) => HasMock (Capture' mods s a :> rest) context where
instance (KnownSymbol s, FromHttpApiData a, Typeable a, HasMock rest context, SBoolI (FoldLenient mods)) => HasMock (Capture' mods s a :> rest) context where
mock _ context = \_ -> mock (Proxy :: Proxy rest) context

instance (KnownSymbol s, FromHttpApiData a, HasMock rest context) => HasMock (CaptureAll s a :> rest) context where
instance (KnownSymbol s, FromHttpApiData a, Typeable a, HasMock rest context) => HasMock (CaptureAll s a :> rest) context where
mock _ context = \_ -> mock (Proxy :: Proxy rest) context

instance (AllCTUnrender ctypes a, HasMock rest context, SBoolI (FoldLenient mods))
Expand Down Expand Up @@ -226,6 +227,13 @@ instance ( HasContextEntry context (NamedContext name subContext)

mock _ _ = mock (Proxy :: Proxy rest) (Proxy :: Proxy subContext)

instance ( HasMock api context
, AtLeastOneFragment api
, FragmentUnique (Fragment a :> api)
) =>
HasMock (Fragment a :> api) context where
mock _ context = mock (Proxy :: Proxy api) context

mockArbitrary :: (MonadIO m, Arbitrary a) => m a
mockArbitrary = liftIO (generate arbitrary)

Expand Down

0 comments on commit f327a09

Please sign in to comment.