git.iko.soy/typeable/http-api-data
on master help sign in
Support GHC-8.2.1
commit3a3720fbb1123c9202636fadcf7505d267323d04 authorOleg Grenrus <oleg.grenrus@iki.fi> dateSun 14 May 2017, 23:23 (9 years ago) parent5158283
7 files changed+71−219
.travis.yml+5 CHANGELOG.md+5 Setup.lhs+19−148 http-api-data.cabal+6−8 test/DocTest.hsc−58 test/Web/Internal/HttpApiDataSpec.hs+11−5 test/doctests.hs+25
.travis.yml+5
@@ -35,12 +35,17 @@ matrix:
3535 - compiler: "ghc-8.0.2"
3636 # env: TEST=--disable-tests BENCH=--disable-benchmarks
3737 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]}}
3842 - compiler: "ghc-head"
3943 env: CABALFLAGS="--allow-newer"
4044 # env: TEST=--disable-tests BENCH=--disable-benchmarks
4145 addons: {apt: {packages: [ghc-ppa-tools,cabal-install-head,ghc-head], sources: [hvr-ghc]}}
4246
4347 allow_failures:
48+ - compiler: "ghc-8.2.1" # needs time-1.8.0.2
4449 - compiler: "ghc-head"
4550
4651before_install:
CHANGELOG.md+5
@@ -1,3 +1,8 @@
1+0.3.7.1
2+---
3+
4+* GHC-8.2 support
5+
160.3.7
27---
38
Setup.lhs+19−148
@@ -1,165 +1,36 @@
11\begin{code}
22{-# LANGUAGE CPP #-}
3−#ifndef MIN_VERSION_Cabal
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
3+{-# OPTIONS_GHC -Wall #-}
124module Main (main) where
135
14−import Control.Monad ( when )
15−import Data.List ( nub )
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 )
6+#ifndef MIN_VERSION_cabal_doctest
7+#define MIN_VERSION_cabal_doctest(x,y,z) 0
308#endif
319
32−#if MIN_VERSION_directory(1,2,2)
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
10+#if MIN_VERSION_cabal_doctest(1,0,0)
4411
12+import Distribution.Extra.Doctest ( defaultMainWithDoctests )
4513main :: IO ()
46−main = defaultMainWithHooks simpleUserHooks
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
14+main = defaultMainWithDoctests "doctests"
6815
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
7216#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
8417
85− -- Actually we need to check whether testName suite == "doctests"
86− -- pending https://github.com/haskell/cabal/pull/4229 getting into GHC HEAD tree
87− withTestLBI pkg lbi $ \suite suitecfg -> when (testName suite == testName suite) $ do
88−
89− -- get and create autogen dir
90−#if MIN_VERSION_Cabal(1,25,0)
91− let testAutogenDir = autogenComponentModulesDir lbi suitecfg
92−#else
93− let testAutogenDir = autogenModulesDir lbi
18+#ifdef MIN_VERSION_Cabal
19+-- If the macro is defined, we have new cabal-install,
20+-- but for some reason we don't have cabal-doctest in package-db
21+--
22+-- Probably we are running cabal sdist, when otherwise using new-build
23+-- workflow
24+#warning You are configuring this package without cabal-doctest installed. \
25+ The doctests test-suite will not work as a result. \
26+ To fix this, install cabal-doctest before configuring.
9427#endif
95− createDirectoryIfMissingVerbose verbosity True testAutogenDir
9628
97− -- write autogen'd file
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
29+import Distribution.Simple
11730
118− formatDeps = map formatOne
119− formatOne (installedPkgId, pkgId)
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
31+main :: IO ()
32+main = defaultMain
16133
162−testDeps :: ComponentLocalBuildInfo -> ComponentLocalBuildInfo -> [(InstalledPackageId, PackageId)]
163−testDeps xs ys = nub $ componentPackageDeps xs ++ componentPackageDeps ys
34+#endif
16435
16536\end{code}
http-api-data.cabal+6−8
@@ -1,5 +1,5 @@
11name: http-api-data
2−version: 0.3.7
2+version: 0.3.7.1
33license: BSD3
44license-file: LICENSE
55author: Nickolay Kudasov <nickolay.kudasov@gmail.com>
@@ -24,10 +24,9 @@ tested-with:
2424
2525custom-setup
2626 setup-depends:
27− base >= 4.7 && <4.10,
28− Cabal >= 1.18 && <1.26,
29− filepath,
30− directory
27+ base >= 4.7 && <4.11,
28+ Cabal >= 1.18 && <2.1,
29+ cabal-doctest >=1.0.1 && <1.1
3130
3231flag use-text-show
3332 description: Use text-show library for efficient ToHttpApiData implementations.
@@ -37,7 +36,7 @@ flag use-text-show
3736library
3837 hs-source-dirs: src/
3938 include-dirs: include/
40− build-depends: base >= 4.7 && < 4.10
39+ build-depends: base >= 4.7 && < 4.11
4140 , attoparsec >= 0.13.0.1 && < 0.14
4241 , attoparsec-iso8601 >= 1.0.0.0 && < 1.1
4342 , bytestring
@@ -86,7 +85,6 @@ test-suite spec
8685
8786test-suite doctests
8887 ghc-options: -Wall
89− build-tools: hsc2hs
9088 build-depends:
9189 base,
9290 directory >= 1.0,
@@ -94,7 +92,7 @@ test-suite doctests
9492 filepath
9593 default-language: Haskell2010
9694 hs-source-dirs: test
97− main-is: DocTest.hs
95+ main-is: doctests.hs
9896 type: exitcode-stdio-1.0
9997
10098source-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
2727
2828import Web.Internal.TestInstances
2929
30−(<=>) :: Eq a => (a -> b) -> (b -> Either T.Text a) -> a -> Bool
31−(f <=> g) x = g (f x) == Right x
30+(<=>) :: forall a b. (Show a, Show b, Eq a) => (a -> b) -> (b -> Either T.Text a) -> a -> Property
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
3238
33−encodedUrlPieceProp :: ToHttpApiData a => a -> Bool
34−encodedUrlPieceProp x = toLazyByteString (toEncodedUrlPiece (toUrlPiece x)) == toLazyByteString (toEncodedUrlPiece x)
39+encodedUrlPieceProp :: ToHttpApiData a => a -> Property
40+encodedUrlPieceProp x = toLazyByteString (toEncodedUrlPiece (toUrlPiece x)) === toLazyByteString (toEncodedUrlPiece x)
3541
3642
3743checkUrlPiece :: 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)
3945
4046-- | Check with given generator
4147checkUrlPiece' :: 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