Skip to content

Commit 607a7fd

Browse files
authored
Merge pull request #5107 from IntersectMBO/nm/doctest-in-nix-develop
* Include doctest and cabal-doctest in the nix develop shell * Ensure a compatible ghc version is being used for doctests
2 parents 005d3cc + 0db7e4d commit 607a7fd

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed

flake.nix

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,19 @@
138138
(python3.withPackages (ps: with ps; [sphinx sphinx_rtd_theme recommonmark sphinx-markdown-tables sphinxemoji]))
139139
haskellPackages.implicit-hie
140140
shellcheck
141-
];
141+
] ++
142+
(let
143+
doctest = haskell-nix.hackage-package {
144+
name = "doctest";
145+
version = "0.24.0";
146+
configureArgs = "-f cabal-doctest";
147+
inherit (config) compiler-nix-name;
148+
};
149+
in
150+
[
151+
(doctest.getComponent "exe:cabal-doctest")
152+
(doctest.getComponent "exe:doctest")
153+
]);
142154
# disable Hoogle until someone request it
143155
withHoogle = false;
144156
# Skip cross compilers for the shell

scripts/doctest.sh

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,32 @@
22

33
set -euo pipefail
44

5-
# Install doctest's Cabal integration
6-
cabal install doctest --flag cabal-doctest --ignore-project --overwrite-policy=always
5+
# Packages to run doctests for; defaults to all packages if none are specified
6+
PACKAGES=("$@")
7+
8+
# Install doctest's Cabal integration, if it's not present already
9+
if [[ -z "$(type -t cabal-doctest)" ]]
10+
then
11+
cabal install doctest --flag cabal-doctest --ignore-project --overwrite-policy=always
12+
fi
13+
14+
# Ensure doctest and PATH are using the same ghc version
15+
16+
getExecutablePath()
17+
{
18+
"$1" -package-env - -e 'import System.Environment' -e 'putStrLn =<< getExecutablePath'
19+
}
20+
21+
default_ghc=$(type -p ghc)
22+
doctest_ghc=$(doctest --info | ghc -e 'interact $ maybe "" id . lookup "ghc" . read')
23+
24+
if [[ "$(getExecutablePath "$default_ghc")" != "$(getExecutablePath "$doctest_ghc")" ]]
25+
then
26+
echo "Incompatible GHC's:" >&2
27+
echo " Default ghc: $(getExecutablePath "$default_ghc")" >&2
28+
echo " Doctest ghc: $(getExecutablePath "$doctest_ghc")" >&2
29+
exit 1
30+
fi
731

832
# Ensure the cabal-doctest executable can be found
933
PATH=$(cabal path --installdir):$PATH
@@ -21,9 +45,10 @@ cardano-ledger-api:lib:cardano-ledger-api --build-depends=cardano-ledger-babbage
2145
EOF
2246

2347
# Run the doctests for some or all packages
24-
cabal-targets.hs "$@" |
48+
cabal-targets.hs "${PACKAGES[@]}" |
2549
sort | join -t' ' -a1 -j1 - "$EXTRA_ARGS" |
2650
while read -ra ARGS
2751
do
52+
echo "***** cabal doctest ${ARGS[0]} *****"
2853
cabal doctest --repl-options='-w -Wdefault' "${ARGS[@]}"
2954
done

0 commit comments

Comments
 (0)