Compare commits

...

4 commits

Author SHA1 Message Date
Oleg Grenrus
3bcb0a5a42 fixup! Resolve #698: sometimes we trigger custom type error 2017-02-13 10:28:23 +02:00
Oleg Grenrus
32fe5354ae Add stack-ghc-8.0.2.yaml 2017-02-12 22:20:37 +02:00
Oleg Grenrus
9bc4de6906 Use cabal-doctest 2017-02-12 22:12:03 +02:00
Oleg Grenrus
60716b10f3 Resolve #698: sometimes we trigger custom type error 2017-02-12 21:57:53 +02:00
7 changed files with 84 additions and 78 deletions

View file

@ -6,6 +6,7 @@ env:
- STACK_YAML=stack-ghc-7.8.4.yaml - STACK_YAML=stack-ghc-7.8.4.yaml
- STACK_YAML=stack.yaml - STACK_YAML=stack.yaml
- STACK_YAML=stack-ghc-8.0.1.yaml - STACK_YAML=stack-ghc-8.0.1.yaml
- STACK_YAML=stack-ghc-8.0.2.yaml
addons: addons:
apt: apt:

View file

@ -1,5 +1,19 @@
\begin{code} \begin{code}
{-# LANGUAGE CPP #-} {-# LANGUAGE CPP #-}
{-# LANGUAGE OverloadedStrings #-}
module Main (main) where
#ifndef MIN_VERSION_cabal_doctest
#define MIN_VERSION_cabal_doctest(x,y,z) 0
#endif
#if MIN_VERSION_cabal_doctest(1,0,0)
import Distribution.Extra.Doctest ( defaultMainWithDoctests )
#else
-- Otherwise we provide a shim
#ifndef MIN_VERSION_Cabal #ifndef MIN_VERSION_Cabal
#define MIN_VERSION_Cabal(x,y,z) 0 #define MIN_VERSION_Cabal(x,y,z) 0
#endif #endif
@ -9,10 +23,10 @@
#if MIN_VERSION_Cabal(1,24,0) #if MIN_VERSION_Cabal(1,24,0)
#define InstalledPackageId UnitId #define InstalledPackageId UnitId
#endif #endif
module Main (main) where
import Control.Monad ( when ) import Control.Monad ( when )
import Data.List ( nub ) import Data.List ( nub )
import Data.String ( fromString )
import Distribution.Package ( InstalledPackageId ) import Distribution.Package ( InstalledPackageId )
import Distribution.Package ( PackageId, Package (..), packageVersion ) import Distribution.Package ( PackageId, Package (..), packageVersion )
import Distribution.PackageDescription ( PackageDescription(), TestSuite(..) , Library (..), BuildInfo (..)) import Distribution.PackageDescription ( PackageDescription(), TestSuite(..) , Library (..), BuildInfo (..))
@ -42,15 +56,8 @@ makeAbsolute p | isAbsolute p = return p
return $ cwd </> p return $ cwd </> p
#endif #endif
main :: IO () generateBuildModule :: String -> BuildFlags -> PackageDescription -> LocalBuildInfo -> IO ()
main = defaultMainWithHooks simpleUserHooks generateBuildModule testsuiteName flags pkg lbi = do
{ buildHook = \pkg lbi hooks flags -> do
generateBuildModule flags pkg lbi
buildHook simpleUserHooks pkg lbi hooks flags
}
generateBuildModule :: BuildFlags -> PackageDescription -> LocalBuildInfo -> IO ()
generateBuildModule flags pkg lbi = do
let verbosity = fromFlag (buildVerbosity flags) let verbosity = fromFlag (buildVerbosity flags)
let distPref = fromFlag (buildDistPref flags) let distPref = fromFlag (buildDistPref flags)
@ -74,7 +81,7 @@ generateBuildModule flags pkg lbi = do
#endif #endif
-- Lib sources and includes -- Lib sources and includes
iArgs <- mapM (fmap ("-i"++) . makeAbsolute) $ "test" : libAutogenDir : hsSourceDirs libBI iArgs <- mapM (fmap ("-i"++) . makeAbsolute) $ libAutogenDir : hsSourceDirs libBI
includeArgs <- mapM (fmap ("-I"++) . makeAbsolute) $ includeDirs libBI includeArgs <- mapM (fmap ("-I"++) . makeAbsolute) $ includeDirs libBI
-- CPP includes, i.e. include cabal_macros.h -- CPP includes, i.e. include cabal_macros.h
@ -82,9 +89,7 @@ generateBuildModule flags pkg lbi = do
[ "-include", libAutogenDir ++ "/cabal_macros.h" ] [ "-include", libAutogenDir ++ "/cabal_macros.h" ]
++ cppOptions libBI ++ cppOptions libBI
-- Actually we need to check whether testName suite == "doctests" withTestLBI pkg lbi $ \suite suitecfg -> when (testName suite == fromString testsuiteName) $ do
-- pending https://github.com/haskell/cabal/pull/4229 getting into GHC HEAD tree
withTestLBI pkg lbi $ \suite suitecfg -> when (testName suite == "doctests") $ do
-- get and create autogen dir -- get and create autogen dir
#if MIN_VERSION_Cabal(1,25,0) #if MIN_VERSION_Cabal(1,25,0)
@ -106,7 +111,7 @@ generateBuildModule flags pkg lbi = do
, "flags = " ++ show (iArgs ++ includeArgs ++ dbFlags ++ cppFlags) , "flags = " ++ show (iArgs ++ includeArgs ++ dbFlags ++ cppFlags)
, "" , ""
, "module_sources :: [String]" , "module_sources :: [String]"
, "module_sources = " ++ show ("Servant.Utils.LinksSpec" : map display module_sources) , "module_sources = " ++ show (map display module_sources)
] ]
where where
-- we do this check in Setup, as then doctests don't need to depend on Cabal -- we do this check in Setup, as then doctests don't need to depend on Cabal
@ -162,4 +167,16 @@ generateBuildModule flags pkg lbi = do
testDeps :: ComponentLocalBuildInfo -> ComponentLocalBuildInfo -> [(InstalledPackageId, PackageId)] testDeps :: ComponentLocalBuildInfo -> ComponentLocalBuildInfo -> [(InstalledPackageId, PackageId)]
testDeps xs ys = nub $ componentPackageDeps xs ++ componentPackageDeps ys testDeps xs ys = nub $ componentPackageDeps xs ++ componentPackageDeps ys
defaultMainWithDoctests :: String -> IO ()
defaultMainWithDoctests testSuiteName = defaultMainWithHooks simpleUserHooks
{ buildHook = \pkg lbi hooks flags -> do
generateBuildModule testSuiteName flags pkg lbi
buildHook simpleUserHooks pkg lbi hooks flags
}
#endif
main :: IO ()
main = defaultMainWithDoctests "doctests"
\end{code} \end{code}

View file

@ -27,7 +27,7 @@ source-repository head
custom-setup custom-setup
setup-depends: setup-depends:
Cabal >=1.14, base, filepath, directory Cabal >=1.14, base, cabal-doctest
library library
exposed-modules: exposed-modules:
@ -134,7 +134,7 @@ test-suite spec
test-suite doctests test-suite doctests
build-depends: base build-depends: base
, servant , servant
, doctest , doctest >=0.11.0 && <0.12
, filemanip , filemanip
, directory , directory
, filepath , filepath
@ -144,5 +144,4 @@ test-suite doctests
buildable: True buildable: True
default-language: Haskell2010 default-language: Haskell2010
ghc-options: -Wall -threaded ghc-options: -Wall -threaded
build-tools: hsc2hs
include-dirs: include include-dirs: include

View file

@ -83,7 +83,7 @@ spec = describe "Servant.Utils.Links" $ do
-- --
-- >>> apiLink (Proxy :: Proxy WrongContentType) -- >>> apiLink (Proxy :: Proxy WrongContentType)
-- ... -- ...
-- ...Could not deduce... -- ...interactive...
-- ... -- ...
-- --
-- >>> apiLink (Proxy :: Proxy WrongMethod) -- >>> apiLink (Proxy :: Proxy WrongMethod)

39
servant/test/doctests.hs Normal file
View file

@ -0,0 +1,39 @@
-----------------------------------------------------------------------------
-- |
-- Module : Main (doctests)
-- Copyright : (C) 2012-14 Edward Kmett
-- License : BSD-style (see the file LICENSE)
-- Maintainer : Edward Kmett <ekmett@gmail.com>
-- Stability : provisional
-- Portability : portable
--
-- This module provides doctests for a project based on the actual versions
-- of the packages it was built with. It requires a corresponding Setup.lhs
-- to be added to the project
-----------------------------------------------------------------------------
module Main where
import Build_doctests (flags, pkgs, module_sources)
import Data.Foldable (traverse_)
import Data.List (isPrefixOf, isSuffixOf)
import Test.DocTest
main :: IO ()
main = do
traverse_ putStrLn args
doctest args
where
args =
"-XOverloadedStrings" :
"-XFlexibleInstances" :
"-XMultiParamTypeClasses" :
flags ++ flags' ++ pkgs ++
"Servant.Utils.LinksSpec" :
module_sources
-- HACK: find -i.../src, and change it ot -i.../test
flags'
= map (\x -> take (length x - 4) x ++ "/test")
. filter (\x -> "-i" `isPrefixOf` x && "/src" `isSuffixOf` x)
$ flags

View file

@ -1,59 +0,0 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE ForeignFunctionInterface #-}
-----------------------------------------------------------------------------
-- |
-- Module : Main (doctests)
-- Copyright : (C) 2012-14 Edward Kmett
-- License : BSD-style (see the file LICENSE)
-- Maintainer : Edward Kmett <ekmett@gmail.com>
-- Stability : provisional
-- Portability : portable
--
-- This module provides doctests for a project based on the actual versions
-- of the packages it was built with. It requires a corresponding Setup.lhs
-- to be added to the project
-----------------------------------------------------------------------------
module Main where
import Build_doctests (flags, pkgs, module_sources)
import Data.Foldable (traverse_)
import Test.DocTest
##if defined(mingw32_HOST_OS)
##if defined(i386_HOST_ARCH)
##define USE_CP
import Control.Applicative
import Control.Exception
import Foreign.C.Types
foreign import stdcall "windows.h SetConsoleCP" c_SetConsoleCP :: CUInt -> IO Bool
foreign import stdcall "windows.h GetConsoleCP" c_GetConsoleCP :: IO CUInt
##elif defined(x86_64_HOST_ARCH)
##define USE_CP
import Control.Applicative
import Control.Exception
import Foreign.C.Types
foreign import ccall "windows.h SetConsoleCP" c_SetConsoleCP :: CUInt -> IO Bool
foreign import ccall "windows.h GetConsoleCP" c_GetConsoleCP :: IO CUInt
##endif
##endif
-- | Run in a modified codepage where we can print UTF-8 values on Windows.
withUnicode :: IO a -> IO a
##ifdef USE_CP
withUnicode m = do
cp <- c_GetConsoleCP
(c_SetConsoleCP 65001 >> m) `finally` c_SetConsoleCP cp
##else
withUnicode m = m
##endif
main :: IO ()
main = withUnicode $ do
traverse_ putStrLn args
doctest args
where
args =
"-XOverloadedStrings" :
"-XFlexibleInstances" :
"-XMultiParamTypeClasses" :
flags ++ pkgs ++ module_sources

9
stack-ghc-8.0.2.yaml Normal file
View file

@ -0,0 +1,9 @@
resolver: nightly-2017-02-11
packages:
- servant/
- servant-client/
- servant-docs/
- servant-foreign/
- servant-server/
- doc/tutorial
extra-deps: []