Skip to content

Commit cdf3af1

Browse files
Coveralls and stack support (#44)
* Implement coveralls support
1 parent ae8ba1f commit cdf3af1

File tree

12 files changed

+111
-79
lines changed

12 files changed

+111
-79
lines changed

.github/workflows/haskell-ci.yml

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
name: Haskell-CI
2+
permissions:
3+
contents: read
24

35
on:
46
push:
@@ -15,13 +17,13 @@ concurrency:
1517
cancel-in-progress: true
1618

1719
jobs:
18-
linux:
20+
test-with-cabal:
1921
name: Haskell-CI - Linux - ${{ matrix.ghc-version }}
2022

2123
strategy:
2224
matrix:
2325
ghc-version: [latest, 9.12, "9.10", 9.8, 9.6]
24-
os: [ubuntu-24.04]
26+
os: [ubuntu-latest]
2527
fail-fast: false
2628

2729
runs-on: ${{ matrix.os }}
@@ -43,3 +45,45 @@ jobs:
4345
with:
4446
key: ${{ matrix.os }}-${{ matrix.ghc-version }}-${{ github.sha }}
4547
path: ~/.cabal/store
48+
49+
test-with-stack:
50+
name: Stack
51+
runs-on: ubuntu-latest
52+
steps:
53+
- uses: actions/checkout@v4
54+
55+
- uses: haskell-actions/setup@v2
56+
id: setup-haskell-stack
57+
name: Setup Haskell
58+
with:
59+
enable-stack: true
60+
stack-version: latest
61+
ghc-version: 9.6.7
62+
63+
- name: Cache
64+
id: cache
65+
uses: actions/cache@v4
66+
with:
67+
path: |
68+
${{ steps.setup-haskell-stack.outputs.stack-root }}
69+
.stack-work
70+
key: ${{ runner.os }}-stack-${{ github.sha }}
71+
restore-keys: ${{ runner.os }}-stack
72+
73+
- name: Test
74+
run: stack test --coverage --flag constrained-generators:dev
75+
76+
- uses: actions/cache/save@v4
77+
with:
78+
path: |
79+
${{ steps.setup-haskell-stack.outputs.stack-root }}
80+
.stack-work
81+
key: ${{ runner.os }}-stack-${{ github.sha }}
82+
83+
- name: Upload coverage report
84+
env:
85+
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
86+
run: |
87+
[ -n "${COVERALLS_REPO_TOKEN}" ]
88+
curl -L https://github.com/rubik/stack-hpc-coveralls/releases/download/v0.0.7.0/shc-Linux-X64.tar.bz2 | tar xj shc
89+
./shc --repo-token="$COVERALLS_REPO_TOKEN" --partial-coverage --fetch-coverage combined all

constrained-generators.cabal

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ library examples
121121
prettyprinter,
122122
random,
123123

124-
test-suite constrained
124+
test-suite constrained-tests
125125
type: exitcode-stdio-1.0
126126
main-is: Tests.hs
127127
hs-source-dirs: test
@@ -141,9 +141,12 @@ test-suite constrained
141141
QuickCheck,
142142
base,
143143
constrained-generators,
144-
constrained-generators:examples,
145144
containers,
146-
hspec,
145+
hspec
146+
147+
if !flag(dev)
148+
build-depends:
149+
constrained-generators:examples
147150

148151
benchmark bench
149152
type: exitcode-stdio-1.0

examples/Constrained/Examples/Basic.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,3 +363,6 @@ pairCant = constrained' $ \ [var| i |] [var| p |] ->
363363
, not_ $ k `elem_` lit [1..9]
364364
]
365365
]
366+
367+
signumPositive :: Specification Rational
368+
signumPositive = constrained $ \ x -> signum (x * 30) >=. 1

examples/Constrained/Examples/CheatSheet.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ tightFit0 = constrained' $ \x y ->
364364
-- TypeSpec (Cartesian TrueSpec (MemberSpec [0])) []
365365
-- ---
366366
-- assert $ Equal (Fst (ToGeneric v_3)) v_1
367-
-- Env {unEnv = fromList [(v_0,EnvValue 0)]}
367+
-- Env (fromList [(v_0,EnvValue 0)])
368368
-- genFromSpecT ErrorSpec{} with explanation:
369369
-- [1..-1]
370370

src/Constrained/Base.hs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,6 @@ import Constrained.GenT
101101
import Constrained.Generic
102102
import Constrained.List hiding (toList)
103103
import Constrained.TypeErrors
104-
import Control.Monad.Writer (
105-
Writer,
106-
tell,
107-
)
108104
import Data.Foldable (
109105
toList,
110106
)
@@ -524,12 +520,6 @@ class
524520
alternateShow :: TypeSpec a -> BinaryShow
525521
alternateShow _ = NonBinary
526522

527-
monadConformsTo :: a -> TypeSpec a -> Writer [String] Bool
528-
monadConformsTo x spec =
529-
if conformsTo @a x spec
530-
then pure True
531-
else tell ["Fails by " ++ show spec] >> pure False
532-
533523
-- | For some types (especially finite ones) there may be much better ways to construct
534524
-- a Specification than the default method of just adding a large 'bad' list to TypSpec. This
535525
-- function allows each HasSpec instance to decide.

src/Constrained/Conformance.hs

Lines changed: 4 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ module Constrained.Conformance (
1414
conformsToSpec,
1515
conformsToSpecE,
1616
satisfies,
17-
checkPred,
1817
checkPredsE,
1918
) where
2019

@@ -34,59 +33,9 @@ import Data.Semigroup (sconcat)
3433
import Prettyprinter hiding (cat)
3534
import Test.QuickCheck (Property, Testable, property)
3635

37-
-- =========================================================================
38-
39-
-- | Does the Pred evaluate to true under the given Env.
40-
-- If it doesn't, some explanation appears in the failure of the monad 'm'
41-
checkPred :: forall m. MonadGenError m => Env -> Pred -> m Bool
42-
checkPred env = \case
43-
p@(ElemPred bool term xs) -> do
44-
v <- runTerm env term
45-
case (elem v xs, bool) of
46-
(True, True) -> pure True
47-
(True, False) -> fatalErrorNE ("notElemPred reduces to True" :| [show p])
48-
(False, True) -> fatalErrorNE ("elemPred reduces to False" :| [show p])
49-
(False, False) -> pure True
50-
Monitor {} -> pure True
51-
Subst x t p -> checkPred env $ substitutePred x t p
52-
Assert t -> runTerm env t
53-
GenHint {} -> pure True
54-
p@(Reifies t' t f) -> do
55-
val <- runTerm env t
56-
val' <- runTerm env t'
57-
explainNE (NE.fromList ["Reification:", " " ++ show p]) $ pure (f val == val')
58-
ForAll t (x :-> p) -> do
59-
set <- runTerm env t
60-
and
61-
<$> sequence
62-
[ checkPred env' p
63-
| v <- forAllToList set
64-
, let env' = Env.extend x v env
65-
]
66-
Case t bs -> do
67-
v <- runTerm env t
68-
runCaseOn v (mapList thing bs) (\x val ps -> checkPred (Env.extend x val env) ps)
69-
When bt p -> do
70-
b <- runTerm env bt
71-
if b then checkPred env p else pure True
72-
TruePred -> pure True
73-
FalsePred es -> explainNE es $ pure False
74-
DependsOn {} -> pure True
75-
And ps -> checkPreds env ps
76-
Let t (x :-> p) -> do
77-
val <- runTerm env t
78-
checkPred (Env.extend x val env) p
79-
Exists k (x :-> p) -> do
80-
a <- runGE $ k (errorGE . explain "checkPred: Exists" . runTerm env)
81-
checkPred (Env.extend x a env) p
82-
Explain es p -> explainNE es $ checkPred env p
83-
84-
checkPreds :: (MonadGenError m, Traversable t) => Env -> t Pred -> m Bool
85-
checkPreds env ps = and <$> mapM (checkPred env) ps
86-
8736
-- ==========================================================
8837

89-
-- | Like checkPred, But it takes [Pred] rather than a single Pred,
38+
-- | Like checkPredE, But it takes [Pred] rather than a single Pred,
9039
-- and it builds a much more involved explanation if it fails.
9140
-- Does the Pred evaluate to True under the given Env?
9241
-- If it doesn't, an involved explanation appears in the (Just message)
@@ -101,8 +50,9 @@ checkPredsE msgs env ps =
10150
[] -> Nothing
10251
(x : xs) -> Just (NE.nub (sconcat (x NE.:| xs)))
10352

104-
-- | An involved explanation for a single Pred
105-
-- The most important explanations come when an assertion fails.
53+
-- | Does the Pred evaluate to true under the given Env. An involved
54+
-- explanation for a single Pred in case of failure and `Nothing` otherwise.
55+
-- The most important explanations come when an assertion fails.
10656
checkPredE :: Env -> NE.NonEmpty String -> Pred -> Maybe (NE.NonEmpty String)
10757
checkPredE env msgs = \case
10858
p@(ElemPred bool t xs) ->

src/Constrained/Env.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import Prettyprinter
2727
import Prelude hiding (lookup)
2828

2929
-- | Typed environments for mapping @t`Var` a@ to @a@
30-
newtype Env = Env {unEnv :: Map EnvKey EnvValue}
30+
newtype Env = Env (Map EnvKey EnvValue)
3131
deriving newtype (Semigroup, Monoid)
3232
deriving stock (Show)
3333

src/Constrained/NumOrd.hs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,33 @@ instance {-# OVERLAPPABLE #-} (HasSpec a, MaybeBounded a, Integral a, TypeSpec a
774774
then r - signum a
775775
else r
776776

777+
instance HasDivision (Ratio Integer) where
778+
doDivide = (/)
779+
780+
divideSpec 0 _ = TrueSpec
781+
divideSpec a (NumSpecInterval ml mu) = typeSpec ts
782+
where
783+
ts | a > 0 = NumSpecInterval ml' mu'
784+
| otherwise = NumSpecInterval mu' ml'
785+
ml' = adjustLowerBound <$> ml
786+
mu' = adjustUpperBound <$> mu
787+
adjustLowerBound l =
788+
let r = l / a
789+
l' = r * a
790+
in
791+
if l' < l
792+
then r + (l - l') * 2 / a
793+
else r
794+
795+
adjustUpperBound u =
796+
let r = u / a
797+
u' = r * a
798+
in
799+
if u < u'
800+
then r - (u' - u) * 2 / a
801+
else r
802+
803+
777804
instance HasDivision Float where
778805
doDivide = (/)
779806

src/Constrained/Syntax.hs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ module Constrained.Syntax (
5151
computeDependencies,
5252
solvableFrom,
5353
respecting,
54-
dependency,
5554
applyNameHints,
5655
envFromPred,
5756
isLit,
@@ -834,10 +833,6 @@ applyNameHints spec = spec
834833
-- | `Graph` specialized to dependencies for variables
835834
type DependGraph = Graph.Graph Name
836835

837-
-- | A variable depends on a thing witha buch of other variables
838-
dependency :: HasVariables t => Name -> t -> DependGraph
839-
dependency x (freeVarSet -> xs) = Graph.dependency x xs
840-
841836
-- | Everything to the left depends on everything from the right, except themselves
842837
irreflexiveDependencyOn ::
843838
forall t t'. (HasVariables t, HasVariables t') => t -> t' -> DependGraph

stack.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
snapshot: lts-22.44
2+
packages:
3+
- .
4+
system-ghc: true

0 commit comments

Comments
 (0)