Skip to content

Commit 800fcc1

Browse files
committed
Use cabal-doctest
1 parent ea5244f commit 800fcc1

File tree

3 files changed

+34
-48
lines changed

3 files changed

+34
-48
lines changed

Setup.lhs

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
\begin{code}
22
{-# LANGUAGE CPP #-}
33
{-# LANGUAGE OverloadedStrings #-}
4+
module Main (main) where
5+
6+
#ifndef MIN_VERSION_cabal_doctest
7+
#define MIN_VERSION_cabal_doctest(x,y,z) 0
8+
#endif
9+
10+
import Distribution.Simple ( defaultMainWithHooks, UserHooks(..), simpleUserHooks )
11+
12+
#if MIN_VERSION_cabal_doctest(1,0,0)
13+
import Distribution.Extra.Doctest ( generateBuildModule )
14+
#else
15+
16+
-- Otherwise we provide a shim
17+
418
#ifndef MIN_VERSION_Cabal
519
#define MIN_VERSION_Cabal(x,y,z) 0
620
#endif
@@ -10,14 +24,13 @@
1024
#if MIN_VERSION_Cabal(1,24,0)
1125
#define InstalledPackageId UnitId
1226
#endif
13-
module Main (main) where
1427
1528
import Control.Monad ( when )
1629
import Data.List ( nub )
30+
import Data.String ( fromString )
1731
import Distribution.Package ( InstalledPackageId )
1832
import Distribution.Package ( PackageId, Package (..), packageVersion )
1933
import Distribution.PackageDescription ( PackageDescription(), TestSuite(..) , Library (..), BuildInfo (..))
20-
import Distribution.Simple ( defaultMainWithHooks, UserHooks(..), simpleUserHooks )
2134
import Distribution.Simple.Utils ( rewriteFile, createDirectoryIfMissingVerbose )
2235
import Distribution.Simple.BuildPaths ( autogenModulesDir )
2336
import Distribution.Simple.Setup ( BuildFlags(buildDistPref, buildVerbosity), fromFlag)
@@ -43,15 +56,8 @@ makeAbsolute p | isAbsolute p = return p
4356
return $ cwd </> p
4457
#endif
4558
46-
main :: IO ()
47-
main = defaultMainWithHooks simpleUserHooks
48-
{ buildHook = \pkg lbi hooks flags -> do
49-
generateBuildModule flags pkg lbi
50-
buildHook simpleUserHooks pkg lbi hooks flags
51-
}
52-
53-
generateBuildModule :: BuildFlags -> PackageDescription -> LocalBuildInfo -> IO ()
54-
generateBuildModule flags pkg lbi = do
59+
generateBuildModule :: String -> BuildFlags -> PackageDescription -> LocalBuildInfo -> IO ()
60+
generateBuildModule testsuiteName flags pkg lbi = do
5561
let verbosity = fromFlag (buildVerbosity flags)
5662
let distPref = fromFlag (buildDistPref flags)
5763
@@ -83,7 +89,7 @@ generateBuildModule flags pkg lbi = do
8389
[ "-include", libAutogenDir ++ "/cabal_macros.h" ]
8490
++ cppOptions libBI
8591
86-
withTestLBI pkg lbi $ \suite suitecfg -> when (testName suite == "doctests") $ do
92+
withTestLBI pkg lbi $ \suite suitecfg -> when (testName suite == fromString testsuiteName) $ do
8793
8894
-- get and create autogen dir
8995
#if MIN_VERSION_Cabal(1,25,0)
@@ -160,5 +166,13 @@ generateBuildModule flags pkg lbi = do
160166
161167
testDeps :: ComponentLocalBuildInfo -> ComponentLocalBuildInfo -> [(InstalledPackageId, PackageId)]
162168
testDeps xs ys = nub $ componentPackageDeps xs ++ componentPackageDeps ys
169+
#endif
170+
171+
main :: IO ()
172+
main = defaultMainWithHooks simpleUserHooks
173+
{ buildHook = \pkg lbi hooks flags -> do
174+
generateBuildModule "doctests" flags pkg lbi
175+
buildHook simpleUserHooks pkg lbi hooks flags
176+
}
163177
164178
\end{code}

servant-swagger.cabal

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ source-repository head
3333
type: git
3434
location: https://github.com/haskell-servant/servant-swagger.git
3535

36+
custom-setup
37+
setup-depends:
38+
base >=4.7 && <4.10,
39+
Cabal >= 1.18 && <2.0,
40+
cabal-doctest >=1 && <1.1
41+
3642
library
3743
ghc-options: -Wall
3844
exposed-modules:
@@ -68,10 +74,9 @@ test-suite doctests
6874
build-depends:
6975
base,
7076
directory >= 1.0,
71-
doctest >= 0.11 && <0.12,
77+
doctest >= 0.11.1 && <0.12,
7278
servant >= 0.10,
7379
QuickCheck,
74-
lens-aeson,
7580
filepath
7681
default-language: Haskell2010
7782
hs-source-dirs: test

test/doctests.hsc

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
{-# LANGUAGE CPP #-}
2-
{-# LANGUAGE ForeignFunctionInterface #-}
31
-----------------------------------------------------------------------------
42
-- |
53
-- Module : Main (doctests)
@@ -16,42 +14,11 @@
1614
module Main where
1715

1816
import Build_doctests (flags, pkgs, module_sources)
19-
#if __GLASGOW_HASKELL__ < 710
20-
import Control.Applicative
21-
#endif
2217
import Data.Foldable (traverse_)
2318
import Test.DocTest
2419

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-
5320
main :: IO ()
54-
main = withUnicode $ do
21+
main = do
5522
traverse_ putStrLn args
5623
doctest args
5724
where

0 commit comments

Comments
 (0)