From 13664a218c54e24a5a64627867e3aa7adbeb5e0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Hahn?= Date: Mon, 27 Oct 2014 07:24:23 +0100 Subject: [PATCH] test suite: added initial test suite --- servant.cabal | 24 +++++++++++++++++++ test/Servant/ServerSpec.hs | 49 ++++++++++++++++++++++++++++++++++++++ test/Spec.hs | 1 + 3 files changed, 74 insertions(+) create mode 100644 test/Servant/ServerSpec.hs create mode 100644 test/Spec.hs diff --git a/servant.cabal b/servant.cabal index dcd2f797..342b3afe 100644 --- a/servant.cabal +++ b/servant.cabal @@ -60,3 +60,27 @@ executable greet , either , text , network-uri + +test-suite spec + type: exitcode-stdio-1.0 + ghc-options: + -Wall -Werror -fno-warn-name-shadowing -fno-warn-missing-signatures + default-language: Haskell2010 + hs-source-dirs: src, test + main-is: Spec.hs + build-depends: + base == 4.* + , aeson + , bytestring + , either + , exceptions + , hspec2 + , hspec-wai + , http-client + , http-types + , network-uri >= 2.6 + , string-conversions + , text + , transformers + , wai + , wai-extra diff --git a/test/Servant/ServerSpec.hs b/test/Servant/ServerSpec.hs new file mode 100644 index 00000000..a44e1363 --- /dev/null +++ b/test/Servant/ServerSpec.hs @@ -0,0 +1,49 @@ +{-# LANGUAGE DeriveGeneric #-} +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE QuasiQuotes #-} +{-# LANGUAGE ScopedTypeVariables #-} + +module Servant.ServerSpec where + + +import Data.Aeson +import Data.Proxy +import GHC.Generics +import Network.Wai.Test +import Test.Hspec +import Test.Hspec.Wai + +import Servant.API.Get +import Servant.Server + + +data Person = Person { + name :: String, + age :: Integer + } + deriving (Eq, Show, Generic) + +instance ToJSON Person +instance FromJSON Person + +alice :: Person +alice = Person "Alice" 103 + + +spec :: Spec +spec = do + getSpec + + +type GetApi = Get Person +getApi :: Proxy GetApi +getApi = Proxy + +getSpec = do + describe "Servant.API.Get" $ do + with (return (serve getApi (return alice))) $ do + it "serves a Person" $ do + response <- get "/" + return response `shouldRespondWith` 200 + liftIO $ do + decode' (simpleBody response) `shouldBe` Just alice diff --git a/test/Spec.hs b/test/Spec.hs new file mode 100644 index 00000000..a824f8c3 --- /dev/null +++ b/test/Spec.hs @@ -0,0 +1 @@ +{-# OPTIONS_GHC -F -pgmF hspec-discover #-}