git.iko.soy/typeable/cabal2nix
on master help sign in
Use cabal-doctests to run the doctest suite.

Fixes https://github.com/NixOS/cabal2nix/issues/272.

commit1be933b51ea84f428d2c46ca8bbdf47a8aa9f7eb authorPeter Simons <simons@cryp.to> dateSun 2 Jul 2017, 11:08 (9 years ago) parent5c18fb5
5 files changed+57−47
Setup.hs+34 Setup.lhs−40 cabal2nix.cabal+9−3 package.yaml+7−1 test/doctests.hs+7−3
Setup.hsnew file+34
@@ -0,0 +1,34 @@
1+{-# LANGUAGE CPP #-}
2+{-# OPTIONS_GHC -Wall #-}
3+
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+#if MIN_VERSION_cabal_doctest(1,0,0)
11+
12+import Distribution.Extra.Doctest ( defaultMainWithDoctests )
13+main :: IO ()
14+main = defaultMainWithDoctests "doctests"
15+
16+#else
17+
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.
27+#endif
28+
29+import Distribution.Simple
30+
31+main :: IO ()
32+main = defaultMain
33+
34+#endif
Setup.lhsdeleted−40
@@ -1,40 +0,0 @@
1−#! /usr/bin/env runhaskell
2−
3−> module Main ( main ) where
4−>
5−> import Data.Char
6−> import Data.Maybe
7−> import Distribution.PackageDescription
8−> import Distribution.Simple
9−> import Distribution.Simple.LocalBuildInfo
10−> import Distribution.Simple.Program
11−> import Distribution.Simple.Setup
12−>
13−> main :: IO ()
14−> main = defaultMainWithHooks simpleUserHooks
15−> { hookedPrograms = map simpleProgram programs
16−> , confHook = configure
17−> }
18−>
19−> programs :: [String]
20−> programs = ["nix-instantiate", "nix-build", "nix-env", "nix-store"]
21−>
22−> configure :: (GenericPackageDescription, HookedBuildInfo) -> ConfigFlags -> IO LocalBuildInfo
23−> configure (gpd, hbi) flags = do
24−> lbi' <- confHook simpleUserHooks (gpd, hbi) flags
25−> let paths = map (\p -> (p, maybe p programPath (lookupProgram (simpleProgram p) (withPrograms lbi)))) programs
26−> descr = localPkgDescr lbi'
27−> lib = fromJust (library descr)
28−> libbi = libBuildInfo lib
29−> lbi = lbi' { localPkgDescr = descr
30−> { library = Just (lib { libBuildInfo = libbi { cppOptions = cppOptions libbi ++ map fmtCppArg paths } })
31−> }
32−> }
33−> return lbi
34−>
35−> fmtCppArg :: (String, FilePath) -> String
36−> fmtCppArg (prg, path) = "-DPATH_TO_" ++ map mangle prg ++ "=" ++ show path
37−> where
38−> mangle :: Char -> Char
39−> mangle '-' = '_'
40−> mangle c = toUpper c
cabal2nix.cabal+9−3
@@ -1,9 +1,9 @@
1−-- This file has been generated from package.yaml by hpack version 0.17.0.
1+-- This file has been generated from package.yaml by hpack version 0.18.1.
22--
33-- see: https://github.com/sol/hpack
44
55name: cabal2nix
6−version: 2.3
6+version: 2.3.1
77synopsis: Convert Cabal files into Nix build instructions.
88description: Convert Cabal files into Nix build instructions. Users of Nix can install the latest version by running:
99 .
@@ -67,7 +67,7 @@ maintainer: Peter Simons <simons@cryp.to>
6767license: BSD3
6868license-file: LICENSE
6969tested-with: GHC > 7.10 && < 8.1
70−build-type: Simple
70+build-type: Custom
7171cabal-version: >= 1.10
7272
7373extra-source-files:
@@ -77,6 +77,12 @@ source-repository head
7777 type: git
7878 location: https://github.com/nixos/cabal2nix
7979
80+custom-setup
81+ setup-depends:
82+ base >= 4 && <5
83+ , Cabal
84+ , cabal-doctest >= 1 && <1.1
85+
8086library
8187 hs-source-dirs:
8288 src
package.yaml+7−1
@@ -1,5 +1,5 @@
11name: cabal2nix
2−version: "2.3"
2+version: "2.3.1"
33synopsis: Convert Cabal files into Nix build instructions.
44author:
55 - Peter Simons
@@ -68,6 +68,12 @@ description: >
6868
6969 > nix-env -i cabal2nix
7070
71+custom-setup:
72+ dependencies:
73+ - base >= 4 && <5
74+ - Cabal
75+ - cabal-doctest >= 1 && <1.1
76+
7177ghc-options: -Wall
7278
7379extra-source-files:
test/doctests.hs+7−3
@@ -1,6 +1,10 @@
1−module Main ( main ) where
1+module Main where
22
3−import Test.DocTest
3+import Build_doctests (flags, pkgs, module_sources)
4+import Data.Foldable (traverse_)
5+import Test.DocTest (doctest)
46
57main :: IO ()
6−main = doctest ["src"]
8+main = do let args = flags ++ pkgs ++ module_sources
9+ traverse_ putStrLn args -- optionally print arguments
10+ doctest args