Skip to content

Commit 929e8cf

Browse files
Present code-coverage input in PRs
1 parent 9c72b29 commit 929e8cf

File tree

4 files changed

+77
-32
lines changed

4 files changed

+77
-32
lines changed

.github/workflows/haskell-ci.yml

Lines changed: 58 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
name: Haskell-CI
22

3+
permissions:
4+
contents: read
5+
pull-requests: write
6+
37
on:
48
push:
59
branches:
@@ -21,25 +25,67 @@ jobs:
2125
strategy:
2226
matrix:
2327
ghc-version: [latest, 9.12, "9.10", 9.8, 9.6]
24-
os: [ubuntu-24.04]
2528
fail-fast: false
2629

27-
runs-on: ${{ matrix.os }}
30+
runs-on: ubuntu-latest
2831

2932
steps:
3033
- uses: actions/checkout@v4
3134
- uses: haskell-actions/setup@v2
3235
with:
3336
ghc-version: ${{matrix.ghc-version}}
34-
- uses: actions/cache/restore@v4
37+
- uses: actions/cache@v4
38+
with:
39+
key: ${{ matrix.ghc-version }}-${{ github.sha }}
40+
path: |
41+
~/.cabal/store
42+
dist-newstyle
43+
.hpc
44+
restore-keys: ${{ matrix.ghc-version }}-
45+
- run: cabal build all --ghc-options=-fhpc
46+
- run: cabal test all --ghc-options=-fhpc
47+
- run: ./scripts/generate-coverage-comment.sh constrained.tix > coverage-report.md
48+
- run: cat coverage-report.md
49+
- run: cabal haddock all --ghc-options=-fhpc
50+
- name: Upload coverage report
51+
uses: actions/upload-artifact@v4
3552
with:
36-
key: ${{ matrix.os }}-${{ matrix.ghc-version }}-${{ github.sha }}
37-
path: ~/.cabal/store
38-
restore-keys: ${{ matrix.os }}-${{ matrix.ghc-version }}-
39-
- run: cabal build all
40-
- run: cabal test all
41-
- run: cabal haddock all
42-
- uses: actions/cache/save@v4
53+
name: constrained-${{matrix.ghc-version}}-coverage
54+
path: coverage-report.md
55+
if-no-files-found: error
56+
compression-level: 0
57+
retention-days: 1
58+
59+
report:
60+
name: Generate coverage report
61+
62+
if: github.event.pull_request
63+
64+
needs: linux
65+
66+
runs-on: ubuntu-latest
67+
68+
steps:
69+
- name: Download coverage report
70+
uses: actions/download-artifact@v4
71+
with:
72+
pattern: 'constrained-latest-coverage'
73+
merge-multiple: true
74+
75+
- run: cat coverage-report.md
76+
77+
- name: Find Comment
78+
uses: peter-evans/find-comment@v3
79+
id: fc
80+
with:
81+
issue-number: ${{ github.event.pull_request.number }}
82+
comment-author: 'github-actions[bot]'
83+
body-includes: "expressions used"
84+
85+
- name: Create or update comment
86+
uses: peter-evans/create-or-update-comment@v4
4387
with:
44-
key: ${{ matrix.os }}-${{ matrix.ghc-version }}-${{ github.sha }}
45-
path: ~/.cabal/store
88+
comment-id: ${{ steps.fc.outputs.comment-id }}
89+
issue-number: ${{ github.event.pull_request.number }}
90+
body-path: coverage-report.md
91+
edit-mode: replace

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ cabal.project.local~
2222
.HTF/
2323
.ghc.environment.*
2424
*.*.sw*
25+
*.tix
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
3+
echo "# Coverage report"
4+
hpc report $1 | awk '{sub(/^[ \t]*/, "& - ")1; sub(/^ /, "", $0); print}'

test/Constrained/Tests.hs

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -59,21 +59,18 @@ testAll = hspec $ tests False
5959
tests :: Bool -> Spec
6060
tests nightly =
6161
describe "constrained" . modifyMaxSuccess (\ms -> if nightly then ms * 10 else ms) $ do
62-
-- TODO: double-shrinking
62+
-- TODO: figure out why this doesn't shrink
6363
testSpecNoShrink "reifiesMultiple" reifiesMultiple
6464
testSpec "assertReal" assertReal
6565
testSpecNoShrink "chooseBackwards" chooseBackwards
6666
testSpecNoShrink "chooseBackwards'" chooseBackwards'
67-
-- TODO: turn this on again when QuickCheck version is bumped
68-
-- testSpec "whenTrueExists" whenTrueExists
67+
testSpec "whenTrueExists" whenTrueExists
6968
testSpec "assertRealMultiple" assertRealMultiple
70-
-- TODO: quickcheck version
71-
testSpecNoShrink "setSpec" setSpec
69+
testSpec "setSpec" setSpec
7270
testSpec "leqPair" leqPair
7371
testSpec "setPair" setPair
7472
testSpecNoShrink "listEmpty" listEmpty
75-
-- TODO: quickcheck version
76-
testSpecNoShrink "compositionalSpec" compositionalSpec
73+
testSpec "compositionalSpec" compositionalSpec
7774
testSpec "simplePairSpec" simplePairSpec
7875
testSpec "trickyCompositional" trickyCompositional
7976
testSpec "emptyListSpec" emptyListSpec
@@ -83,17 +80,18 @@ tests nightly =
8380
testSpec "fooSpec" fooSpec
8481
testSpec "mapElemSpec" mapElemSpec
8582
testSpec "mapElemKeySpec" mapElemKeySpec
86-
-- TODO: double shrinking
83+
-- TODO: figure out why this doesn't shrink
8784
testSpecNoShrink "mapIsJust" mapIsJust
85+
-- TODO: figure out why this doesn't shrink
8886
testSpecNoShrink "intSpec" intSpec
89-
testSpecNoShrink "mapPairSpec" mapPairSpec
87+
testSpec "mapPairSpec" mapPairSpec
88+
-- TODO: figure out why this doesn't shrink
9089
testSpecNoShrink "mapEmptyDomainSpec" mapEmptyDomainSpec
9190
-- TODO: this _can_ be shrunk, but it's incredibly expensive to do
9291
-- so and it's not obvious if there is a faster way without implementing
9392
-- more detailed shrinking of `SuspendedSpec`s
9493
testSpecNoShrink "setPairSpec" setPairSpec
95-
-- TODO: quickcheck version
96-
testSpecNoShrink "fixedSetSpec" fixedSetSpec
94+
testSpec "fixedSetSpec" fixedSetSpec
9795
testSpec "setOfPairLetSpec" setOfPairLetSpec
9896
testSpecNoShrink "emptyEitherSpec" emptyEitherSpec
9997
testSpecNoShrink "emptyEitherMemberSpec" emptyEitherMemberSpec
@@ -106,19 +104,19 @@ tests nightly =
106104
testSpec "maybeJustSetSpec" maybeJustSetSpec
107105
testSpec "weirdSetPairSpec" weirdSetPairSpec
108106
testSpec "knownDomainMap" knownDomainMap
109-
-- TODO: figure out double-shrinking
107+
-- TODO: figure out why this doesn't shrink
110108
testSpecNoShrink "testRewriteSpec" testRewriteSpec
111109
testSpec "parallelLet" parallelLet
112110
testSpec "letExists" letExists
113111
testSpec "letExistsLet" letExistsLet
114112
testSpec "notSubset" notSubset
115113
testSpec "unionSized" unionSized
116-
-- TODO: figure out double-shrinking
114+
-- TODO: figure out why this doesn't shrink
117115
testSpecNoShrink "dependencyWeirdness" dependencyWeirdness
118116
testSpec "foldTrueCases" foldTrueCases
119117
testSpec "foldSingleCase" foldSingleCase
120118
testSpec "listSumPair" (listSumPair @Int)
121-
-- TODO: figure out double-shrinking
119+
-- TODO: figure out why this doesn't shrink
122120
testSpecNoShrink "parallelLetPair" parallelLetPair
123121
testSpec "mapSizeConstrained" mapSizeConstrained
124122
testSpec "isAllZeroTree" isAllZeroTree
@@ -136,13 +134,12 @@ tests nightly =
136134
testSpec "sumRange" sumRange
137135
testSpec "sumListBad" sumListBad
138136
testSpec "listExistsUnfree" listExistsUnfree
139-
-- TODO: turn this on when we bump quickcheck version
140-
-- testSpec "listSumShort" listSumShort
137+
testSpec "listSumShort" listSumShort
141138
testSpec "existsUnfree" existsUnfree
142139
testSpec "appendSize" appendSize
143140
testSpecNoShrink "appendSingleton" appendSingleton
144141
testSpec "singletonSubset" singletonSubset
145-
-- TODO: double shrinking
142+
-- TODO: figure out why this doesn't shrink
146143
testSpecNoShrink "reifyYucky" reifyYucky
147144
testSpec "fixedRange" fixedRange
148145
testSpec "rangeHint" rangeHint
@@ -467,6 +464,3 @@ foldWithSizeTests = do
467464
prop "something of size 2, can add to 0 in type with negative values." $
468465
testFoldSpec @Int (between 2 2) (between (-10) 10) (MemberSpec (pure 0)) Succeed
469466
prop "TEST listSum" $ prop_constrained_satisfies_sound (listSum @Int)
470-
471-
-- TODO Needs to sample like this: OR [pick t c | t <- total, c <- count]
472-
-- prop "count =0, total is 0,1,2" $ testFoldSpec @Int (between 0 1) evenSpec (between 0 2) Succeed

0 commit comments

Comments
 (0)