Skip to content

Commit 2ad4ea3

Browse files
authored
Error on unused-top-binds in tests (#1030)
This guards against defining a test or benchmark but forgetting to include it in the test tree.
1 parent 7a85bc6 commit 2ad4ea3

File tree

5 files changed

+42
-41
lines changed

5 files changed

+42
-41
lines changed

containers-tests/containers-tests.cabal

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ common deps
4040
, deepseq >=1.2 && <1.6
4141
, template-haskell
4242

43+
common warnings
44+
ghc-options: -Werror=unused-top-binds
45+
4346
common test-deps
4447
import: deps
4548
build-depends:
@@ -140,39 +143,39 @@ library
140143
-----------------------------
141144

142145
benchmark intmap-benchmarks
143-
import: benchmark-deps
146+
import: benchmark-deps, warnings
144147
default-language: Haskell2010
145148
type: exitcode-stdio-1.0
146149
hs-source-dirs: benchmarks
147150
main-is: IntMap.hs
148151
ghc-options: -O2
149152

150153
benchmark intset-benchmarks
151-
import: benchmark-deps
154+
import: benchmark-deps, warnings
152155
default-language: Haskell2010
153156
type: exitcode-stdio-1.0
154157
hs-source-dirs: benchmarks
155158
main-is: IntSet.hs
156159
ghc-options: -O2
157160

158161
benchmark map-benchmarks
159-
import: benchmark-deps
162+
import: benchmark-deps, warnings
160163
default-language: Haskell2010
161164
type: exitcode-stdio-1.0
162165
hs-source-dirs: benchmarks
163166
main-is: Map.hs
164167
ghc-options: -O2
165168

166169
benchmark tree-benchmarks
167-
import: benchmark-deps
170+
import: benchmark-deps, warnings
168171
default-language: Haskell2010
169172
type: exitcode-stdio-1.0
170173
hs-source-dirs: benchmarks
171174
main-is: Tree.hs
172175
ghc-options: -O2
173176

174177
benchmark sequence-benchmarks
175-
import: benchmark-deps
178+
import: benchmark-deps, warnings
176179
default-language: Haskell2010
177180
type: exitcode-stdio-1.0
178181
hs-source-dirs: benchmarks
@@ -183,15 +186,15 @@ benchmark sequence-benchmarks
183186
, transformers
184187

185188
benchmark set-benchmarks
186-
import: benchmark-deps
189+
import: benchmark-deps, warnings
187190
default-language: Haskell2010
188191
type: exitcode-stdio-1.0
189192
hs-source-dirs: benchmarks
190193
main-is: Set.hs
191194
ghc-options: -O2
192195

193196
benchmark graph-benchmarks
194-
import: benchmark-deps
197+
import: benchmark-deps, warnings
195198
default-language: Haskell2010
196199
type: exitcode-stdio-1.0
197200
hs-source-dirs: benchmarks
@@ -201,7 +204,7 @@ benchmark graph-benchmarks
201204
random >=0 && <1.2
202205

203206
benchmark set-operations-intmap
204-
import: benchmark-deps
207+
import: benchmark-deps, warnings
205208
default-language: Haskell2010
206209
type: exitcode-stdio-1.0
207210
hs-source-dirs: benchmarks/SetOperations
@@ -210,7 +213,7 @@ benchmark set-operations-intmap
210213
ghc-options: -O2
211214

212215
benchmark set-operations-intset
213-
import: benchmark-deps
216+
import: benchmark-deps, warnings
214217
default-language: Haskell2010
215218
type: exitcode-stdio-1.0
216219
hs-source-dirs: benchmarks/SetOperations
@@ -219,7 +222,7 @@ benchmark set-operations-intset
219222
ghc-options: -O2
220223

221224
benchmark set-operations-map
222-
import: benchmark-deps
225+
import: benchmark-deps, warnings
223226
default-language: Haskell2010
224227
type: exitcode-stdio-1.0
225228
hs-source-dirs: benchmarks/SetOperations
@@ -228,7 +231,7 @@ benchmark set-operations-map
228231
ghc-options: -O2
229232

230233
benchmark set-operations-set
231-
import: benchmark-deps
234+
import: benchmark-deps, warnings
232235
default-language: Haskell2010
233236
type: exitcode-stdio-1.0
234237
hs-source-dirs: benchmarks/SetOperations
@@ -237,7 +240,7 @@ benchmark set-operations-set
237240
ghc-options: -O2
238241

239242
benchmark lookupge-intmap
240-
import: benchmark-deps
243+
import: benchmark-deps, warnings
241244
default-language: Haskell2010
242245
type: exitcode-stdio-1.0
243246
hs-source-dirs: benchmarks/LookupGE
@@ -246,7 +249,7 @@ benchmark lookupge-intmap
246249
build-depends: containers-tests
247250

248251
benchmark lookupge-map
249-
import: benchmark-deps
252+
import: benchmark-deps, warnings
250253
default-language: Haskell2010
251254
type: exitcode-stdio-1.0
252255
hs-source-dirs: benchmarks/LookupGE
@@ -263,7 +266,7 @@ benchmark lookupge-map
263266
-- plus the testing stuff.
264267

265268
test-suite map-lazy-properties
266-
import: test-deps
269+
import: test-deps, warnings
267270
default-language: Haskell2010
268271
hs-source-dirs: tests
269272
main-is: map-properties.hs
@@ -275,7 +278,7 @@ test-suite map-lazy-properties
275278
CPP
276279

277280
test-suite map-strict-properties
278-
import: test-deps
281+
import: test-deps, warnings
279282
default-language: Haskell2010
280283
hs-source-dirs: tests
281284
main-is: map-properties.hs
@@ -288,7 +291,7 @@ test-suite map-strict-properties
288291
CPP
289292

290293
test-suite bitqueue-properties
291-
import: test-deps
294+
import: test-deps, warnings
292295
default-language: Haskell2010
293296
hs-source-dirs: tests
294297
main-is: bitqueue-properties.hs
@@ -299,7 +302,7 @@ test-suite bitqueue-properties
299302
CPP
300303

301304
test-suite set-properties
302-
import: test-deps
305+
import: test-deps, warnings
303306
default-language: Haskell2010
304307
hs-source-dirs: tests
305308
main-is: set-properties.hs
@@ -317,7 +320,7 @@ test-suite set-properties
317320
Utils.NoThunks
318321

319322
test-suite intmap-lazy-properties
320-
import: test-deps
323+
import: test-deps, warnings
321324
default-language: Haskell2010
322325
hs-source-dirs: tests
323326
main-is: intmap-properties.hs
@@ -330,7 +333,7 @@ test-suite intmap-lazy-properties
330333
CPP
331334

332335
test-suite intmap-strict-properties
333-
import: test-deps
336+
import: test-deps, warnings
334337
default-language: Haskell2010
335338
hs-source-dirs: tests
336339
main-is: intmap-properties.hs
@@ -344,7 +347,7 @@ test-suite intmap-strict-properties
344347
CPP
345348

346349
test-suite intset-properties
347-
import: test-deps
350+
import: test-deps, warnings
348351
default-language: Haskell2010
349352
hs-source-dirs: tests
350353
main-is: intset-properties.hs
@@ -357,7 +360,7 @@ test-suite intset-properties
357360
CPP
358361

359362
test-suite seq-properties
360-
import: test-deps
363+
import: test-deps, warnings
361364
default-language: Haskell2010
362365
hs-source-dirs: tests
363366
main-is: seq-properties.hs
@@ -369,7 +372,7 @@ test-suite seq-properties
369372
CPP
370373

371374
test-suite tree-properties
372-
import: test-deps
375+
import: test-deps, warnings
373376
default-language: Haskell2010
374377
hs-source-dirs: tests
375378
main-is: tree-properties.hs
@@ -381,15 +384,15 @@ test-suite tree-properties
381384
CPP
382385

383386
test-suite graph-properties
384-
import: test-deps
387+
import: test-deps, warnings
385388
default-language: Haskell2010
386389
hs-source-dirs: tests
387390
main-is: graph-properties.hs
388391
type: exitcode-stdio-1.0
389392
ghc-options: -O2
390393

391394
test-suite map-strictness-properties
392-
import: test-deps
395+
import: test-deps, warnings
393396
default-language: Haskell2010
394397
hs-source-dirs: tests
395398
main-is: map-strictness.hs
@@ -412,7 +415,7 @@ test-suite map-strictness-properties
412415
Utils.NoThunks
413416

414417
test-suite intmap-strictness-properties
415-
import: test-deps
418+
import: test-deps, warnings
416419
default-language: Haskell2010
417420
hs-source-dirs: tests
418421
main-is: intmap-strictness.hs
@@ -436,7 +439,7 @@ test-suite intmap-strictness-properties
436439
Utils.NoThunks
437440

438441
test-suite intset-strictness-properties
439-
import: test-deps
442+
import: test-deps, warnings
440443
default-language: Haskell2010
441444
hs-source-dirs: tests
442445
main-is: intset-strictness.hs
@@ -457,7 +460,7 @@ test-suite intset-strictness-properties
457460
Utils.NoThunks
458461

459462
test-suite listutils-properties
460-
import: test-deps
463+
import: test-deps, warnings
461464
default-language: Haskell2010
462465
hs-source-dirs: tests
463466
main-is: listutils-properties.hs

containers-tests/tests/intmap-properties.hs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -216,13 +216,6 @@ main = defaultMain $ testGroup "intmap-properties"
216216
, testProperty "isSubmapOfBy" prop_isSubmapOfBy
217217
]
218218

219-
apply2 :: Fun (a, b) c -> a -> b -> c
220-
apply2 f a b = apply f (a, b)
221-
222-
apply3 :: Fun (a, b, c) d -> a -> b -> c -> d
223-
apply3 f a b c = apply f (a, b, c)
224-
225-
226219
{--------------------------------------------------------------------
227220
Arbitrary, reasonably balanced trees
228221
--------------------------------------------------------------------}

containers-tests/tests/intset-properties.hs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ main = defaultMain $ testGroup "intset-properties"
6767
, testProperty "prop_foldL" prop_foldL
6868
, testProperty "prop_foldL'" prop_foldL'
6969
, testProperty "prop_map" prop_map
70+
, testProperty "prop_mapMonotonicId" prop_mapMonotonicId
71+
, testProperty "prop_mapMonotonicLinear" prop_mapMonotonicLinear
7072
, testProperty "prop_maxView" prop_maxView
7173
, testProperty "prop_minView" prop_minView
7274
, testProperty "prop_split" prop_split
@@ -389,9 +391,15 @@ prop_mapMonotonicId :: IntSet -> Property
389391
prop_mapMonotonicId s = mapMonotonic id s === map id s
390392

391393
prop_mapMonotonicLinear :: Positive Int -> Int -> IntSet -> Property
392-
prop_mapMonotonicLinear (Positive a) b s = mapMonotonic f s === map f s
394+
prop_mapMonotonicLinear (Positive a) b s =
395+
all ok (toList s) ==>
396+
mapMonotonic f s === map f s
393397
where
394398
f x = a*x + b
399+
ok x = -- must not overflow
400+
fromIntegral (minBound :: Int) <= y && y <= fromIntegral (maxBound :: Int)
401+
where
402+
y = fromIntegral a * fromIntegral x + fromIntegral b :: Integer
395403

396404
prop_maxView :: IntSet -> Bool
397405
prop_maxView s = case maxView s of

containers-tests/tests/map-properties.hs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,7 @@ mkArb step n
345345
-- A type with a peculiar Eq instance designed to make sure keys
346346
-- come from where they're supposed to.
347347
data OddEq a = OddEq a Bool deriving (Show)
348-
getOddEq :: OddEq a -> (a, Bool)
349-
getOddEq (OddEq a b) = (a, b)
348+
350349
instance Arbitrary a => Arbitrary (OddEq a) where
351350
arbitrary = OddEq <$> arbitrary <*> arbitrary
352351
instance Eq a => Eq (OddEq a) where

containers-tests/tests/seq-properties.hs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -562,10 +562,8 @@ prop_sort :: Seq OrdA -> Bool
562562
prop_sort xs =
563563
toList' (sort xs) ~= Data.List.sort (toList xs)
564564

565-
data UnstableOrd = UnstableOrd
566-
{ ordKey :: OrdA
567-
, _ignored :: A
568-
} deriving (Show)
565+
data UnstableOrd = UnstableOrd OrdA A
566+
deriving (Show)
569567

570568
instance Eq UnstableOrd where
571569
x == y = compare x y == EQ

0 commit comments

Comments
 (0)