Update to servant-0.15

This commit is contained in:
Oleg Grenrus 2019-02-09 19:50:52 +02:00
parent efb966aa04
commit aef56f17b0
8 changed files with 16114 additions and 132 deletions

1
.gitignore vendored
View file

@ -3,4 +3,5 @@
.cabal-sandbox/*
*dist/
*dist-newstyle/
.ghc.environment.*
.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
getEndpoint :: Proxy a -> Request -> Maybe ([Text], Method)
instance HasEndpoint EmptyAPI where
getEndpoint _ _ = Nothing
instance (HasEndpoint (a :: *), HasEndpoint (b :: *)) => HasEndpoint (a :<|> b) where
getEndpoint _ req =
getEndpoint (Proxy :: Proxy a) req `mplus`
@ -114,7 +117,7 @@ instance (KnownSymbol (path :: Symbol), HasEndpoint (sub :: *))
_ -> Nothing
instance (KnownSymbol (capture :: Symbol), HasEndpoint (sub :: *))
=> HasEndpoint (Capture capture a :> sub) where
=> HasEndpoint (Capture' mods capture a :> sub) where
getEndpoint _ req =
case pathInfo req of
_:ps -> do
@ -123,10 +126,16 @@ instance (KnownSymbol (capture :: Symbol), HasEndpoint (sub :: *))
return (p:end, method)
_ -> Nothing
instance HasEndpoint (sub :: *) => HasEndpoint (Header h a :> sub) where
instance HasEndpoint (sub :: *) => HasEndpoint (Summary d :> sub) where
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)
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
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)
instance HasEndpoint (sub :: *) => HasEndpoint (RemoteHost :> sub) where
@ -159,6 +171,12 @@ instance ReflectMethod method => HasEndpoint (Verb method status cts a) where
_ -> Nothing
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
getEndpoint _ _ = Just ([],"RAW")

15894
output.log Normal file

File diff suppressed because it is too large Load diff

View file

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

View file

@ -1,61 +1,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.
resolver: lts-13.6
packages:
- '.'
# Dependency packages to be pulled from upstream that are not in the resolver
# (e.g., acme-missiles-0.3)
extra-deps:
# Override default flag values for local packages and extra-deps
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
- ekg-0.4.0.15
- ekg-json-0.1.0.6

View file

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