Skip to content

Commit 3d53e4d

Browse files
Present code-coverage input in PRs
1 parent 45559e0 commit 3d53e4d

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
@@ -57,21 +57,18 @@ testAll = hspec $ tests False
5757
tests :: Bool -> Spec
5858
tests nightly =
5959
describe "constrained" . modifyMaxSuccess (\ms -> if nightly then ms * 10 else ms) $ do
60-
-- TODO: double-shrinking
60+
-- TODO: figure out why this doesn't shrink
6161
testSpecNoShrink "reifiesMultiple" reifiesMultiple
6262
testSpec "assertReal" assertReal
6363
testSpecNoShrink "chooseBackwards" chooseBackwards
6464
testSpecNoShrink "chooseBackwards'" chooseBackwards'
65-
-- TODO: turn this on again when QuickCheck version is bumped
66-
-- testSpec "whenTrueExists" whenTrueExists
65+
testSpec "whenTrueExists" whenTrueExists
6766
testSpec "assertRealMultiple" assertRealMultiple
68-
-- TODO: quickcheck version
69-
testSpecNoShrink "setSpec" setSpec
67+
testSpec "setSpec" setSpec
7068
testSpec "leqPair" leqPair
7169
testSpec "setPair" setPair
7270
testSpecNoShrink "listEmpty" listEmpty
73-
-- TODO: quickcheck version
74-
testSpecNoShrink "compositionalSpec" compositionalSpec
71+
testSpec "compositionalSpec" compositionalSpec
7572
testSpec "simplePairSpec" simplePairSpec
7673
testSpec "trickyCompositional" trickyCompositional
7774
testSpec "emptyListSpec" emptyListSpec
@@ -81,17 +78,18 @@ tests nightly =
8178
testSpec "fooSpec" fooSpec
8279
testSpec "mapElemSpec" mapElemSpec
8380
testSpec "mapElemKeySpec" mapElemKeySpec
84-
-- TODO: double shrinking
81+
-- TODO: figure out why this doesn't shrink
8582
testSpecNoShrink "mapIsJust" mapIsJust
83+
-- TODO: figure out why this doesn't shrink
8684
testSpecNoShrink "intSpec" intSpec
87-
testSpecNoShrink "mapPairSpec" mapPairSpec
85+
testSpec "mapPairSpec" mapPairSpec
86+
-- TODO: figure out why this doesn't shrink
8887
testSpecNoShrink "mapEmptyDomainSpec" mapEmptyDomainSpec
8988
-- TODO: this _can_ be shrunk, but it's incredibly expensive to do
9089
-- so and it's not obvious if there is a faster way without implementing
9190
-- more detailed shrinking of `SuspendedSpec`s
9291
testSpecNoShrink "setPairSpec" setPairSpec
93-
-- TODO: quickcheck version
94-
testSpecNoShrink "fixedSetSpec" fixedSetSpec
92+
testSpec "fixedSetSpec" fixedSetSpec
9593
testSpec "setOfPairLetSpec" setOfPairLetSpec
9694
testSpecNoShrink "emptyEitherSpec" emptyEitherSpec
9795
testSpecNoShrink "emptyEitherMemberSpec" emptyEitherMemberSpec
@@ -104,19 +102,19 @@ tests nightly =
104102
testSpec "maybeJustSetSpec" maybeJustSetSpec
105103
testSpec "weirdSetPairSpec" weirdSetPairSpec
106104
testSpec "knownDomainMap" knownDomainMap
107-
-- TODO: figure out double-shrinking
105+
-- TODO: figure out why this doesn't shrink
108106
testSpecNoShrink "testRewriteSpec" testRewriteSpec
109107
testSpec "parallelLet" parallelLet
110108
testSpec "letExists" letExists
111109
testSpec "letExistsLet" letExistsLet
112110
testSpec "notSubset" notSubset
113111
testSpec "unionSized" unionSized
114-
-- TODO: figure out double-shrinking
112+
-- TODO: figure out why this doesn't shrink
115113
testSpecNoShrink "dependencyWeirdness" dependencyWeirdness
116114
testSpec "foldTrueCases" foldTrueCases
117115
testSpec "foldSingleCase" foldSingleCase
118116
testSpec "listSumPair" (listSumPair @Int)
119-
-- TODO: figure out double-shrinking
117+
-- TODO: figure out why this doesn't shrink
120118
testSpecNoShrink "parallelLetPair" parallelLetPair
121119
testSpec "mapSizeConstrained" mapSizeConstrained
122120
testSpec "isAllZeroTree" isAllZeroTree
@@ -134,13 +132,12 @@ tests nightly =
134132
testSpec "sumRange" sumRange
135133
testSpec "sumListBad" sumListBad
136134
testSpec "listExistsUnfree" listExistsUnfree
137-
-- TODO: turn this on when we bump quickcheck version
138-
-- testSpec "listSumShort" listSumShort
135+
testSpec "listSumShort" listSumShort
139136
testSpec "existsUnfree" existsUnfree
140137
testSpec "appendSize" appendSize
141138
testSpecNoShrink "appendSingleton" appendSingleton
142139
testSpec "singletonSubset" singletonSubset
143-
-- TODO: double shrinking
140+
-- TODO: figure out why this doesn't shrink
144141
testSpecNoShrink "reifyYucky" reifyYucky
145142
testSpec "fixedRange" fixedRange
146143
testSpec "rangeHint" rangeHint
@@ -461,6 +458,3 @@ foldWithSizeTests = do
461458
prop "something of size 2, can add to 0 in type with negative values." $
462459
testFoldSpec @Int (between 2 2) (between (-10) 10) (MemberSpec (pure 0)) Succeed
463460
prop "TEST listSum" $ prop_constrained_satisfies_sound (listSum @Int)
464-
465-
-- TODO Needs to sample like this: OR [pick t c | t <- total, c <- count]
466-
-- prop "count =0, total is 0,1,2" $ testFoldSpec @Int (between 0 1) evenSpec (between 0 2) Succeed

0 commit comments

Comments
 (0)