Skip to content

Commit

Permalink
test: Set nonzero exitcode when tests fail
Browse files Browse the repository at this point in the history
* Create a single list of quickcheck properties
* Test the result of the quickcehck run
* Exit with appropriate status code
  • Loading branch information
414owen committed Dec 26, 2023
1 parent 6adccba commit bc5e551
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
5 changes: 1 addition & 4 deletions tests/DListProperties.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
--------------------------------------------------------------------------------

-- | QuickCheck property tests for DList.
module DListProperties (test) where
module DListProperties (properties) where

--------------------------------------------------------------------------------

Expand Down Expand Up @@ -183,6 +183,3 @@ properties =
("Semigroup stimes", property prop_Semigroup_stimes)
#endif
]

test :: IO ()
test = quickCheckLabeledProperties properties
5 changes: 1 addition & 4 deletions tests/DNonEmptyProperties.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
--------------------------------------------------------------------------------

-- | QuickCheck property tests for DNonEmpty.
module DNonEmptyProperties (test) where
module DNonEmptyProperties (properties) where

--------------------------------------------------------------------------------

Expand Down Expand Up @@ -104,6 +104,3 @@ properties =
("fromList", property prop_fromList),
("Semigroup <>", property prop_Semigroup_append)
]

test :: IO ()
test = quickCheckLabeledProperties properties
14 changes: 10 additions & 4 deletions tests/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,20 @@ import qualified DListProperties
import qualified DNonEmptyProperties
#endif
import qualified OverloadedStrings
import QuickCheckUtil (quickCheckLabeledProperties)
import Control.Monad (unless)
import Test.QuickCheck (isSuccess)
import System.Exit (exitFailure)

--------------------------------------------------------------------------------

main :: IO ()
main = do
DListProperties.test
-- CPP: GHC >= 8 for DNonEmpty
OverloadedStrings.test
result <- quickCheckLabeledProperties $
DListProperties.properties
-- CPP: GHC >= 8 for DNonEmpty
#if __GLASGOW_HASKELL__ >= 800
DNonEmptyProperties.test
++ DNonEmptyProperties.properties
#endif
OverloadedStrings.test
unless (isSuccess result) exitFailure
4 changes: 2 additions & 2 deletions tests/QuickCheckUtil.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ eqOn c f g x = c x ==> f x == g x

--------------------------------------------------------------------------------

quickCheckLabeledProperties :: [(String, Property)] -> IO ()
quickCheckLabeledProperties = quickCheck . conjoin . map (uncurry label)
quickCheckLabeledProperties :: [(String, Property)] -> IO Result
quickCheckLabeledProperties = quickCheckResult . conjoin . map (uncurry label)

--------------------------------------------------------------------------------

Expand Down

0 comments on commit bc5e551

Please sign in to comment.