Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doctest-parallel #178

Merged
merged 4 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 26 additions & 40 deletions .github/workflows/haskell-ci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
name: build
on: [push]
name: haskell-ci

# INFO: The following configuration block ensures that only one build runs per branch,
# which may be desirable for projects with a costly build process.
# Remove this block from the CI workflow to let each CI job run to completion.
concurrency:
group: build-${{ github.ref }}
cancel-in-progress: true

jobs:
hlint:
runs-on: ubuntu-latest
Expand All @@ -14,28 +22,21 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: haskell-actions/run-ormolu@v15
cabal:
- uses: haskell-actions/run-ormolu@v16
build:
name: GHC ${{ matrix.ghc-version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
ghc-version: ['9.10', '9.8', '9.6', '9.4', '9.2']
docspec: [false]
experimental: [false]
ghc-version: ['9.10', '9.8', '9.6']

include:
- os: windows-latest
ghc-version: '9.8'
- os: macos-latest
ghc-version: '9.8'
- os: ubuntu-latest
ghc-version: '9.8'
docspec: true
experimental: true
name: docspec

steps:
- uses: actions/checkout@v4
Expand All @@ -46,57 +47,42 @@ jobs:
with:
ghc-version: ${{ matrix.ghc-version }}

- name: Installed minor versions of GHC and Cabal
shell: bash
run: |
GHC_VERSION=$(ghc --numeric-version)
CABAL_VERSION=$(cabal --numeric-version)
echo "GHC_VERSION=${GHC_VERSION}" >> "${GITHUB_ENV}"
echo "CABAL_VERSION=${CABAL_VERSION}" >> "${GITHUB_ENV}"

- name: Configure the build
run: |
cabal configure --enable-tests --enable-benchmarks --disable-documentation
cabal build --dry-run
# The last step generates dist-newstyle/cache/plan.json for the cache key.

- name: Restore cached dependencies
uses: actions/cache/restore@v3
uses: actions/cache/restore@v4
id: cache
env:
key: ${{ runner.os }}-ghc-${{ steps.setup.outputs.ghc-version }}-cabal-${{ steps.setup.outputs.cabal-version }}
with:
path: ${{ steps.setup.outputs.cabal-store }}
key: ${{ runner.os }}-ghc-${{ env.GHC_VERSION }}-cabal-${{ env.CABAL_VERSION }}-plan-${{ hashFiles('**/plan.json') }}
restore-keys: |
${{ runner.os }}-ghc-${{ env.GHC_VERSION }}-cabal-${{ env.CABAL_VERSION }}-
key: ${{ env.key }}-plan-${{ hashFiles('**/plan.json') }}
restore-keys: ${{ env.key }}-

- name: Install dependencies
# If we had an exact cache hit, the dependencies will be up to date.
if: steps.cache.outputs.cache-hit != 'true'
run: cabal build all --only-dependencies

# Cache dependencies already here, so that we do not have to rebuild them should the subsequent steps fail.
- name: Save cached dependencies
uses: actions/cache/save@v3
# Caches are immutable, trying to save with the same key would error.
if: ${{ !steps.cache.outputs.cache-hit
|| steps.cache.outputs.cache-primary-key != steps.cache.outputs.cache-matched-key }}
uses: actions/cache/save@v4
# If we had an exact cache hit, trying to save the cache would error because of key clash.
if: steps.cache.outputs.cache-hit != 'true'
with:
path: ${{ steps.setup.outputs.cabal-store }}
key: ${{ steps.cache.outputs.cache-primary-key }}

- name: Build
run: cabal build all

- if: ${{ matrix.os == 'ubuntu-latest' && matrix.ghc-version == '9.8'}}
name: doctests
run: cabal run doctests

- name: Check cabal file
run: cabal check

- if: matrix.docspec
name: cabal-docspec
run: |
mkdir -p $HOME/.cabal/bin
echo "$HOME/.cabal/bin" >> $GITHUB_PATH
curl -sL https://github.com/phadej/cabal-extras/releases/download/cabal-docspec-0.0.0.20240414/cabal-docspec-0.0.0.20240414-x86_64-linux.xz > cabal-docspec.xz
echo '2d18a3f79619e8ec5f11870f926f6dc2616e02a6c889315b7f82044b95a1adb9 cabal-docspec.xz' | sha256sum -c -
xz -d < cabal-docspec.xz > $HOME/.cabal/bin/cabal-docspec
rm -f cabal-docspec.xz
chmod a+x $HOME/.cabal/bin/cabal-docspec
$HOME/.cabal/bin/cabal-docspec --version
cabal-docspec
2 changes: 2 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
packages: numhask.cabal

write-ghc-environment-files: always
12 changes: 12 additions & 0 deletions numhask.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,15 @@ library
NumHask.Exception
NumHask.Prelude
default-extensions: RebindableSyntax

test-suite doctests
import: ghc2021-stanza
type: exitcode-stdio-1.0
hs-source-dirs: test
main-is: doctests.hs
ghc-options: -threaded
build-depends:
, base
, numhask
, doctest-parallel >=0.3 && <0.4
default-extensions: RebindableSyntax
1 change: 1 addition & 0 deletions src/NumHask.hs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ import NumHask.Exception (NumHaskException (..), throw)

-- $setup
--
-- >>> :m -Prelude
-- >>> :set -XRebindableSyntax
-- >>> import NumHask.Prelude
-- >>> 1+1
Expand Down
1 change: 1 addition & 0 deletions src/NumHask/Algebra/Additive.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import Prelude qualified as P

-- $setup
--
-- >>> :m -Prelude
-- >>> :set -XRebindableSyntax
-- >>> import NumHask.Prelude

Expand Down
7 changes: 4 additions & 3 deletions src/NumHask/Algebra/Field.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import Prelude qualified as P

-- $setup
--
-- >>> :m -Prelude
-- >>> :set -XRebindableSyntax
-- >>> :set -XScopedTypeVariables
-- >>> import NumHask.Prelude
Expand Down Expand Up @@ -67,9 +68,9 @@ type Field a = (Ring a, Divisive a)

-- | A hyperbolic field class
--
-- prop> \a -> a < zero || (sqrt . (**2)) a == a
-- prop> \a -> a < zero || (log . exp) a ~= a
-- prop> \a b -> (b < zero) || a <= zero || a == 1 || abs (a ** logBase a b - b) < 10 * epsilon
-- prop> \(a::Double) -> a < zero || (sqrt . (**2)) a == a
-- prop> \(a::Double) -> a < zero || (log . exp) a ~= a
-- prop> \(a::Double) (b::Double) -> (b < zero) || a <= zero || a == 1 || abs (a ** logBase a b - b) < 10 * epsilon
class
(Field a) =>
ExpField a
Expand Down
1 change: 1 addition & 0 deletions src/NumHask/Algebra/Metric.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import Prelude qualified as P

-- $setup
--
-- >>> :m -Prelude
-- >>> :set -XRebindableSyntax
-- >>> import NumHask.Prelude

Expand Down
1 change: 1 addition & 0 deletions src/NumHask/Algebra/Multiplicative.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import Prelude qualified as P

-- $setup
--
-- >>> :m -Prelude
-- >>> :set -XRebindableSyntax
-- >>> import NumHask.Prelude

Expand Down
1 change: 1 addition & 0 deletions src/NumHask/Algebra/Ring.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import Prelude qualified as P

-- $setup
--
-- >>> :m -Prelude
-- >>> :set -XRebindableSyntax
-- >>> import NumHask.Prelude

Expand Down
1 change: 1 addition & 0 deletions src/NumHask/Data/Integral.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import Prelude qualified as P

-- $setup
--
-- >>> :m -Prelude
-- >>> :set -XRebindableSyntax
-- >>> import NumHask.Prelude

Expand Down
1 change: 1 addition & 0 deletions src/NumHask/Data/Positive.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import Prelude qualified as P

-- $setup
--
-- >>> :m -Prelude
-- >>> :set -XRebindableSyntax
-- >>> import NumHask.Prelude
-- >>> import NumHask.Data.Positive
Expand Down
1 change: 1 addition & 0 deletions src/NumHask/Data/Rational.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import Prelude qualified as P

-- $setup
--
-- >>> :m -Prelude
-- >>> :set -XRebindableSyntax
-- >>> import NumHask.Prelude

Expand Down
1 change: 1 addition & 0 deletions src/NumHask/Prelude.hs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ import Prelude hiding (Integral (..), Rational, abs, acos, acosh, asin, asinh, a

-- $usage
--
-- >>> :m -Prelude
-- >>> :set -XRebindableSyntax
-- >>> import NumHask.Prelude
-- >>> 1+1
Expand Down
8 changes: 8 additions & 0 deletions test/doctests.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module Main where

import System.Environment (getArgs)
import Test.DocTest (mainFromCabal)
import Prelude (IO, (=<<))

main :: IO ()
main = mainFromCabal "numhask" =<< getArgs