assert4hs-tasty: Provider for tasty runner to run assert4hs tests

[ library, mit, web ] [ Propose Tags ]

Please see the README on GitHub at https://github.com/paweln1986/assert4hs-tasty#readme


[Skip to Readme]
Versions [faq] 0.0.0.1, 0.1.0
Change log ChangeLog.md
Dependencies assert4hs-core (>=0.1.0), base (>=4.7 && <5), tasty (>=1.4.1) [details]
License MIT
Copyright 2021 Pawel Nosal
Author Pawel Nosal
Maintainer p.nosal1986@gmail.com
Category Web
Home page https://github.com/paweln1986/assert4hs-tasty#readme
Bug tracker https://github.com/paweln1986/assert4hs-tasty/issues
Source repo head: git clone https://github.com/paweln1986/assert4hs-tasty
Uploaded by paweln1986 at 2021-04-08T18:47:25Z
Distributions NixOS:0.1.0
Downloads 62 total (62 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Hackage Matrix CI
Docs available [build log]
Last success reported on 2021-04-08 [all 1 reports]

Modules

[Index] [Quick Jump]

Downloads

Maintainer's Corner

For package maintainers and hackage trustees


Readme for assert4hs-tasty-0.1.0

[back to package description]

assert4hs-tasty

assert4hs provider for tasty

Example


data Foo = Foo {name :: String, age :: Int} deriving (Show, Eq)

isSuitableForEmployment :: Assertion Foo
isSuitableForEmployment =
  simpleAssertion (\a -> age a > 17) (\a -> "new employee must be 18 years or older, but it has " <> show (age a))
    . simpleAssertion (\a -> age a < 70) (\a -> "must be younger than 70 years old, but it has " <> show (age a))

unitTests :: TestTree
unitTests =
  testGroup
    "Unit tests"
    [ 
      fluentTestCase "chaining assertions" $ do
        let result = 4
        assertThat result $
          isGreaterThan 5
            . isLowerThan 20,
      fluentTestCase "focusing on part of data structure" $ do
        assertThat (Foo "someName" 15) $
          isEqualTo (Foo "someName" 15)
            . focus age
            . isGreaterThan 20
            . isLowerEqualThan 5,
      fluentTestCase "Changing subject uder test" $ do
        assertThat (Foo "someName" 15) $
          inside age (isGreaterThan 20 . isLowerEqualThan 5)
            . focus name
            . isEqualTo "someName1",
      fluentTestCase "Tagging assertions" $ do
        assertThat (Foo "someName" 15) $
          inside age (tag "age" . isGreaterThan 20 . isLowerEqualThan 5)
            . tag "name"
            . focus name
            . isEqualTo "someName1"
            . tag "should not be equal"
            . isNotEqualTo "someName",
      fluentTestCase "Custom assertions" $ do
        assertThat (Foo "someName" 15) isSuitableForEmployment,
        fluentTestCase "Custom assertions" $ do
        assertThat (Foo "someName" 76) isSuitableForEmployment
    ]

>>> Progress 1/2: assert4hsTests
>>>   Unit tests
>>>     chaining assertions:                FAIL
>>>       (test/Spec.hs:46): 
>>>       given 4 should be greater than 5
>>>     passed: 1, failed: 1, total: 2
>>>     focusing on part of data structure: FAIL
>>>       (test/Spec.hs:52): 
>>>       given 15 should be greater than 20
>>>       
>>>       (test/Spec.hs:53): 
>>>       given 15 should be lower or equal to 5
>>>     passed: 1, failed: 2, total: 3
>>>     Changing subject uder test:         FAIL
>>>       (test/Spec.hs:56): 
>>>       given 15 should be greater than 20
>>>       
>>>       (test/Spec.hs:56): 
>>>       given 15 should be lower or equal to 5
>>>       
>>>       (test/Spec.hs:58): 
>>>       given "someName" should be equal to "someName1"
>>>       "someName"
>>>       ╷
>>>       │
>>>       ╵
>>>       "someName1"
>>>                ▲
>>>     passed: 0, failed: 3, total: 3
>>>     Tagging assertions:                 FAIL
>>>       (test/Spec.hs:61): 
>>>       [age] given 15 should be greater than 20
>>>       
>>>       (test/Spec.hs:61): 
>>>       [age] given 15 should be lower or equal to 5
>>>       
>>>       (test/Spec.hs:64): 
>>>       [name] given "someName" should be equal to "someName1"
>>>       "someName"
>>>       ╷
>>>       │
>>>       ╵
>>>       "someName1"
>>>                ▲
>>>       (test/Spec.hs:66): 
>>>       [name.should not be equal] given "someName" should be not equal to "someName"
>>>     passed: 0, failed: 4, total: 4
>>>     Custom assertions:                  FAIL
>>>       (test/Spec.hs:35): 
>>>       new employee must be 18 years or older, but it has 15
>>>     passed: 1, failed: 1, total: 2
>>>     Custom assertions:                  FAIL
>>>       (test/Spec.hs:36): 
>>>       must be younger than 70 years old, but it has 76
>>>     passed: 1, failed: 1, total: 2
>>> 
>>> 6 out of 6 tests failed (0.01s)