-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A set of assertion for writing more readable tests cases -- -- Please see the README on GitHub at -- https://github.com/paweln1986/assert4hs#readme @package assert4hs-core @version 0.1.0 -- | This module provide an assertion for check if expected Exception has -- been throw by IO action. module Test.Fluent.Assertions.Exceptions -- | Select all exceptions. anyException :: ExceptionSelector SomeException -- | Select all IOException. anyIOException :: ExceptionSelector IOException -- | Select all an Exception of given type. This selector should be used -- with TypeApplications -- --
-- data MyException = ThisException | ThatException -- deriving (Show) -- -- instance Exception MyException -- -- selectMyException = exceptionType @MyException --exceptionOfType :: Exception e => ExceptionSelector e type ExceptionSelector a = a -> a module Test.Fluent.Diff pretty :: Show a => a -> a -> String module Test.Fluent.Internal.AssertionConfig newtype AssertionConfig AssertionConfig :: Int -> AssertionConfig [assertionTimeout] :: AssertionConfig -> Int -- | Default configuration used for assertThat and -- assertThatIO. - default timeout is set to 5 seconds defaultConfig :: AssertionConfig -- | Allow to modify timeout of single assertion setAssertionTimeout :: Int -> AssertionConfig -> AssertionConfig instance GHC.Show.Show Test.Fluent.Internal.AssertionConfig.AssertionConfig -- | This library aims to provide a set of combinators to assert arbitrary -- nested data structures. The inspiration of this library is AssertJ for -- Java, the composition of assertions was inspired by lens -- library. -- -- Example: -- --
-- data Foo = Foo {name :: String, age :: Int} deriving (Show, Eq)
--
-- assertThat (Foo "someName" 15) $
-- isEqualTo (Foo "someN1ame" 15)
-- . focus age
-- . tag "age"
-- . isGreaterThan 20
--
--
-- result in
--
--
-- given Foo {name = "someName", age = 15} should be equal to Foo {name = "someN1ame", age = 15}
-- Foo {name = "someName", age = 15}
-- ╷
-- │
-- ╵
-- Foo {name = "someN1ame", age = 15}
-- ▲
-- [age] given 15 should be greater than 20
--
module Test.Fluent.Assertions
-- | The simpleAssertion function is a building block of more
-- complicated assertions.
--
-- It takes one predicate and function to format error message.
--
-- -- myIsEqual x = simpleAssertion (== x) (\x' -> show x' <> " is not equal to " <> show x) --simpleAssertion :: HasCallStack => (a -> Bool) -> (a -> String) -> Assertion a -- | assert if subject under test is equal to given value -- --
-- assertThat 15 $ isEqualTo 16 ---- -- result -- --
-- given 15 should be equal to 16 -- ▼ -- 15 -- ╷ -- │ -- ╵ -- 16 -- ▲ --isEqualTo :: (Eq a, Show a, HasCallStack) => a -> Assertion a isNotEqualTo :: (Eq a, Show a, HasCallStack) => a -> Assertion a -- | assert if the subject under test is greater than given value -- --
-- assertThat 15 $ isGreaterThan 16 ---- -- result -- --
-- given 15 should be greater than 16 --isGreaterThan :: (Ord a, Show a, HasCallStack) => a -> Assertion a isGreaterEqualThan :: (Ord a, Show a, HasCallStack) => a -> Assertion a -- | assert if the subject under test is lower than given value -- --
-- assertThat 16 $ isLowerThan 15 ---- -- result -- --
-- given 16 should be lower than 15 --isLowerThan :: (Ord a, Show a, HasCallStack) => a -> Assertion a isLowerEqualThan :: (Ord a, Show a, HasCallStack) => a -> Assertion a shouldSatisfy :: (Show a, HasCallStack) => (a -> Bool) -> Assertion a hasSize :: (Foldable t, HasCallStack) => Int -> Assertion (t a) isEmpty :: (Foldable t, HasCallStack) => Assertion (t a) isNotEmpty :: (Foldable t, HasCallStack) => Assertion (t a) contains :: (Foldable t, Eq a, Show a, HasCallStack) => a -> Assertion (t a) -- | allow changing subject under test using a transformation function -- --
-- assertThat "1 " $ -- isNotEqualTo "" -- . focus length -- . isEqualTo 10 ---- -- result -- --
-- given 5 should be equal to 10 -- ▼ -- 5 -- ╷ -- │ -- ╵ -- 10 -- ▲▲ --focus :: (a -> b) -> Assertion' a b -- | like focus, this function allow changing subject under test, it -- takes an assertion for modified value, then it allows us to continue -- assertion on the original value -- --
-- assertThat (Foo "someName" 15) $ -- isEqualTo (Foo "someN1ame" 15) -- . inside age (tag "age" . isGreaterThan 20 . isLowerThan 10) -- . isEqualTo (Foo "someName" 15) ---- -- result -- --
-- given Foo {name = "someName", age = 15} should be equal to Foo {name = "someN1ame", age = 15}
-- Foo {name = "someName", age = 15}
-- ╷
-- │
-- ╵
-- Foo {name = "someN1ame", age = 15}
-- ▲
-- [age] given 15 should be greater than 20
-- [age] given 15 should be lower than 10
--
inside :: (b -> a) -> Assertion a -> Assertion b
-- | this combinator allows marking following assertion with a given prefix
--
-- -- assertThat (Foo "someName" 15) $ -- tag "foo" . isEqualTo (Foo "someN1ame" 15) -- . inside age (tag "age" . isGreaterThan 20 . isLowerThan 10) -- . tag "foo not equal" -- . isNotEqualTo (Foo "someName" 15) ---- -- result -- --
-- [foo] given Foo {name = "someName", age = 15} should be equal to Foo {name = "someN1ame", age = 15}
-- Foo {name = "someName", age = 15}
-- ╷
-- │
-- ╵
-- Foo {name = "someN1ame", age = 15}
-- ▲
-- [foo.age] given 15 should be greater than 20
-- [foo.age] given 15 should be lower than 10
-- [foo.not equal to] given Foo {name = "someName", age = 15} should be not equal to Foo {name = "someName", age = 15}
-- Foo {name = "someName", age = 15}
-- ╷
-- │
-- ╵
-- Foo {name = "someName", age = 15}
--
tag :: String -> Assertion a
-- | Sometimes it is handy to stop the assertions chain.
--
-- This combinator gets an assertion that should be forced, any following
-- assertion will be not executed then
--
-- -- extracting :: HasCallStack => Assertion' (Maybe a) a -- extracting = forceError isJust . focus Maybe.fromJust --forceError :: Assertion a -> Assertion a data AssertionConfig -- | Default configuration used for assertThat and -- assertThatIO. - default timeout is set to 5 seconds defaultConfig :: AssertionConfig -- | Allow to modify timeout of single assertion setAssertionTimeout :: Int -> AssertionConfig -> AssertionConfig type Assertion a = Assertion' a a type Assertion' a b = Assertion'' a a b b data FluentTestFailure FluentTestFailure :: !Maybe SrcLoc -> ![(String, Maybe SrcLoc)] -> !Int -> !Int -> FluentTestFailure [srcLoc] :: FluentTestFailure -> !Maybe SrcLoc [msg] :: FluentTestFailure -> ![(String, Maybe SrcLoc)] [errorsCount] :: FluentTestFailure -> !Int [successCount] :: FluentTestFailure -> !Int -- | This library aims to provide a set of combinators to assert Maybe -- type. module Test.Fluent.Assertions.Maybe -- | assert if subject under is empty -- --
-- assertThat (Just 10) isNothing --isNothing :: HasCallStack => Assertion (Maybe a) -- | assert if subject under is not empty -- --
-- assertThat (Just 10) isJust --isJust :: HasCallStack => Assertion (Maybe a) -- | assert if subject under is not empty and extract contained value -- --
-- assertThat (Just 10) extracting --extracting :: HasCallStack => Assertion' (Maybe a) a -- | This library aims to provide a set of combinators to assert List type. module Test.Fluent.Assertions.List -- | assert if given list has same length as expected list -- --
-- assertThat [1..10] $ shouldHaveSameSizeAs [0..10] --shouldHaveSameSizeAs :: HasCallStack => [a] -> Assertion [a] -- | verify if the given list has a length lower or equal to expected value -- --
-- assertThat [1..10] $ shouldHaveSizeLowerOrEqual 10 --shouldHaveSizeLowerOrEqual :: HasCallStack => Int -> Assertion [a] -- | verify if the given list has expected prefix -- --
-- assertThat [1..10] $ shouldStartWith [0..4] --shouldStartWith :: (Eq a, Show a, HasCallStack) => [a] -> Assertion [a] -- | verify if the given list does not start with prefix -- --
-- assertThat [1..10] $ shouldNotStartWith [1..4] --shouldNotStartWith :: (Eq a, Show a, HasCallStack) => [a] -> Assertion [a] shouldBeSameAs :: (Eq a, HasCallStack, Show a) => [a] -> Assertion [a] shouldContain :: (Eq a, HasCallStack, Show a) => a -> Assertion [a] shouldNotContain :: (Eq a, HasCallStack, Show a) => a -> Assertion [a] -- | verify if the given list contains same elements as expected list in -- any order -- --
-- assertThat [1..10] $ shouldNotStartWith [1..4] --shouldHaveSameElements :: (HasCallStack, Eq a, Show a) => [a] -> Assertion [a] -- | This module provide a set of combinators to assert Either type. module Test.Fluent.Assertions.Either -- | assert if subject under test is Left -- --
-- assertThat (Left 10) isLeft --isLeft :: HasCallStack => Assertion (Either a b) -- | assert if subject under test is Right -- --
-- assertThat (Left 10) isRight --isRight :: HasCallStack => Assertion (Either a b) -- | assert if subject under test is Right and extract contained value -- --
-- assertThat (Left 10) extractingRight --extractingRight :: HasCallStack => Assertion' (Either a b) b -- | assert if subject under test is Left and extract contained value -- --
-- assertThat (Left 10) extractingLeft --extractingLeft :: HasCallStack => Assertion' (Either a b) a module Test.Fluent.Assertions.Core -- | Execute assertions against given subject under test. assertThat :: HasCallStack => a -> Assertion' a b -> IO () -- | Execute assertions against given subject under test extracted from IO -- action. assertThatIO :: HasCallStack => IO a -> Assertion' a b -> IO () -- | A variant of assertThat which allow to pass additional -- configuration. assertThat' :: HasCallStack => AssertionConfig -> a -> Assertion' a b -> IO () -- | A variant of assertThatIO which allow to pass additional -- configuration. assertThatIO' :: HasCallStack => AssertionConfig -> IO a -> Assertion' a c -> IO () -- | Execute assertions against selected exception assertThrown :: (HasCallStack, Exception e) => IO a -> ExceptionSelector e -> Assertion' e b -> IO () assertThrown' :: (HasCallStack, Exception e) => AssertionConfig -> IO a -> ExceptionSelector e -> Assertion' e b -> IO () assertThrows' :: (HasCallStack, Exception e) => AssertionConfig -> IO a -> ExceptionSelector e -> IO () -- | Module : Test.Fluent.Assertions.Core Description : Set util function -- to execute assertions against given value Copyright : (c) Pawel Nosal, -- 2021 License : MIT Maintainer : p.nosal1986@gmail.com Stability : -- experimental -- -- Verify if given IO action throws expected exception. assertThrows :: (HasCallStack, Exception e) => IO a -> ExceptionSelector e -> IO ()