run doctests as part of cabal test

This commit is contained in:
Marco Perone 2023-01-11 16:22:51 +01:00 committed by Marco Perone
parent 58d3f1ba69
commit b9a99914cc
8 changed files with 44 additions and 6 deletions

1
.gitignore vendored
View File

@ -2,6 +2,7 @@
dist
dist-*
*.cabal
.ghc.*
# nix
result

1
.hspec Normal file
View File

@ -0,0 +1 @@
--color

View File

@ -116,3 +116,13 @@ Nix (or more precisely, Cabal2nix) uses a `.cabal` file if it is present, otherw
- `crm.cabal`
This file is automatically generated from the `package.yaml` file and should not be committed to Git history.
### tool-specific files
- `fourmolu.yaml`
Configuration file for the [`fourmolu`](https://github.com/fourmolu/fourmolu) formatting tool.
- `.hspec`
Using a dedicated file to specify options for [`hspec`](https://hspec.github.io) allows passing options only to it. Using `cabal test --test-options` would pass options to all test stanzas instead.

8
doctest/Main.hs Normal file
View File

@ -0,0 +1,8 @@
module Main where
import "base" System.Environment (getArgs)
import "doctest-parallel" Test.DocTest (mainFromCabal)
main :: IO ()
main = do
mainFromCabal "crm" =<< getArgs

View File

@ -76,8 +76,10 @@
"cabal build";
# Trigger a test execution every time a file changes
# the --write-ghc-environment-files=always is required by doctest-parallel
# see https://github.com/martijnbastiaan/doctest-parallel/blob/main/example/README.md#cabalproject
test-watch = watch "test-watch"
"cabal test --test-show-details=streaming --test-option=--color";
"cabal test --test-show-details=streaming --write-ghc-environment-files=always";
in
rec {
packages = {

View File

@ -1,4 +1,5 @@
[
"doctest"
"src"
"spec"
"package.yaml"

View File

@ -92,13 +92,13 @@ ghc-options:
dependencies:
- base
- singletons-base
- text
library:
source-dirs: src
dependencies:
- profunctors
- singletons-base
- text
# Disable adding Paths_crm to other-modules, because it does not conform to our style guide.
# https://github.com/sol/hpack#handling-of-paths_-modules
when:
@ -112,6 +112,21 @@ tests:
dependencies:
- crm
- hspec
- singletons-base
- text
when:
- condition: false
other-modules: Paths_crm
crm-doctests:
source-dirs: doctest
main: Main.hs
ghc-options:
- -threaded
- -Wno-unused-packages
dependencies:
- crm
- doctest-parallel
when:
- condition: false
other-modules: Paths_crm

View File

@ -10,10 +10,10 @@ newtype Graph a = Graph [(a, a)]
It has as vertices the product of the set of vertices of the initial graph.
It has as edge from `(a1, b1)` to `(a2, b2)` if and only if there is an edge
from `a1` to `a2` and an edge from `b1` to `b2`
-}
-- >>> productGraph (Graph [('a', 'b')]) (Graph [('c', 'd')])
-- Graph [(('a','c'),('b','d'))]
>>> productGraph (Graph [('a', 'b')]) (Graph [('c', 'd')])
Graph [(('a','c'),('b','d'))]
-}
productGraph :: Graph a -> Graph b -> Graph (a, b)
productGraph (Graph edges1) (Graph edges2) =
Graph $