Merge pull request #7 from haskell-servant/updates

Update to servant-0.15
This commit is contained in:
Oleg Grenrus 2019-02-11 19:39:47 +02:00 committed by GitHub
commit 8f5e9ad2bb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 16114 additions and 132 deletions

1
.gitignore vendored
View file

@ -3,4 +3,5 @@
.cabal-sandbox/* .cabal-sandbox/*
*dist/ *dist/
*dist-newstyle/ *dist-newstyle/
.ghc.environment.*
.stack-work/ .stack-work/

121
.travis.yml Normal file
View file

@ -0,0 +1,121 @@
# This Travis job script has been generated by a script via
#
# haskell-ci '--output=.travis.yml' '--branches=master' 'cabal.project'
#
# For more information, see https://github.com/haskell-CI/haskell-ci
#
language: c
dist: xenial
git:
submodules: false # whether to recursively clone submodules
branches:
only:
- master
cache:
directories:
- $HOME/.cabal/packages
- $HOME/.cabal/store
before_cache:
- rm -fv $HOME/.cabal/packages/hackage.haskell.org/build-reports.log
# remove files that are regenerated by 'cabal update'
- rm -fv $HOME/.cabal/packages/hackage.haskell.org/00-index.*
- rm -fv $HOME/.cabal/packages/hackage.haskell.org/*.json
- rm -fv $HOME/.cabal/packages/hackage.haskell.org/01-index.cache
- rm -fv $HOME/.cabal/packages/hackage.haskell.org/01-index.tar
- rm -fv $HOME/.cabal/packages/hackage.haskell.org/01-index.tar.idx
- rm -rfv $HOME/.cabal/packages/head.hackage
matrix:
include:
- compiler: "ghc-8.6.3"
# env: TEST=--disable-tests BENCH=--disable-benchmarks
addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-8.6.3], sources: [hvr-ghc]}}
- compiler: "ghc-8.4.4"
# env: TEST=--disable-tests BENCH=--disable-benchmarks
addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-8.4.4], sources: [hvr-ghc]}}
- compiler: "ghc-8.2.2"
# env: TEST=--disable-tests BENCH=--disable-benchmarks
addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-8.2.2], sources: [hvr-ghc]}}
- compiler: "ghc-8.0.2"
# env: TEST=--disable-tests BENCH=--disable-benchmarks
addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-8.0.2], sources: [hvr-ghc]}}
before_install:
- HC=${CC}
- HCPKG=${HC/ghc/ghc-pkg}
- unset CC
- ROOTDIR=$(pwd)
- mkdir -p $HOME/.local/bin
- "PATH=/opt/ghc/bin:/opt/ghc-ppa-tools/bin:$HOME/local/bin:$PATH"
- HCNUMVER=$(( $(${HC} --numeric-version|sed -E 's/([0-9]+)\.([0-9]+)\.([0-9]+).*/\1 * 10000 + \2 * 100 + \3/') ))
- echo $HCNUMVER
install:
- cabal --version
- echo "$(${HC} --version) [$(${HC} --print-project-git-commit-id 2> /dev/null || echo '?')]"
- BENCH=${BENCH---enable-benchmarks}
- TEST=${TEST---enable-tests}
- HADDOCK=${HADDOCK-true}
- UNCONSTRAINED=${UNCONSTRAINED-true}
- NOINSTALLEDCONSTRAINTS=${NOINSTALLEDCONSTRAINTS-false}
- GHCHEAD=${GHCHEAD-false}
- travis_retry cabal update -v
- "sed -i.bak 's/^jobs:/-- jobs:/' ${HOME}/.cabal/config"
- rm -fv cabal.project cabal.project.local
- grep -Ev -- '^\s*--' ${HOME}/.cabal/config | grep -Ev '^\s*$'
- "printf 'packages: \".\"\\n' > cabal.project"
- "printf 'write-ghc-environment-files: always\\n' >> cabal.project"
- "echo 'reorder-goals: True' >> cabal.project"
- "echo 'max-backjumps: 100' >> cabal.project"
- touch cabal.project.local
- "if ! $NOINSTALLEDCONSTRAINTS; then for pkg in $($HCPKG list --simple-output); do echo $pkg | grep -vw -- servant-ekg | sed 's/^/constraints: /' | sed 's/-[^-]*$/ installed/' >> cabal.project.local; done; fi"
- cat cabal.project || true
- cat cabal.project.local || true
- if [ -f "./configure.ac" ]; then
(cd "." && autoreconf -i);
fi
- rm -f cabal.project.freeze
- cabal new-build -w ${HC} ${TEST} ${BENCH} --project-file="cabal.project" --dep -j2 all
- cabal new-build -w ${HC} --disable-tests --disable-benchmarks --project-file="cabal.project" --dep -j2 all
- rm -rf .ghc.environment.* "."/dist
- DISTDIR=$(mktemp -d /tmp/dist-test.XXXX)
# Here starts the actual work to be performed for the package under test;
# any command which exits with a non-zero exit code causes the build to fail.
script:
# test that source-distributions can be generated
- cabal new-sdist all
- mv dist-newstyle/sdist/*.tar.gz ${DISTDIR}/
- cd ${DISTDIR} || false
- find . -maxdepth 1 -name '*.tar.gz' -exec tar -xvf '{}' \;
- "printf 'packages: servant-ekg-*/*.cabal\\n' > cabal.project"
- "printf 'write-ghc-environment-files: always\\n' >> cabal.project"
- "echo 'reorder-goals: True' >> cabal.project"
- "echo 'max-backjumps: 100' >> cabal.project"
- touch cabal.project.local
- "if ! $NOINSTALLEDCONSTRAINTS; then for pkg in $($HCPKG list --simple-output); do echo $pkg | grep -vw -- servant-ekg | sed 's/^/constraints: /' | sed 's/-[^-]*$/ installed/' >> cabal.project.local; done; fi"
- cat cabal.project || true
- cat cabal.project.local || true
# this builds all libraries and executables (without tests/benchmarks)
- cabal new-build -w ${HC} --disable-tests --disable-benchmarks all
# build & run tests, build benchmarks
- cabal new-build -w ${HC} ${TEST} ${BENCH} all
- if [ "x$TEST" = "x--enable-tests" ]; then cabal new-test -w ${HC} ${TEST} ${BENCH} all; fi
# cabal check
- (cd servant-ekg-* && cabal check)
# haddock
- if $HADDOCK; then cabal new-haddock -w ${HC} ${TEST} ${BENCH} all; else echo "Skipping haddock generation";fi
# Build without installed constraints for packages in global-db
- if $UNCONSTRAINED; then rm -f cabal.project.local; cabal new-build -w ${HC} --disable-tests --disable-benchmarks all; else echo "Not building without installed constraints"; fi
# REGENDATA ["--output=.travis.yml","--branches=master","cabal.project"]
# EOF

3
cabal.project Normal file
View file

@ -0,0 +1,3 @@
packages: .
reorder-goals: True
max-backjumps: 100

View file

@ -99,6 +99,9 @@ monitorEndpoints proxy store meters application request respond = do
class HasEndpoint a where class HasEndpoint a where
getEndpoint :: Proxy a -> Request -> Maybe ([Text], Method) getEndpoint :: Proxy a -> Request -> Maybe ([Text], Method)
instance HasEndpoint EmptyAPI where
getEndpoint _ _ = Nothing
instance (HasEndpoint (a :: *), HasEndpoint (b :: *)) => HasEndpoint (a :<|> b) where instance (HasEndpoint (a :: *), HasEndpoint (b :: *)) => HasEndpoint (a :<|> b) where
getEndpoint _ req = getEndpoint _ req =
getEndpoint (Proxy :: Proxy a) req `mplus` getEndpoint (Proxy :: Proxy a) req `mplus`
@ -114,7 +117,7 @@ instance (KnownSymbol (path :: Symbol), HasEndpoint (sub :: *))
_ -> Nothing _ -> Nothing
instance (KnownSymbol (capture :: Symbol), HasEndpoint (sub :: *)) instance (KnownSymbol (capture :: Symbol), HasEndpoint (sub :: *))
=> HasEndpoint (Capture capture a :> sub) where => HasEndpoint (Capture' mods capture a :> sub) where
getEndpoint _ req = getEndpoint _ req =
case pathInfo req of case pathInfo req of
_:ps -> do _:ps -> do
@ -123,10 +126,16 @@ instance (KnownSymbol (capture :: Symbol), HasEndpoint (sub :: *))
return (p:end, method) return (p:end, method)
_ -> Nothing _ -> Nothing
instance HasEndpoint (sub :: *) => HasEndpoint (Header h a :> sub) where instance HasEndpoint (sub :: *) => HasEndpoint (Summary d :> sub) where
getEndpoint _ = getEndpoint (Proxy :: Proxy sub) getEndpoint _ = getEndpoint (Proxy :: Proxy sub)
instance HasEndpoint (sub :: *) => HasEndpoint (QueryParam (h :: Symbol) a :> sub) where instance HasEndpoint (sub :: *) => HasEndpoint (Description d :> sub) where
getEndpoint _ = getEndpoint (Proxy :: Proxy sub)
instance HasEndpoint (sub :: *) => HasEndpoint (Header' mods h a :> sub) where
getEndpoint _ = getEndpoint (Proxy :: Proxy sub)
instance HasEndpoint (sub :: *) => HasEndpoint (QueryParam' mods (h :: Symbol) a :> sub) where
getEndpoint _ = getEndpoint (Proxy :: Proxy sub) getEndpoint _ = getEndpoint (Proxy :: Proxy sub)
instance HasEndpoint (sub :: *) => HasEndpoint (QueryParams (h :: Symbol) a :> sub) where instance HasEndpoint (sub :: *) => HasEndpoint (QueryParams (h :: Symbol) a :> sub) where
@ -135,7 +144,10 @@ instance HasEndpoint (sub :: *) => HasEndpoint (QueryParams (h :: Symbol) a :> s
instance HasEndpoint (sub :: *) => HasEndpoint (QueryFlag h :> sub) where instance HasEndpoint (sub :: *) => HasEndpoint (QueryFlag h :> sub) where
getEndpoint _ = getEndpoint (Proxy :: Proxy sub) getEndpoint _ = getEndpoint (Proxy :: Proxy sub)
instance HasEndpoint (sub :: *) => HasEndpoint (ReqBody cts a :> sub) where instance HasEndpoint (sub :: *) => HasEndpoint (ReqBody' mods cts a :> sub) where
getEndpoint _ = getEndpoint (Proxy :: Proxy sub)
instance HasEndpoint (sub :: *) => HasEndpoint (StreamBody' mods framing ct a :> sub) where
getEndpoint _ = getEndpoint (Proxy :: Proxy sub) getEndpoint _ = getEndpoint (Proxy :: Proxy sub)
instance HasEndpoint (sub :: *) => HasEndpoint (RemoteHost :> sub) where instance HasEndpoint (sub :: *) => HasEndpoint (RemoteHost :> sub) where
@ -159,6 +171,12 @@ instance ReflectMethod method => HasEndpoint (Verb method status cts a) where
_ -> Nothing _ -> Nothing
where method = reflectMethod (Proxy :: Proxy method) where method = reflectMethod (Proxy :: Proxy method)
instance ReflectMethod method => HasEndpoint (Stream method status framing ct a) where
getEndpoint _ req = case pathInfo req of
[] | requestMethod req == method -> Just ([], method)
_ -> Nothing
where method = reflectMethod (Proxy :: Proxy method)
instance HasEndpoint (Raw) where instance HasEndpoint (Raw) where
getEndpoint _ _ = Just ([],"RAW") getEndpoint _ _ = Just ([],"RAW")

15894
output.log Normal file

File diff suppressed because it is too large Load diff

View file

@ -1,14 +1,19 @@
cabal-version: >=1.10
name: servant-ekg name: servant-ekg
version: 0.2.0.0 version: 0.2.1.0
synopsis: Helpers for using ekg with servant synopsis: Helpers for using ekg with servant
description: Helpers for using ekg with servant description: Helpers for using ekg with servant, e.g.. counters per endpoint.
license: BSD3 license: BSD3
license-file: LICENSE license-file: LICENSE
author: Anchor Engineering <engineering@lists.anchor.net.au>, Servant Contributors author:
maintainer: Servant Contributors <haskell-servant-maintainers@googlegroups.com> Anchor Engineering <engineering@lists.anchor.net.au>, Servant Contributors
maintainer:
Servant Contributors <haskell-servant-maintainers@googlegroups.com>
category: System category: System
build-type: Simple build-type: Simple
cabal-version: >=1.10 tested-with: ghc ==8.0.2 || ==8.2.2 || ==8.4.4 || ==8.6.3
source-repository HEAD source-repository HEAD
type: git type: git
@ -17,14 +22,16 @@ source-repository HEAD
library library
exposed-modules: Servant.Ekg exposed-modules: Servant.Ekg
hs-source-dirs: lib hs-source-dirs: lib
build-depends: base >=4.7 && < 4.10 build-depends:
, ekg-core base >=4.9 && <4.13
, servant > 0.5 && < 0.10 , ekg-core >=0.1.1.6 && <0.2
, http-types , http-types >=0.12.2 && <0.13
, text , servant >=0.15 && <0.16
, time , text >=1.2.3.0 && <1.3
, unordered-containers , time >=1.6.0.1 && <1.9
, wai , unordered-containers >=0.2.9.0 && <0.3
, wai >=3.2.2 && <3.3
default-language: Haskell2010 default-language: Haskell2010
test-suite spec test-suite spec
@ -33,34 +40,38 @@ test-suite spec
default-language: Haskell2010 default-language: Haskell2010
hs-source-dirs: test hs-source-dirs: test
main-is: Spec.hs main-is: Spec.hs
build-depends: base == 4.* other-modules: Servant.EkgSpec
, aeson build-tool-depends: hspec-discover:hspec-discover
build-depends:
aeson
, base
, ekg , ekg
, ekg-core , ekg-core
, hspec >=2 && <3
, http-client
, servant
, servant-client
, servant-ekg , servant-ekg
, servant-server , servant-server
, servant-client
, servant
, http-client
, text , text
, wai
, warp >= 3.2.4 && < 3.3
, hspec == 2.*
, unordered-containers
, transformers , transformers
, unordered-containers
, wai
, warp >=3.2.4 && <3.3
executable bench executable bench
hs-source-dirs: bench hs-source-dirs: bench
main-is: Main.hs main-is: Main.hs
ghc-options: -Wall -threaded -O2 ghc-options: -Wall -threaded
default-language: Haskell2010 default-language: Haskell2010
build-depends: base == 4.* build-depends:
, aeson aeson
, base >=4 && <5
, ekg , ekg
, ekg-core , ekg-core
, process
, servant-ekg , servant-ekg
, servant-server , servant-server
, text , text
, wai , wai
, warp >= 3.2.4 && < 3.3 , warp >=3.2.4 && <3.3
, process

View file

@ -1,61 +1,6 @@
resolver: lts-13.6
# Resolver to choose a 'specific' stackage snapshot or a compiler version.
# A snapshot resolver dictates the compiler version and the set of packages
# to be used for project dependencies. For example:
#
# resolver: lts-3.5
# resolver: nightly-2015-09-21
# resolver: ghc-7.10.2
# resolver: ghcjs-0.1.0_ghc-7.10.2
# resolver:
# name: custom-snapshot
# location: "./custom-snapshot.yaml"
resolver: lts-7.18
# User packages to be built.
# Various formats can be used as shown in the example below.
#
# packages:
# - some-directory
# - https://example.com/foo/bar/baz-0.0.2.tar.gz
# - location:
# git: https://github.com/commercialhaskell/stack.git
# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a
# - location: https://github.com/commercialhaskell/stack/commit/e7b331f14bcffb8367cd58fbfc8b40ec7642100a
# extra-dep: true
# subdirs:
# - auto-update
# - wai
#
# A package marked 'extra-dep: true' will only be built if demanded by a
# non-dependency (i.e. a user package), and its test suites and benchmarks
# will not be run. This is useful for tweaking upstream packages.
packages: packages:
- '.' - '.'
# Dependency packages to be pulled from upstream that are not in the resolver
# (e.g., acme-missiles-0.3)
extra-deps: extra-deps:
- ekg-0.4.0.15
# Override default flag values for local packages and extra-deps - ekg-json-0.1.0.6
flags: {}
# Extra package databases containing global packages
extra-package-dbs: []
# Control whether we use the GHC we find on the path
# system-ghc: true
#
# Require a specific version of stack, using version ranges
# require-stack-version: -any # Default
# require-stack-version: ">=1.1"
#
# Override the architecture used by stack, especially useful on Windows
# arch: i386
# arch: x86_64
#
# Extra directories used by stack for building
# extra-include-dirs: [/path/to/dir]
# extra-lib-dirs: [/path/to/dir]
#
# Allow a newer minor version of GHC than the snapshot specifies
# compiler-check: newer-minor

View file

@ -9,21 +9,18 @@
module Servant.EkgSpec (spec) where module Servant.EkgSpec (spec) where
import Control.Concurrent import Control.Concurrent
#if !MIN_VERSION_servant(0,9,0)
import Control.Monad.Trans.Except
#endif
import Data.Aeson import Data.Aeson
import Data.Monoid import Data.Monoid
import Data.Proxy import Data.Proxy
import qualified Data.HashMap.Strict as H import qualified Data.HashMap.Strict as H
import Data.Text import Data.Text
import GHC.Generics import GHC.Generics
import Network.HTTP.Client (defaultManagerSettings, newManager, Manager) import Network.HTTP.Client (defaultManagerSettings, newManager)
import Network.Wai import Network.Wai
import Network.Wai.Handler.Warp import Network.Wai.Handler.Warp
import Servant import Servant
import Servant.Client import Servant.Client
import Servant.API.Internal.Test.ComprehensiveAPI (comprehensiveAPI) import Servant.Test.ComprehensiveAPI (comprehensiveAPI)
import System.Metrics import System.Metrics
import qualified System.Metrics.Counter as Counter import qualified System.Metrics.Counter as Counter
import Test.Hspec import Test.Hspec
@ -41,12 +38,8 @@ spec = describe "servant-ekg" $ do
it "collects number of request" $ do it "collects number of request" $ do
withApp $ \port mvar -> do withApp $ \port mvar -> do
mgr <- newManager defaultManagerSettings mgr <- newManager defaultManagerSettings
let runFn :: (Manager -> BaseUrl -> ExceptT e m a) -> m (Either e a) let runFn :: ClientM a -> IO (Either ServantError a)
#if MIN_VERSION_servant(0,9,0) runFn fn = runClientM fn (mkClientEnv mgr (BaseUrl Http "localhost" port ""))
runFn fn = runClientM $ fn mgr (ClientEnv mgr (BaseUrl Http "localhost" port ""))
#else
runFn fn = runExceptT $ fn mgr (BaseUrl Http "localhost" port "")
#endif
_ <- runFn $ getEp "name" Nothing _ <- runFn $ getEp "name" Nothing
_ <- runFn $ postEp (Greet "hi") _ <- runFn $ postEp (Greet "hi")
_ <- runFn $ deleteEp "blah" _ <- runFn $ deleteEp "blah"
@ -85,11 +78,7 @@ type TestApi =
:<|> "greet" :> ReqBody '[JSON] Greet :> Post '[JSON] Greet :<|> "greet" :> ReqBody '[JSON] Greet :> Post '[JSON] Greet
-- DELETE /greet/:greetid -- DELETE /greet/:greetid
#if MIN_VERSION_servant(0,8,0)
:<|> "greet" :> Capture "greetid" Text :> Delete '[JSON] NoContent :<|> "greet" :> Capture "greetid" Text :> Delete '[JSON] NoContent
#else
:<|> "greet" :> Capture "greetid" Text :> Delete '[JSON] ()
#endif
testApi :: Proxy TestApi testApi :: Proxy TestApi
testApi = Proxy testApi = Proxy