typeable-mock 0.1.0.0 → 0.1.0.1
raw patch · 4 files changed
+24/−8 lines, 4 files
Files
- ChangeLog.md +4/−0
- src/Test/TypeableMock.hs +5/−5
- test/Spec.hs +12/−2
- typeable-mock.cabal +3/−1
ChangeLog.md view
@@ -1,4 +1,8 @@ # Changelog for typeable-mock +## 0.1.0.1+- Add category and synopsis to package description+- Add call stack to callMatches+ ## 0.1.0.0 - The first release
src/Test/TypeableMock.hs view
@@ -54,7 +54,7 @@ import Data.Function.Variadic import Data.Function.Variadic.Utils (composeN, constN) import Data.IORef (IORef, modifyIORef, newIORef, readIORef, writeIORef)-import Data.List (foldl', intercalate)+import Data.List (foldl') import Data.Map (Map) import qualified Data.Map as Map import Data.Maybe@@ -118,7 +118,7 @@ | MockFailureNotCalled ExpectedCallRecord instance Show MockFailureReason where- show reason = intercalate "\n" $ case reason of+ show reason = unlines $ case reason of MockFailureArgumentCountMismatch (ActualCallRecord actArgs _) (ExpectedCallRecord expArgs _) -> ["Number of arguments does not match:", "expected: " ++ show (length expArgs), "but got: " ++ show (length actArgs)] MockFailureArgumentTypeMismatch actual expected ->@@ -134,7 +134,7 @@ instance Show MockFailure where show MockFailure {..} =- intercalate "\n" $+ unlines $ ["Assertion failed for " <> show mfMock, show mfReason] <> maybe [] (\loc -> ["at:", prettyLocation loc]) mfLocation where prettyLocation SrcLoc {..} = srcLocFile ++ ":" ++ show srcLocStartLine ++ ":" ++ show srcLocStartCol ++ " in " ++ srcLocPackage ++ ":" ++ srcLocModule@@ -368,7 +368,7 @@ -- | The expected call record matches the actual one. Note that it throws -- error for the logic bugs when a mismatch is caused by wrong number -- of arguments or wrong types.-callMatches :: ActualCallRecord -> ExpectedCallRecord -> Bool+callMatches :: HasCallStack => ActualCallRecord -> ExpectedCallRecord -> Bool callMatches actCall expCall = case checkCallRecord actCall expCall of Nothing -> True Just MockFailureArgumentValueMismatch {} -> False@@ -376,7 +376,7 @@ Just reason -> error $ "callMatches: invalid arguments\n" <> show reason -- | Assert that the expected call happened at least once.-assertAnyCall :: ExpectedCallRecord -> Mock -> IO ()+assertAnyCall :: HasCallStack => ExpectedCallRecord -> Mock -> IO () assertAnyCall expCall mock = do actualCalls <- getCalls mock unless (any (\actCall -> isNothing $ checkCallRecord actCall expCall) actualCalls) $ do
test/Spec.hs view
@@ -2,6 +2,7 @@ import Control.Monad (void) import Control.Monad.IO.Class (MonadIO (..))+import Data.List (isInfixOf) import Data.Maybe (fromMaybe, isNothing) import Data.Typeable (Typeable) import Test.Hspec@@ -157,6 +158,10 @@ printWithMock mockConf "one" assertHasCalls [expectCall AnyVal] printStringMock + it "callMatches fails on incompatible arguments" $ do+ (callMatches (ActualCallRecord [] (ActualVal ())) (ExpectedCallRecord [] (ExpectedVal True)) `seq` pure ())+ `shouldThrow` anyErrorCall+ describe "Retrieving mocks" $ do describe "lookupMock" $ do it "finds mock" $ do@@ -205,7 +210,12 @@ lookupMockTyped @(Int -> IO ()) mockConf "print" `shouldSatisfy` isNothing - describe "Display" $ do- it "shows Mock correctly" $ do+ describe "Messages" $ do+ it "shows Mock" $ do mock <- makeMock "print" (const $ pure () :: Int -> IO ()) show mock `shouldBe` "Mock (print :: Int -> IO ())"++ it "shows MockFailure" $ do+ printWithMock mockConf "one"+ assertHasCalls [expectCall "two"] printStringMock `shouldThrow` \(e :: MockFailure) ->+ "test/Spec.hs" `isInfixOf` show e
typeable-mock.cabal view
@@ -5,8 +5,10 @@ -- see: https://github.com/sol/hpack name: typeable-mock-version: 0.1.0.0+version: 0.1.0.1+synopsis: Mock functions and expressions anywhere. description: Please see the README on GitHub at <https://github.com/lykahb/typeable-mock#readme>+category: Testing homepage: https://github.com/lykahb/typeable-mock#readme bug-reports: https://github.com/lykahb/typeable-mock/issues author: Boris Lykah