git.iko.soy/typeable/servant
on master help sign in
add ComprehensiveAPI to test whether we're missing instances
e5974ecSönke Hahn
servant-client/test/Servant/ClientSpec.hs+3
@@ -49,9 +49,12 @@ import Test.HUnit
49import Test.QuickCheck
49import Test.QuickCheck
50
50
51import Servant.API
51import Servant.API
52+import Servant.API.Internal.Test.ComprehensiveAPI
52import Servant.Client
53import Servant.Client
53import Servant.Server
54import Servant.Server
54
55
56+_ = client comprehensiveAPI
57+
55spec :: Spec
58spec :: Spec
56spec = describe "Servant.Client" $ do
59spec = describe "Servant.Client" $ do
57 sucessSpec
60 sucessSpec
servant-docs/test/Servant/DocsSpec.hs+17−1
@@ -1,7 +1,7 @@
1{-# LANGUAGE DataKinds #-}
1{-# LANGUAGE DataKinds #-}
2{-# LANGUAGE DeriveGeneric #-}
2{-# LANGUAGE DeriveGeneric #-}
3−{-# LANGUAGE FlexibleInstances #-}
4{-# LANGUAGE FlexibleContexts #-}
3{-# LANGUAGE FlexibleContexts #-}
4+{-# LANGUAGE FlexibleInstances #-}
5{-# LANGUAGE MultiParamTypeClasses #-}
5{-# LANGUAGE MultiParamTypeClasses #-}
6{-# LANGUAGE OverloadedStrings #-}
6{-# LANGUAGE OverloadedStrings #-}
7{-# LANGUAGE TypeOperators #-}
7{-# LANGUAGE TypeOperators #-}
@@ -18,8 +18,24 @@ import GHC.Generics
18import Test.Hspec
18import Test.Hspec
19
19
20import Servant.API
20import Servant.API
21+import Servant.API.Internal.Test.ComprehensiveAPI
21import Servant.Docs.Internal
22import Servant.Docs.Internal
22
23
24+-- * comprehensive api
25+
26+_ = docs comprehensiveAPI
27+
28+instance ToParam (QueryParam "foo" Int) where
29+ toParam = error "unused"
30+instance ToParam (QueryParams "foo" Int) where
31+ toParam = error "unused"
32+instance ToParam (QueryFlag "foo") where
33+ toParam = error "unused"
34+instance ToCapture (Capture "foo" Int) where
35+ toCapture = error "unused"
36+
37+-- * specs
38+
23spec :: Spec
39spec :: Spec
24spec = describe "Servant.Docs" $ do
40spec = describe "Servant.Docs" $ do
25
41
servant-js/test/Servant/JSSpec.hs+7
@@ -21,6 +21,7 @@ import qualified Data.Text as T
21import Language.ECMAScript3.Parser (program, parse)
21import Language.ECMAScript3.Parser (program, parse)
22import Test.Hspec hiding (shouldContain, shouldNotContain)
22import Test.Hspec hiding (shouldContain, shouldNotContain)
23
23
24+import Servant.API.Internal.Test.ComprehensiveAPI
24import Servant.JS
25import Servant.JS
25import Servant.JS.Internal
26import Servant.JS.Internal
26import qualified Servant.JS.Angular as NG
27import qualified Servant.JS.Angular as NG
@@ -29,6 +30,12 @@ import qualified Servant.JS.JQuery as JQ
29import qualified Servant.JS.Vanilla as JS
30import qualified Servant.JS.Vanilla as JS
30import Servant.JSSpec.CustomHeaders
31import Servant.JSSpec.CustomHeaders
31
32
33+-- * comprehensive api
34+
35+_ = (jsForAPI comprehensiveAPI vanillaJS :: Text)
36+
37+-- * specs
38+
32type TestAPI = "simple" :> ReqBody '[JSON,FormUrlEncoded] Text :> Post '[JSON] Bool
39type TestAPI = "simple" :> ReqBody '[JSON,FormUrlEncoded] Text :> Post '[JSON] Bool
33 :<|> "has.extension" :> Get '[FormUrlEncoded,JSON] Bool
40 :<|> "has.extension" :> Get '[FormUrlEncoded,JSON] Bool
34
41
servant-mock/servant-mock.cabal+15
@@ -45,3 +45,18 @@ executable mock-app
45 buildable: True
45 buildable: True
46 else
46 else
47 buildable: False
47 buildable: False
48+
49+test-suite spec
50+ type: exitcode-stdio-1.0
51+ ghc-options:
52+ -Wall -fno-warn-name-shadowing
53+ default-language: Haskell2010
54+ hs-source-dirs: test
55+ main-is: Spec.hs
56+ other-modules:
57+ Servant.MockSpec
58+ build-depends:
59+ base,
60+ hspec,
61+ servant,
62+ servant-mock
servant-mock/test/Servant/MockSpec.hsnew file+12
@@ -0,0 +1,12 @@
1+
2+module Servant.MockSpec where
3+
4+import Test.Hspec
5+
6+import Servant.API.Internal.Test.ComprehensiveAPI
7+import Servant.Mock
8+
9+_ = mock comprehensiveAPI
10+
11+spec :: Spec
12+spec = return ()
servant-mock/test/Spec.hsnew file+1
@@ -0,0 +1 @@
1+{-# OPTIONS_GHC -F -pgmF hspec-discover #-}
servant-server/test/Servant/ServerSpec.hs+4
@@ -46,6 +46,7 @@ import Servant.API ((:<|>) (..), (:>), Capture, Delete,
46 QueryFlag, QueryParam, QueryParams,
46 QueryFlag, QueryParam, QueryParams,
47 Raw, RemoteHost, ReqBody,
47 Raw, RemoteHost, ReqBody,
48 StdMethod (..), Verb, addHeader)
48 StdMethod (..), Verb, addHeader)
49+import Servant.API.Internal.Test.ComprehensiveAPI
49import Servant.Server (ServantErr (..), Server, err404,
50import Servant.Server (ServantErr (..), Server, err404,
50 serve)
51 serve)
51import Test.Hspec (Spec, context, describe, it,
52import Test.Hspec (Spec, context, describe, it,
@@ -60,6 +61,9 @@ import Servant.Server.Internal.Router
60 (tweakResponse, runRouter,
61 (tweakResponse, runRouter,
61 Router, Router'(LeafRouter))
62 Router, Router'(LeafRouter))
62
63
64+-- * comprehensive api test
65+
66+_ = serve comprehensiveAPI (error "unused") (error "unused")
63
67
64-- * Specs
68-- * Specs
65
69
servant/servant.cabal+1
@@ -31,6 +31,7 @@ library
31 Servant.API.ContentTypes
31 Servant.API.ContentTypes
32 Servant.API.Header
32 Servant.API.Header
33 Servant.API.HttpVersion
33 Servant.API.HttpVersion
34+ Servant.API.Internal.Test.ComprehensiveAPI
34 Servant.API.IsSecure
35 Servant.API.IsSecure
35 Servant.API.QueryParam
36 Servant.API.QueryParam
36 Servant.API.Raw
37 Servant.API.Raw
servant/src/Servant/API/Internal/Test/ComprehensiveAPI.hsnew file+32
@@ -0,0 +1,32 @@
1+{-# LANGUAGE DataKinds #-}
2+{-# LANGUAGE TypeOperators #-}
3+
4+module Servant.API.Internal.Test.ComprehensiveAPI where
5+
6+import Data.Proxy
7+
8+import Servant.API
9+
10+type GET = Get '[JSON] ()
11+
12+type ComprehensiveAPI =
13+ GET :<|>
14+ Get '[JSON] Int :<|>
15+ Capture "foo" Int :> GET :<|>
16+ Header "foo" Int :> GET :<|>
17+-- HttpVersion :> GET :<|>
18+ IsSecure :> GET :<|>
19+ QueryParam "foo" Int :> GET :<|>
20+ QueryParams "foo" Int :> GET :<|>
21+ QueryFlag "foo" :> GET :<|>
22+-- Raw :<|>
23+-- RemoteHost :<|>
24+ ReqBody '[JSON] Int :> GET :<|>
25+-- Get '[JSON] (Headers '[Header "foo" Int] ()) :<|>
26+ "foo" :> GET :<|>
27+ Vault :> GET :<|>
28+ Verb 'POST 204 '[JSON] () :<|>
29+ Verb 'POST 204 '[JSON] Int
30+
31+comprehensiveAPI :: Proxy ComprehensiveAPI
32+comprehensiveAPI = Proxy