Skip to content

Commit 5f9bdc5

Browse files
committed
Add test.
1 parent 659d80f commit 5f9bdc5

File tree

6 files changed

+143
-0
lines changed

6 files changed

+143
-0
lines changed

test/cabal-doctests/Doctests.hs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module Main where
2+
3+
import Build_doctests (flags, pkgs, module_sources)
4+
import Data.Foldable (traverse_)
5+
import System.Environment (unsetEnv)
6+
import Test.DocTest (doctest)
7+
8+
main :: IO ()
9+
main = do
10+
putStrLn ""
11+
traverse_ putStrLn args -- optionally print arguments
12+
unsetEnv "GHC_ENVIRONMENT" -- see 'Notes'; you may not need this
13+
doctest args
14+
where
15+
args :: [String]
16+
args = flags ++ pkgs ++ module_sources -- ++ ["-v"]

test/cabal-doctests/Lib.hs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module Lib
2+
( someFunc
3+
) where
4+
5+
import Data.Aeson (encode)
6+
import Paths_cabal_doctests_test (version)
7+
8+
-- |
9+
-- >>> 1 + 1
10+
-- 2
11+
--
12+
-- >>> version
13+
-- Version {versionBranch = [0,1,0,0], versionTags = []}
14+
--
15+
-- >>> encode (Just 1 :: Maybe Int)
16+
-- "1"
17+
someFunc :: IO ()
18+
someFunc = putStrLn "someFunc"

test/cabal-doctests/Setup.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module Main where
2+
3+
import Distribution.Extra.Doctest (defaultMainWithDoctests)
4+
5+
main :: IO ()
6+
main = defaultMainWithDoctests "doctests"
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
cabal-version: 1.12
2+
3+
name: cabal-doctests-test
4+
version: 0.1.0.0
5+
build-type: Custom
6+
7+
custom-setup
8+
setup-depends:
9+
base >= 4 && <5,
10+
Cabal,
11+
cabal-doctest >= 1 && <1.1
12+
13+
library
14+
exposed-modules: Lib
15+
other-modules: Paths_cabal_doctests_test
16+
build-depends:
17+
base >=4.7 && <5,
18+
aeson
19+
default-language: Haskell2010
20+
21+
test-suite doctests
22+
type: exitcode-stdio-1.0
23+
main-is: Doctests.hs
24+
ghc-options: -threaded -rtsopts -with-rtsopts=-N
25+
build-depends:
26+
base >=4.7 && <5
27+
, doctest
28+
, cabal-doctests-test
29+
default-language: Haskell2010

test/cabal-doctests/default.nix

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Test a package set
2+
{ stdenv, util, cabalProject', haskellLib, gmp6, zlib, recurseIntoAttrs }:
3+
4+
with stdenv.lib;
5+
6+
let
7+
project =
8+
cabalProject' {
9+
src = haskellLib.cleanGit { src = ../..; subDir = "test/cabal-doctests"; };
10+
index-state = "2020-01-26T00:00:00Z";
11+
modules = [
12+
{
13+
# This is needed for the doctest library to be built. Without it, you
14+
# get an error like the following:
15+
#
16+
# Configuring library for doctest-0.16.2..
17+
# Error:
18+
# The following packages are broken because other packages they
19+
# depend on are missing. These broken packages must be rebuilt
20+
# before they can be used.
21+
# - installed package ghc-8.6.5 is broken due to missing package
22+
# terminfo-0.4.1.2
23+
nonReinstallablePkgs =
24+
[ "rts" "ghc-heap" "ghc-prim" "integer-gmp" "integer-simple" "base"
25+
"deepseq" "array" "ghc-boot-th" "pretty" "template-haskell"
26+
"ghc-boot"
27+
"ghc" "Cabal" "Win32" "array" "binary" "bytestring" "containers"
28+
"directory" "filepath" "ghc-boot" "ghc-compact" "ghc-prim"
29+
"ghci" "haskeline"
30+
"hpc"
31+
"mtl" "parsec" "process" "text" "time" "transformers"
32+
"unix" "xhtml"
33+
"stm" "terminfo"
34+
];
35+
36+
packages.cabal-doctests-test.components.tests.doctests.isDoctest = true;
37+
}
38+
];
39+
};
40+
41+
packages = project.hsPkgs;
42+
43+
in
44+
45+
recurseIntoAttrs {
46+
ifdInputs = {
47+
inherit (project) plan-nix;
48+
};
49+
50+
# Used for testing externally with nix-shell (../tests.sh).
51+
# This just adds cabal-install to the existing shells.
52+
# test-shell = util.addCabalInstall packages.cabal-doctests-test.components.all;
53+
54+
run = stdenv.mkDerivation {
55+
name = "cabal-doctests-test";
56+
57+
buildCommand = ''
58+
printf "Checking that doctest tests have run ... " >& 2
59+
doctest_output="${packages.cabal-doctests-test.checks.doctests}"
60+
test -f "$doctest_output"
61+
cat "$doctest_output" >& 2
62+
63+
touch $out
64+
'';
65+
66+
meta.platforms = platforms.all;
67+
68+
passthru = {
69+
# Used for debugging with nix repl
70+
inherit project packages;
71+
};
72+
};
73+
}

test/default.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ let
167167
ghc-options-stack = haskell-nix.callPackage ./ghc-options/stack.nix {};
168168
exe-only = haskell-nix.callPackage ./exe-only { inherit util; };
169169
stack-source-repo = haskell-nix.callPackage ./stack-source-repo {};
170+
cabal-doctests = haskell-nix.callPackage ./cabal-doctests { inherit util; };
170171

171172
unit = unitTests;
172173
};

0 commit comments

Comments
 (0)