Skip to content

Commit ef1e12c

Browse files
authored
Merge pull request #8735 from ulysses4ever/t8504-improve-doctest
doctests: switch to the preffered method of calling the tool
2 parents fd09059 + 822d1a7 commit ef1e12c

File tree

3 files changed

+41
-20
lines changed

3 files changed

+41
-20
lines changed

.github/workflows/quick-jobs.yml

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,6 @@ jobs:
6565
- name: Set PATH
6666
run: |
6767
echo "$HOME/.cabal/bin" >> $GITHUB_PATH
68-
- name: Install cabal-env
69-
run: |
70-
mkdir -p $HOME/.cabal/bin
71-
curl -sL https://github.com/phadej/cabal-extras/releases/download/preview-20191225/cabal-env-snapshot-20191225-x86_64-linux.xz > cabal-env.xz
72-
echo "1b567d529c5f627fd8c956e57ae8f0d9f11ee66d6db34b7fb0cb1c370b4edf01 cabal-env.xz" | sha256sum -c -
73-
xz -d < cabal-env.xz > $HOME/.cabal/bin/cabal-env
74-
rm -f cabal-env.xz
75-
chmod a+x $HOME/.cabal/bin/cabal-env
7668
- uses: actions/cache@v1
7769
with:
7870
path: ~/.cabal/store
@@ -91,17 +83,12 @@ jobs:
9183
run: |
9284
ghcup --version
9385
ghcup config set cache true
94-
ghcup install ghc recommended
95-
ghcup set ghc recommended
86+
ghcup install ghc --set recommended
87+
ghcup install cabal --set latest
9688
- name: Update Hackage index
9789
run: cabal v2-update
98-
- name: Install doctest
99-
run: cabal v2-install doctest
100-
- name: Install libraries
101-
run: |
102-
cabal-env --transitive QuickCheck
103-
cabal-env array bytestring containers deepseq directory filepath pretty process time binary unix text parsec mtl
104-
cat $HOME/.ghc/*/environments/default
10590
- uses: actions/checkout@v3
91+
- name: Install doctest
92+
run: make doctest-install
10693
- name: Doctest
10794
run: make doctest

Makefile

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,27 @@ 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
85+
cabal repl --with-ghc=doctest --build-depends=QuickCheck --build-depends=template-haskell --repl-options="-w" --project-file="cabal.project.validate" Cabal
86+
7887

7988
# This is not run as part of validate.sh (we need hackage-security, which is tricky to get).
8089
doctest-cli :
8190
doctest -D__DOCTEST__ --fast cabal-install/src cabal-install-solver/src cabal-install-solver/src-assertion
8291

92+
doctest-install:
93+
cabal install doctest --overwrite-policy=always --ignore-project
94+
8395
# tests
8496

8597
check-tests :

cabal-testsuite/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,28 @@ 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, and don't forget to reinstall it every time you switch GHC version:
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
42+
```
43+
44+
In this example we have run doctests in `Cabal-syntax`. Notice, that some
45+
components have broken doctests
46+
([#8734](https://github.com/haskell/cabal/issues/8734));
47+
our CI currently checks that `Cabal-syntax` and `Cabal` doctests pass via
48+
`make doctest-install && make doctest` (you can use this make-based workflow too).
49+
2850
How to write
2951
------------
3052

0 commit comments

Comments
 (0)