git.iko.soy/typeable/http-api-data
on master help sign in
Merge pull request #55 from phadej/ghc-8.2b
9c96c01Nickolay Kudasov
.travis.yml+5
@@ -35,12 +35,17 @@ matrix:
35 - compiler: "ghc-8.0.2"
35 - compiler: "ghc-8.0.2"
36 # env: TEST=--disable-tests BENCH=--disable-benchmarks
36 # env: TEST=--disable-tests BENCH=--disable-benchmarks
37 addons: {apt: {packages: [ghc-ppa-tools,cabal-install-head,ghc-8.0.2], sources: [hvr-ghc]}}
37 addons: {apt: {packages: [ghc-ppa-tools,cabal-install-head,ghc-8.0.2], sources: [hvr-ghc]}}
38+ - compiler: "ghc-8.2.1"
39+ env: CABALFLAGS="--allow-newer"
40+ # env: TEST=--disable-tests BENCH=--disable-benchmarks
41+ addons: {apt: {packages: [ghc-ppa-tools,cabal-install-head,ghc-8.2.1], sources: [hvr-ghc]}}
38 - compiler: "ghc-head"
42 - compiler: "ghc-head"
39 env: CABALFLAGS="--allow-newer"
43 env: CABALFLAGS="--allow-newer"
40 # env: TEST=--disable-tests BENCH=--disable-benchmarks
44 # env: TEST=--disable-tests BENCH=--disable-benchmarks
41 addons: {apt: {packages: [ghc-ppa-tools,cabal-install-head,ghc-head], sources: [hvr-ghc]}}
45 addons: {apt: {packages: [ghc-ppa-tools,cabal-install-head,ghc-head], sources: [hvr-ghc]}}
42
46
43 allow_failures:
47 allow_failures:
48+ - compiler: "ghc-8.2.1" # needs time-1.8.0.2
44 - compiler: "ghc-head"
49 - compiler: "ghc-head"
45
50
46before_install:
51before_install:
CHANGELOG.md+5
@@ -1,3 +1,8 @@
1+0.3.7.1
2+---
3+
4+* GHC-8.2 support
5+
10.3.7
60.3.7
2---
7---
3
8
Setup.lhs+19−148
@@ -1,165 +1,36 @@
1\begin{code}
1\begin{code}
2{-# LANGUAGE CPP #-}
2{-# LANGUAGE CPP #-}
3−#ifndef MIN_VERSION_Cabal
3+{-# OPTIONS_GHC -Wall #-}
4−#define MIN_VERSION_Cabal(x,y,z) 0
5−#endif
6−#ifndef MIN_VERSION_directory
7−#define MIN_VERSION_directory(x,y,z) 0
8−#endif
9−#if MIN_VERSION_Cabal(1,24,0)
10−#define InstalledPackageId UnitId
11−#endif
12module Main (main) where
4module Main (main) where
13
5
14−import Control.Monad ( when )
6+#ifndef MIN_VERSION_cabal_doctest
15−import Data.List ( nub )
7+#define MIN_VERSION_cabal_doctest(x,y,z) 0
16−import Distribution.Package ( InstalledPackageId )
17−import Distribution.Package ( PackageId, Package (..), packageVersion )
18−import Distribution.PackageDescription ( PackageDescription(), TestSuite(..) , Library (..), BuildInfo (..))
19−import Distribution.Simple ( defaultMainWithHooks, UserHooks(..), simpleUserHooks )
20−import Distribution.Simple.Utils ( rewriteFile, createDirectoryIfMissingVerbose )
21−import Distribution.Simple.BuildPaths ( autogenModulesDir )
22−import Distribution.Simple.Setup ( BuildFlags(buildDistPref, buildVerbosity), fromFlag)
23−import Distribution.Simple.LocalBuildInfo ( withPackageDB, withLibLBI, withTestLBI, LocalBuildInfo(), ComponentLocalBuildInfo(componentPackageDeps), compiler )
24−import Distribution.Simple.Compiler ( showCompilerId , PackageDB (..))
25−import Distribution.Text ( display , simpleParse )
26−import System.FilePath ( (</>) )
27−
28−#if MIN_VERSION_Cabal(1,25,0)
29−import Distribution.Simple.BuildPaths ( autogenComponentModulesDir )
30#endif
8#endif
31
9
32−#if MIN_VERSION_directory(1,2,2)
10+#if MIN_VERSION_cabal_doctest(1,0,0)
33−import System.Directory (makeAbsolute)
34−#else
35−import System.Directory (getCurrentDirectory)
36−import System.FilePath (isAbsolute)
37−
38−makeAbsolute :: FilePath -> IO FilePath
39−makeAbsolute p | isAbsolute p = return p
40− | otherwise = do
41− cwd <- getCurrentDirectory
42− return $ cwd </> p
43−#endif
44
11
12+import Distribution.Extra.Doctest ( defaultMainWithDoctests )
45main :: IO ()
13main :: IO ()
46−main = defaultMainWithHooks simpleUserHooks
14+main = defaultMainWithDoctests "doctests"
47− { buildHook = \pkg lbi hooks flags -> do
48− generateBuildModule flags pkg lbi
49− buildHook simpleUserHooks pkg lbi hooks flags
50− }
51−
52−generateBuildModule :: BuildFlags -> PackageDescription -> LocalBuildInfo -> IO ()
53−generateBuildModule flags pkg lbi = do
54− let verbosity = fromFlag (buildVerbosity flags)
55− let distPref = fromFlag (buildDistPref flags)
56−
57− -- Package DBs
58− let dbStack = withPackageDB lbi ++ [ SpecificPackageDB $ distPref </> "package.conf.inplace" ]
59− let dbFlags = "-hide-all-packages" : packageDbArgs dbStack
60−
61− withLibLBI pkg lbi $ \lib libcfg -> do
62− let libBI = libBuildInfo lib
63−
64− -- modules
65− let modules = exposedModules lib ++ otherModules libBI
66− -- it seems that doctest is happy to take in module names, not actual files!
67− let module_sources = modules
68
15
69− -- We need the directory with library's cabal_macros.h!
70−#if MIN_VERSION_Cabal(1,25,0)
71− let libAutogenDir = autogenComponentModulesDir lbi libcfg
72#else
16#else
73− let libAutogenDir = autogenModulesDir lbi
74−#endif
75−
76− -- Lib sources and includes
77− iArgs <- mapM (fmap ("-i"++) . makeAbsolute) $ libAutogenDir : hsSourceDirs libBI
78− includeArgs <- mapM (fmap ("-I"++) . makeAbsolute) $ includeDirs libBI
79−
80− -- CPP includes, i.e. include cabal_macros.h
81− let cppFlags = map ("-optP"++) $
82− [ "-include", libAutogenDir ++ "/cabal_macros.h" ]
83− ++ cppOptions libBI
84
17
85− -- Actually we need to check whether testName suite == "doctests"
18+#ifdef MIN_VERSION_Cabal
86− -- pending https://github.com/haskell/cabal/pull/4229 getting into GHC HEAD tree
19+-- If the macro is defined, we have new cabal-install,
87− withTestLBI pkg lbi $ \suite suitecfg -> when (testName suite == testName suite) $ do
20+-- but for some reason we don't have cabal-doctest in package-db
88−
21+--
89− -- get and create autogen dir
22+-- Probably we are running cabal sdist, when otherwise using new-build
90−#if MIN_VERSION_Cabal(1,25,0)
23+-- workflow
91− let testAutogenDir = autogenComponentModulesDir lbi suitecfg
24+#warning You are configuring this package without cabal-doctest installed. \
92−#else
25+ The doctests test-suite will not work as a result. \
93− let testAutogenDir = autogenModulesDir lbi
26+ To fix this, install cabal-doctest before configuring.
94#endif
27#endif
95− createDirectoryIfMissingVerbose verbosity True testAutogenDir
96
28
97− -- write autogen'd file
29+import Distribution.Simple
98− rewriteFile (testAutogenDir </> "Build_doctests.hs") $ unlines
99− [ "module Build_doctests where"
100− , ""
101− -- -package-id etc. flags
102− , "pkgs :: [String]"
103− , "pkgs = " ++ (show $ formatDeps $ testDeps libcfg suitecfg)
104− , ""
105− , "flags :: [String]"
106− , "flags = " ++ show (iArgs ++ includeArgs ++ dbFlags ++ cppFlags)
107− , ""
108− , "module_sources :: [String]"
109− , "module_sources = " ++ show (map display module_sources)
110− ]
111− where
112− -- we do this check in Setup, as then doctests don't need to depend on Cabal
113− isOldCompiler = maybe False id $ do
114− a <- simpleParse $ showCompilerId $ compiler lbi
115− b <- simpleParse "7.5"
116− return $ packageVersion (a :: PackageId) < b
117
30
118− formatDeps = map formatOne
31+main :: IO ()
119− formatOne (installedPkgId, pkgId)
32+main = defaultMain
120− -- The problem is how different cabal executables handle package databases
121− -- when doctests depend on the library
122− | packageId pkg == pkgId = "-package=" ++ display pkgId
123− | otherwise = "-package-id=" ++ display installedPkgId
124−
125− -- From Distribution.Simple.Program.GHC
126− packageDbArgs :: [PackageDB] -> [String]
127− packageDbArgs | isOldCompiler = packageDbArgsConf
128− | otherwise = packageDbArgsDb
129−
130− -- GHC <7.6 uses '-package-conf' instead of '-package-db'.
131− packageDbArgsConf :: [PackageDB] -> [String]
132− packageDbArgsConf dbstack = case dbstack of
133− (GlobalPackageDB:UserPackageDB:dbs) -> concatMap specific dbs
134− (GlobalPackageDB:dbs) -> ("-no-user-package-conf")
135− : concatMap specific dbs
136− _ -> ierror
137− where
138− specific (SpecificPackageDB db) = [ "-package-conf=" ++ db ]
139− specific _ = ierror
140− ierror = error $ "internal error: unexpected package db stack: "
141− ++ show dbstack
142−
143− -- GHC >= 7.6 uses the '-package-db' flag. See
144− -- https://ghc.haskell.org/trac/ghc/ticket/5977.
145− packageDbArgsDb :: [PackageDB] -> [String]
146− -- special cases to make arguments prettier in common scenarios
147− packageDbArgsDb dbstack = case dbstack of
148− (GlobalPackageDB:UserPackageDB:dbs)
149− | all isSpecific dbs -> concatMap single dbs
150− (GlobalPackageDB:dbs)
151− | all isSpecific dbs -> "-no-user-package-db"
152− : concatMap single dbs
153− dbs -> "-clear-package-db"
154− : concatMap single dbs
155− where
156− single (SpecificPackageDB db) = [ "-package-db=" ++ db ]
157− single GlobalPackageDB = [ "-global-package-db" ]
158− single UserPackageDB = [ "-user-package-db" ]
159− isSpecific (SpecificPackageDB _) = True
160− isSpecific _ = False
161
33
162−testDeps :: ComponentLocalBuildInfo -> ComponentLocalBuildInfo -> [(InstalledPackageId, PackageId)]
34+#endif
163−testDeps xs ys = nub $ componentPackageDeps xs ++ componentPackageDeps ys
164
35
165\end{code}
36\end{code}
http-api-data.cabal+6−8
@@ -1,5 +1,5 @@
1name: http-api-data
1name: http-api-data
2−version: 0.3.7
2+version: 0.3.7.1
3license: BSD3
3license: BSD3
4license-file: LICENSE
4license-file: LICENSE
5author: Nickolay Kudasov <nickolay.kudasov@gmail.com>
5author: Nickolay Kudasov <nickolay.kudasov@gmail.com>
@@ -24,10 +24,9 @@ tested-with:
24
24
25custom-setup
25custom-setup
26 setup-depends:
26 setup-depends:
27− base >= 4.7 && <4.10,
27+ base >= 4.7 && <4.11,
28− Cabal >= 1.18 && <1.26,
28+ Cabal >= 1.18 && <2.1,
29− filepath,
29+ cabal-doctest >=1.0.1 && <1.1
30− directory
31
30
32flag use-text-show
31flag use-text-show
33 description: Use text-show library for efficient ToHttpApiData implementations.
32 description: Use text-show library for efficient ToHttpApiData implementations.
@@ -37,7 +36,7 @@ flag use-text-show
37library
36library
38 hs-source-dirs: src/
37 hs-source-dirs: src/
39 include-dirs: include/
38 include-dirs: include/
40− build-depends: base >= 4.7 && < 4.10
39+ build-depends: base >= 4.7 && < 4.11
41 , attoparsec >= 0.13.0.1 && < 0.14
40 , attoparsec >= 0.13.0.1 && < 0.14
42 , attoparsec-iso8601 >= 1.0.0.0 && < 1.1
41 , attoparsec-iso8601 >= 1.0.0.0 && < 1.1
43 , bytestring
42 , bytestring
@@ -86,7 +85,6 @@ test-suite spec
86
85
87test-suite doctests
86test-suite doctests
88 ghc-options: -Wall
87 ghc-options: -Wall
89− build-tools: hsc2hs
90 build-depends:
88 build-depends:
91 base,
89 base,
92 directory >= 1.0,
90 directory >= 1.0,
@@ -94,7 +92,7 @@ test-suite doctests
94 filepath
92 filepath
95 default-language: Haskell2010
93 default-language: Haskell2010
96 hs-source-dirs: test
94 hs-source-dirs: test
97− main-is: DocTest.hs
95+ main-is: doctests.hs
98 type: exitcode-stdio-1.0
96 type: exitcode-stdio-1.0
99
97
100source-repository head
98source-repository head
test/DocTest.hscdeleted−58
@@ -1,58 +0,0 @@
1−{-# LANGUAGE CPP #-}
2−{-# LANGUAGE ForeignFunctionInterface #-}
3−-----------------------------------------------------------------------------
4−-- |
5−-- Module : Main (doctests)
6−-- Copyright : (C) 2012-14 Edward Kmett
7−-- License : BSD-style (see the file LICENSE)
8−-- Maintainer : Edward Kmett <ekmett@gmail.com>
9−-- Stability : provisional
10−-- Portability : portable
11−--
12−-- This module provides doctests for a project based on the actual versions
13−-- of the packages it was built with. It requires a corresponding Setup.lhs
14−-- to be added to the project
15−-----------------------------------------------------------------------------
16−module Main where
17−
18−import Build_doctests (flags, pkgs, module_sources)
19−#if __GLASGOW_HASKELL__ < 710
20−import Control.Applicative
21−#endif
22−import Data.Foldable (traverse_)
23−import Test.DocTest
24−
25−##if defined(mingw32_HOST_OS)
26−##if defined(i386_HOST_ARCH)
27−##define USE_CP
28−import Control.Applicative
29−import Control.Exception
30−import Foreign.C.Types
31−foreign import stdcall "windows.h SetConsoleCP" c_SetConsoleCP :: CUInt -> IO Bool
32−foreign import stdcall "windows.h GetConsoleCP" c_GetConsoleCP :: IO CUInt
33−##elif defined(x86_64_HOST_ARCH)
34−##define USE_CP
35−import Control.Applicative
36−import Control.Exception
37−import Foreign.C.Types
38−foreign import ccall "windows.h SetConsoleCP" c_SetConsoleCP :: CUInt -> IO Bool
39−foreign import ccall "windows.h GetConsoleCP" c_GetConsoleCP :: IO CUInt
40−##endif
41−##endif
42−
43−-- | Run in a modified codepage where we can print UTF-8 values on Windows.
44−withUnicode :: IO a -> IO a
45−##ifdef USE_CP
46−withUnicode m = do
47− cp <- c_GetConsoleCP
48− (c_SetConsoleCP 65001 >> m) `finally` c_SetConsoleCP cp
49−##else
50−withUnicode m = m
51−##endif
52−
53−main :: IO ()
54−main = withUnicode $ do
55− traverse_ putStrLn args
56− doctest args
57− where
58− args = flags ++ pkgs ++ module_sources
test/Web/Internal/HttpApiDataSpec.hs+11−5
@@ -27,15 +27,21 @@ import Web.Internal.HttpApiData
27
27
28import Web.Internal.TestInstances
28import Web.Internal.TestInstances
29
29
30−(<=>) :: Eq a => (a -> b) -> (b -> Either T.Text a) -> a -> Bool
30+(<=>) :: forall a b. (Show a, Show b, Eq a) => (a -> b) -> (b -> Either T.Text a) -> a -> Property
31−(f <=> g) x = g (f x) == Right x
31+(f <=> g) x = counterexample
32+ (show lhs' ++ " : " ++ show lhs ++ " /= " ++ show rhs)
33+ (lhs == rhs)
34+ where
35+ lhs' = f x
36+ lhs = g lhs' :: Either T.Text a
37+ rhs = Right x :: Either T.Text a
32
38
33−encodedUrlPieceProp :: ToHttpApiData a => a -> Bool
39+encodedUrlPieceProp :: ToHttpApiData a => a -> Property
34−encodedUrlPieceProp x = toLazyByteString (toEncodedUrlPiece (toUrlPiece x)) == toLazyByteString (toEncodedUrlPiece x)
40+encodedUrlPieceProp x = toLazyByteString (toEncodedUrlPiece (toUrlPiece x)) === toLazyByteString (toEncodedUrlPiece x)
35
41
36
42
37checkUrlPiece :: forall a. (Eq a, ToHttpApiData a, FromHttpApiData a, Show a, Arbitrary a) => Proxy a -> String -> Spec
43checkUrlPiece :: forall a. (Eq a, ToHttpApiData a, FromHttpApiData a, Show a, Arbitrary a) => Proxy a -> String -> Spec
38−checkUrlPiece _ name = prop name (toUrlPiece <=> parseUrlPiece :: a -> Bool)
44+checkUrlPiece _ name = prop name (toUrlPiece <=> parseUrlPiece :: a -> Property)
39
45
40-- | Check with given generator
46-- | Check with given generator
41checkUrlPiece' :: forall a. (Eq a, ToHttpApiData a, FromHttpApiData a, Show a) => Gen a -> String -> Spec
47checkUrlPiece' :: forall a. (Eq a, ToHttpApiData a, FromHttpApiData a, Show a) => Gen a -> String -> Spec
test/doctests.hsnew file+25
@@ -0,0 +1,25 @@
1+-----------------------------------------------------------------------------
2+-- |
3+-- Module : Main (doctests)
4+-- Copyright : (C) 2012-14 Edward Kmett
5+-- License : BSD-style (see the file LICENSE)
6+-- Maintainer : Edward Kmett <ekmett@gmail.com>
7+-- Stability : provisional
8+-- Portability : portable
9+--
10+-- This module provides doctests for a project based on the actual versions
11+-- of the packages it was built with. It requires a corresponding Setup.lhs
12+-- to be added to the project
13+-----------------------------------------------------------------------------
14+module Main where
15+
16+import Build_doctests (flags, pkgs, module_sources)
17+import Data.Foldable (traverse_)
18+import Test.DocTest
19+
20+main :: IO ()
21+main = do
22+ traverse_ putStrLn args
23+ doctest args
24+ where
25+ args = flags ++ pkgs ++ module_sources