packages feed

cabal-doctest 1.0.1 → 1.0.2

raw patch · 4 files changed

+87/−11 lines, 4 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Distribution.Extra.Doctest: addDoctestsUserHook :: String -> UserHooks -> UserHooks
+ Distribution.Extra.Doctest: defaultMainAutoconfWithDoctests :: String -> IO ()

Files

ChangeLog.md view
@@ -1,3 +1,12 @@+# 1.0.2 -- 2017-05-16++* Add `defaultMainAutoconfWithDoctests` and `addDoctestsUserHook`.++* Add support for `.hsc` and other preprocessed files+  ([#8](https://github.com/phadej/cabal-doctest/issues/8))++* Add support for `x-doctest-source-dirs` and `x-doctest-modules`.+ # 1.0.1 -- 2017-05-05  * Add support for `x-doctest-options` cabal-file field
README.md view
@@ -1,14 +1,17 @@ cabal-doctest--------------+=============  [![Hackage](https://img.shields.io/hackage/v/cabal-doctest.svg)](https://hackage.haskell.org/package/cabal-doctest) [![Build Status](https://travis-ci.org/phadej/cabal-doctest.svg?branch=master)](https://travis-ci.org/phadej/cabal-doctest)  A `Setup.hs` helper for running `doctests`.  Example Usage-=============+------------- -See [https://github.com/phadej/cabal-doctest/tree/master/example] for an example package.+See [https://github.com/phadej/cabal-doctest/tree/master/example] for an+example package. (Note that the example requires `Cabal-1.24` or later, but+you can relax this bound safely, although running doctests won't be supported+on versions of `Cabal` older than 1.24.)  To use this library in your `Setup.hs`, you should specify a `custom-setup` section in your `.cabal` file. For example:@@ -54,8 +57,30 @@     args = flags ++ pkgs ++ module_sources ``` +Additional configuration+------------------------++The `cabal-doctest` based `Setup.hs` supports few extensions fields+in `pkg.cabal` files to customise the `doctest` runner behaviour, without+customising the default `doctest.hs`.++```+test-suite doctests:+  if impl(ghc >= 8.0)+    x-doctest-options: -fdiagnostics-color=never+  x-doctest-source-dirs: test+  x-doctest-modules: Servant.Utils.LinksSpec++  ...+ ```++* `x-doctest-options` Additional arguments passed into `doctest` command.+* `x-doctest-modules` Additional modules to `doctest`. May be useful if you+  have `doctest` in test or executables (i.e not default library complonent).+* `x-doctest-src-dirs` Additional source directories to look for the modules.+ Notes-=====+-----  * `custom-setup` section is supported starting from `cabal-install-1.24`.   For older `cabal-install's` you have to install custom setup dependencies@@ -77,8 +102,15 @@ * You can use `x-doctest-options` field in `test-suite doctests` to   pass additional flags to the `doctest`. +* For `build-type: Configure` packages, you can use+  `defaultMainAutoconfWithDoctests` function to make custom `Setup.hs` script.++* If you use the default `.` in `hs-source-dirs`, then running `doctests`+  might fail with weird errors (ambigious module errors). Workaround is+  to move sources under `src/` or some non-top-level directory.+ Copyright-=========+---------  Copyright 2017 Oleg Grenrus. 
cabal-doctest.cabal view
@@ -1,5 +1,5 @@ name:                cabal-doctest-version:             1.0.1+version:             1.0.2 synopsis:            A Setup.hs helper for doctests running description:   Currently (beginning of 2017), there isn't @cabal doctest@
src/Distribution/Extra/Doctest.hs view
@@ -33,6 +33,8 @@ -- module Distribution.Extra.Doctest (     defaultMainWithDoctests,+    defaultMainAutoconfWithDoctests,+    addDoctestsUserHook,     doctestsUserHooks,     generateBuildModule,     ) where@@ -55,7 +57,7 @@ import Distribution.PackageDescription        (BuildInfo (..), Library (..), PackageDescription (), TestSuite (..)) import Distribution.Simple-       (UserHooks (..), defaultMainWithHooks, simpleUserHooks)+       (UserHooks (..), autoconfUserHooks, defaultMainWithHooks, simpleUserHooks) import Distribution.Simple.BuildPaths        (autogenModulesDir) import Distribution.Simple.Compiler@@ -111,14 +113,30 @@     -> IO () defaultMainWithDoctests = defaultMainWithHooks . doctestsUserHooks +-- | Like 'defaultMainWithDoctests', for 'build-type: Configure' packages.+--+-- @since 1.0.2+defaultMainAutoconfWithDoctests+    :: String  -- ^ doctests test-suite name+    -> IO ()+defaultMainAutoconfWithDoctests n =+    defaultMainWithHooks (addDoctestsUserHook n autoconfUserHooks)+ -- | 'simpleUserHooks' with 'generateBuildModule' prepended to the 'buildHook'. doctestsUserHooks     :: String  -- ^ doctests test-suite name     -> UserHooks-doctestsUserHooks testsuiteName = simpleUserHooks+doctestsUserHooks testsuiteName =+    addDoctestsUserHook testsuiteName simpleUserHooks++-- |+--+-- @since 1.0.2+addDoctestsUserHook :: String -> UserHooks -> UserHooks+addDoctestsUserHook testsuiteName uh = uh     { buildHook = \pkg lbi hooks flags -> do        generateBuildModule testsuiteName flags pkg lbi-       buildHook simpleUserHooks pkg lbi hooks flags+       buildHook uh pkg lbi hooks flags     }  -- | Generate a build module for the test suite.@@ -163,8 +181,13 @@ #endif      -- Lib sources and includes-    iArgs <- mapM (fmap ("-i"++) . makeAbsolute) $ libAutogenDir : hsSourceDirs libBI+    iArgs' <- mapM (fmap ("-i"++) . makeAbsolute)+        $ libAutogenDir            -- autogenerated files+        : (distPref ++ "/build")   -- preprocessed files (.hsc -> .hs); "build" is hardcoded in Cabal.+        : hsSourceDirs libBI     includeArgs <- mapM (fmap ("-I"++) . makeAbsolute) $ includeDirs libBI+    -- We clear all includes, so the CWD isn't used.+    let iArgs = "-i" : iArgs'      -- default-extensions     let extensionArgs = map (("-X"++) . display) $ defaultExtensions libBI@@ -176,11 +199,22 @@      withTestLBI pkg lbi $ \suite suitecfg -> when (testName suite == fromString testSuiteName) $ do       let testBI = testBuildInfo suite+       -- TODO: `words` is not proper parser (no support for quotes)       let additionalFlags = maybe [] words             $ lookup "x-doctest-options"             $ customFieldsBI testBI +      let additionalModules = maybe [] words+            $ lookup "x-doctest-modules"+            $ customFieldsBI testBI++      let additionalDirs' = maybe [] words+            $ lookup "x-doctest-source-dirs"+            $ customFieldsBI testBI+      additionalDirs <- mapM (fmap ("-i" ++) . makeAbsolute) additionalDirs'++       -- get and create autogen dir #if MIN_VERSION_Cabal(1,25,0)       let testAutogenDir = autogenComponentModulesDir lbi suitecfg@@ -200,6 +234,7 @@         , "flags :: [String]"         , "flags = " ++ show (concat           [ iArgs+          , additionalDirs           , includeArgs           , dbFlags           , cppFlags@@ -208,7 +243,7 @@           ])         , ""         , "module_sources :: [String]"-        , "module_sources = " ++ show (map display module_sources)+        , "module_sources = " ++ show (map display module_sources ++ additionalModules)         ]   where     -- we do this check in Setup, as then doctests don't need to depend on Cabal