Skip to content

Commit f023545

Browse files
committed
doctests: switch to the preffered method of calling the tool
which is `cabal repl --with-ghc=doctest`. This not only catches up with the current upstream recommendations, but also simplifies the usage: before this change calling doctest required you to set up an environment with QuickCheck available (we used to do it via cabal-env). The new method takes care of it automatically. Also add some docs to fix #8147
1 parent a5ddb14 commit f023545

File tree

3 files changed

+32
-17
lines changed

3 files changed

+32
-17
lines changed

.github/workflows/quick-jobs.yml

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,6 @@ jobs:
5454
- name: Set PATH
5555
run: |
5656
echo "$HOME/.cabal/bin" >> $GITHUB_PATH
57-
- name: Install cabal-env
58-
run: |
59-
mkdir -p $HOME/.cabal/bin
60-
curl -sL https://github.com/phadej/cabal-extras/releases/download/preview-20191225/cabal-env-snapshot-20191225-x86_64-linux.xz > cabal-env.xz
61-
echo "1b567d529c5f627fd8c956e57ae8f0d9f11ee66d6db34b7fb0cb1c370b4edf01 cabal-env.xz" | sha256sum -c -
62-
xz -d < cabal-env.xz > $HOME/.cabal/bin/cabal-env
63-
rm -f cabal-env.xz
64-
chmod a+x $HOME/.cabal/bin/cabal-env
6557
- uses: actions/cache@v1
6658
with:
6759
path: ~/.cabal/store
@@ -70,16 +62,11 @@ jobs:
7062
run: |
7163
ghcup config set cache true
7264
ghcup install ghc recommended
73-
ghcup set ghc recommended
65+
ghcup install cabal latest
7466
- name: Update Hackage index
7567
run: cabal v2-update
7668
- name: Install doctest
7769
run: cabal v2-install doctest
78-
- name: Install libraries
79-
run: |
80-
cabal-env --transitive QuickCheck
81-
cabal-env array bytestring containers deepseq directory filepath pretty process time binary unix text parsec mtl
82-
cat $HOME/.ghc/*/environments/default
8370
- uses: actions/checkout@v3
8471
- name: Doctest
8572
run: make doctest

Makefile

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,18 @@ ghcid-lib :
7171
ghcid-cli :
7272
ghcid -c 'cabal v2-repl cabal-install'
7373

74-
# doctests (relies on .ghc.environment files)
75-
74+
# Artem, 2023-02-03, https://github.com/haskell/cabal/issues/8504
75+
# The new and prefered way to call the doctest tool (as of now) is based on cabal repl --with-ghc=doctest.
76+
# The call below reflects the current documentation of the doctest tool except one caveat,
77+
# which is https://github.com/haskell/cabal/issues/6859, i.e. we have to hide allow-newer in our project
78+
# file from cabal/doctest. This is easy: we just select a project file with no allow-newer (e.g. cabal.project.libonly).
79+
#
80+
# TODO: Cabal-described should be added here but its doctests currently broken, see:
81+
# https://github.com/haskell/cabal/issues/8734
82+
# Just as well, cabal-install(-solver) doctests (the target below) bitrotted and need some care.
7683
doctest :
77-
doctest --fast -XHaskell2010 Cabal-syntax/src Cabal/src
84+
cabal repl --with-ghc=doctest --build-depends=QuickCheck --build-depends=template-haskell --repl-options="-w" --project-file="cabal.project.validate" Cabal-syntax Cabal
85+
7886

7987
# This is not run as part of validate.sh (we need hackage-security, which is tricky to get).
8088
doctest-cli :

cabal-testsuite/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,26 @@ There are a few useful flags:
2525
the autodetection doesn't work correctly (which may be the
2626
case for old versions of GHC.)
2727

28+
doctests
29+
========
30+
31+
You need to install the doctest tool. Make sure it's compiled with your current
32+
GHC:
33+
34+
``` shellsession
35+
cabal install doctest --overwrite-policy=always --ignore-project
36+
```
37+
38+
After that you can run doctests for a component of your choice via the following command:
39+
40+
``` shellsession
41+
cabal repl --with-ghc=doctest --build-depends=QuickCheck --build-depends=template-haskell --repl-options="-w" --project-file="cabal.project.validate" Cabal-syntax Cabal
42+
```
43+
44+
In this example we run doctests in `Cabal-syntax` and `Cabal`. Exactly the same
45+
can be done via `make doctest` (that's what our CI does). Notice, that some
46+
components have broken doctests ([#8734](https://github.com/haskell/cabal/issues/8734)).
47+
2848
How to write
2949
------------
3050

0 commit comments

Comments
 (0)