Permalink
Browse files

Merge pull request #10 from phadej/doctest-0.11

Allow doctest-0.11
  • Loading branch information...
2 parents 3449990 + 59a5453 commit c02e943f7f3d0727bcbd63c6f954649eb021fbe1 @ekmett committed on GitHub Aug 29, 2016
Showing with 55 additions and 15 deletions.
  1. +45 −4 Setup.lhs
  2. +2 −2 hyphenation.cabal
  3. +8 −9 tests/doctests.hs
View
@@ -1,7 +1,48 @@
#!/usr/bin/runhaskell
-> module Main (main) where
+\begin{code}
+{-# OPTIONS_GHC -Wall #-}
+module Main (main) where
-> import Distribution.Simple
+import Data.List ( nub )
+import Data.Version ( showVersion )
+import Distribution.Package ( PackageName(PackageName), PackageId, InstalledPackageId, packageVersion, packageName )
+import Distribution.PackageDescription ( PackageDescription(), TestSuite(..) )
+import Distribution.Simple ( defaultMainWithHooks, UserHooks(..), simpleUserHooks )
+import Distribution.Simple.Utils ( rewriteFile, createDirectoryIfMissingVerbose )
+import Distribution.Simple.BuildPaths ( autogenModulesDir )
+import Distribution.Simple.Setup ( BuildFlags(buildVerbosity), fromFlag )
+import Distribution.Simple.LocalBuildInfo ( withLibLBI, withTestLBI, LocalBuildInfo(), ComponentLocalBuildInfo(componentPackageDeps) )
+import Distribution.Verbosity ( Verbosity )
+import System.FilePath ( (</>) )
-> main :: IO ()
-> main = defaultMain
+main :: IO ()
+main = defaultMainWithHooks simpleUserHooks
+ { buildHook = \pkg lbi hooks flags -> do
+ generateBuildModule (fromFlag (buildVerbosity flags)) pkg lbi
+ buildHook simpleUserHooks pkg lbi hooks flags
+ }
+
+generateBuildModule :: Verbosity -> PackageDescription -> LocalBuildInfo -> IO ()
+generateBuildModule verbosity pkg lbi = do
+ let dir = autogenModulesDir lbi
+ createDirectoryIfMissingVerbose verbosity True dir
+ withLibLBI pkg lbi $ \_ libcfg -> do
+ withTestLBI pkg lbi $ \suite suitecfg -> do
+ rewriteFile (dir </> "Build_" ++ testName suite ++ ".hs") $ unlines
+ [ "module Build_" ++ testName suite ++ " where"
+ , ""
+ , "autogen_dir :: String"
+ , "autogen_dir = " ++ show dir
+ , ""
+ , "deps :: [String]"
+ , "deps = " ++ (show $ formatdeps (testDeps libcfg suitecfg))
+ ]
+ where
+ formatdeps = map (formatone . snd)
+ formatone p = case packageName p of
+ PackageName n -> n ++ "-" ++ showVersion (packageVersion p)
+
+testDeps :: ComponentLocalBuildInfo -> ComponentLocalBuildInfo -> [(InstalledPackageId, PackageId)]
+testDeps xs ys = nub $ componentPackageDeps xs ++ componentPackageDeps ys
+
+\end{code}
View
@@ -29,7 +29,7 @@ description:
.
>>> hyphenate icelandic "va\240lahei\240avegavinnuverkf\230rageymslusk\250r"
["va\240la","hei\240a","vega","vinnu","verk","f\230ra","geymslu","sk\250r"]
-build-type: Simple
+build-type: Custom
data-dir: data
data-files: *.hyp.txt.gz, *.pat.txt.gz, *.lic.txt.gz, *.chr.txt.gz
@@ -79,7 +79,7 @@ test-suite doctests
base,
containers,
directory >= 1.0 && < 1.3,
- doctest >= 0.8 && < 0.10,
+ doctest >= 0.8 && < 0.12,
filepath >= 1.3 && < 1.5,
hyphenation,
unordered-containers
View
@@ -1,22 +1,21 @@
-{-# LANGUAGE CPP #-}
module Main where
-import Test.DocTest
-import System.Directory
-import System.FilePath
-#if __GLASGOW_HASKELL__ < 710
+import Build_doctests (autogen_dir, deps)
import Control.Applicative
-#endif
import Control.Monad
import Data.List
+import System.Directory
+import System.FilePath
+import Test.DocTest
main :: IO ()
main = getSources >>= \sources -> doctest $
"-isrc"
- : "-idist/build/autogen"
+ : ("-i" ++ autogen_dir)
: "-optP-include"
- : "-optPdist/build/autogen/cabal_macros.h"
- : sources
+ : ("-optP" ++ autogen_dir ++ "/cabal_macros.h")
+ : "-hide-all-packages"
+ : map ("-package="++) deps ++ sources
getSources :: IO [FilePath]
getSources = filter (isSuffixOf ".hs") <$> go "src"

0 comments on commit c02e943

Please sign in to comment.