git.iko.soy/servant-quickcheck
on master help sign in
Support new CaptureAll combinator.
commit0337996c6c5a7c87762b61c648e0eefab0d5d950 authorJulian K. Arni <jkarni@gmail.com> dateWed 14 Sep 2016, 10:13 (10 years ago) parent9ff4375
5 files changed+28−5
.travis.yml+2−1 servant-quickcheck.cabal+5−1 src/Servant/QuickCheck/Internal/HasGenRequest.hs+15 stack-ghc-8.0.1.yaml+4−1 test/Servant/QuickCheck/InternalSpec.hs+2−2
.travis.yml+2−1
@@ -11,7 +11,7 @@ matrix:
1111
1212install:
1313 - (mkdir -p $HOME/.local/bin && cd $HOME/.local/bin && wget https://zalora-public.s3.amazonaws.com/tinc && chmod +x tinc)
14− - export PATH=/opt/ghc/$GHCVER/bin:/opt/cabal/1.22/bin:$PATH
14+ - export PATH=/opt/ghc/$GHCVER/bin:/opt/cabal/$CABALVER/bin:$PATH
1515 - ghc --version
1616 - cabal --version
1717 - travis_retry cabal update
@@ -19,6 +19,7 @@ install:
1919
2020script:
2121 - tinc && cabal configure --enable-tests && cabal build && cabal test
22+ - cabal check
2223
2324cache:
2425 directories:
servant-quickcheck.cabal+5−1
@@ -13,7 +13,11 @@ category: Web
1313build-type: Simple
1414cabal-version: >=1.10
1515extra-source-files:
16− CHANGELOG.md
16+ CHANGELOG.yaml
17+
18+source-repository head
19+ type: git
20+ location: https://github.com/haskell-servant/servant-quickcheck
1721
1822flag long-tests
1923 description: Run more QuickCheck tests
src/Servant/QuickCheck/Internal/HasGenRequest.hs+15
@@ -1,3 +1,4 @@
1+{-# LANGUAGE CPP #-}
12{-# LANGUAGE PolyKinds #-}
23module Servant.QuickCheck.Internal.HasGenRequest where
34
@@ -5,6 +6,7 @@ import Data.Default.Class (def)
56import Data.Monoid ((<>))
67import Data.String (fromString)
78import Data.String.Conversions (cs)
9+import qualified Data.ByteString as BS
810import GHC.TypeLits (KnownSymbol, Nat, symbolVal)
911import Network.HTTP.Client (Request, RequestBody (..), host, method, path,
1012 port, queryString, requestBody, requestHeaders,
@@ -44,6 +46,19 @@ instance (Arbitrary c, HasGenRequest b, ToHttpApiData c )
4446 old = genRequest (Proxy :: Proxy b)
4547 new = arbitrary :: Gen c
4648
49+#if MIN_VERSION_servant(0,8,0)
50+instance (Arbitrary c, HasGenRequest b, ToHttpApiData c )
51+ => HasGenRequest (CaptureAll x c :> b) where
52+ genRequest _ = do
53+ old' <- old
54+ new' <- fmap (cs . toUrlPiece) <$> new
55+ let new'' = BS.intercalate "/" new'
56+ return $ \burl -> let r = old' burl in r { path = new'' <> path r }
57+ where
58+ old = genRequest (Proxy :: Proxy b)
59+ new = arbitrary :: Gen [c]
60+#endif
61+
4762instance (Arbitrary c, KnownSymbol h, HasGenRequest b, ToHttpApiData c)
4863 => HasGenRequest (Header h c :> b) where
4964 genRequest _ = do
stack-ghc-8.0.1.yaml+4−1
@@ -2,6 +2,9 @@
22resolver: nightly-2016-09-07
33packages:
44- '.'
5−extra-deps: []
5+extra-deps:
6+- 'servant-0.8.1'
7+- 'servant-server-0.8.1'
8+- 'servant-client-0.8.1'
69flags: {}
710extra-package-dbs: []
test/Servant/QuickCheck/InternalSpec.hs+2−2
@@ -5,7 +5,7 @@ import Control.Concurrent.MVar (newMVar, readMVar, swapMVar)
55import Control.Monad.IO.Class (liftIO)
66import Prelude.Compat
77import Servant
8−import Servant.API.Internal.Test.ComprehensiveAPI (comprehensiveAPI)
8+import Servant.API.Internal.Test.ComprehensiveAPI (comprehensiveAPIWithoutRaw)
99import Test.Hspec (Spec, context, describe, it,
1010 shouldBe, shouldContain)
1111import Test.Hspec.Core.Spec (Arg, Example, Result (..),
@@ -81,7 +81,7 @@ isComprehensiveSpec :: Spec
8181isComprehensiveSpec = describe "HasGenRequest" $ do
8282
8383 it "has instances for all 'servant' combinators" $ do
84− let _g = genRequest comprehensiveAPI
84+ let _g = genRequest comprehensiveAPIWithoutRaw
8585 True `shouldBe` True -- This is a type-level check
8686
8787