packages feed

should-not-typecheck 2.0 → 2.0.1

raw patch · 5 files changed

+37/−15 lines, 5 files

Files

CHANGELOG.md view
@@ -1,5 +1,8 @@ # `should-not-typecheck` changelog +## 2.0.1+* Support HUnit 1.3+ ## 2.0 * Changed API to require `NFData a` so we can fully evaluate expressions, rather than just converting to WHNF. 
README.md view
@@ -96,7 +96,7 @@  main :: IO () main = hspec $ do-  decsribe 4 $ do -- Oops!+  describe 4 $ do -- Oops!    -- ... ``` 
should-not-typecheck.cabal view
@@ -1,5 +1,5 @@ name:                should-not-typecheck-version:             2.0+version:             2.0.1 synopsis:            A HUnit/hspec assertion library to verify that an expression does not typecheck description:   For examples and an introduction to the library please take a look at the <https://github.com/CRogers/should-not-typecheck#should-not-typecheck- README> on github.
stack.yaml view
@@ -2,4 +2,4 @@ packages: - '.' extra-deps: []-resolver: lts-2.14+resolver: nightly-2015-09-07
test/ShouldNotTypecheckSpec.hs view
@@ -1,4 +1,4 @@-{-# LANGUAGE GADTs, TemplateHaskell #-}+{-# LANGUAGE GADTs, TemplateHaskell, CPP #-} {-# OPTIONS_GHC -fdefer-type-errors #-}  module Main where@@ -8,24 +8,43 @@ import GHC.Generics (Generic) import Test.Hspec import Test.Hspec.Expectations (expectationFailure)-import Test.HUnit.Lang (performTestCase)+import qualified Test.HUnit.Lang as HL import Test.ShouldNotTypecheck +data Result+  = Success+  | Failure+  | Error String++#if MIN_VERSION_HUnit(1,3,0)+toResult :: HL.Result -> Result+toResult result = case result of+  HL.Success -> Success+  HL.Failure _ _ -> Failure+  HL.Error _ msg -> Error msg+#else+toResult :: Maybe (Bool, String) -> Result+toResult result = case result of+  Nothing -> Success+  Just (True, _) -> Failure+  Just (False, msg) -> Error msg+#endif+ shouldFailAssertion :: IO () -> IO () shouldFailAssertion value = do-  result <- performTestCase value-  case result of-    Nothing           -> expectationFailure "Did not throw an assertion error"-    Just (True,  _)   -> return ()-    Just (False, msg) -> expectationFailure $ "Raised an error " ++ msg+  result <- HL.performTestCase value+  case toResult result of+    Success   -> expectationFailure "Did not throw an assertion error"+    Failure   -> return ()+    Error msg -> expectationFailure $ "Raised an error " ++ msg  shouldThrowException :: Exception e => e -> IO () -> IO () shouldThrowException exception value = do-  result <- performTestCase value-  case result of-    Nothing           -> expectationFailure "Did not throw exception: assertion succeeded"-    Just (True,  _)   -> expectationFailure "Did not throw exception: assertion failed"-    Just (False, msg) -> case msg == show exception of+  result <- HL.performTestCase value+  case toResult result of+    Success   -> expectationFailure "Did not throw exception: assertion succeeded"+    Failure   -> expectationFailure "Did not throw exception: assertion failed"+    Error msg -> case msg == show exception of       True -> return ()       False -> expectationFailure "Incorrect exception propagated"