Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for different test and property names #42

Merged
merged 4 commits into from
Mar 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@
/cabal.sandbox.config
/cabal.project.local
result

.stack-work/
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ main =
testGroup "tasty-hedgehog tests"
[ testProperty
"reverse involutive"
"prop_reverse_involutive"
prop_reverse_involutive
]
```
Expand Down Expand Up @@ -106,10 +107,12 @@ main =
testGroup "tasty-hedgehog tests"
[ testProperty
"reverse involutive"
"prop_reverse_involutive"
prop_reverse_involutive
, expectFail $ testProperty
"badReverse involutive fails"
prop_badReverse_involutive
"prop_badReverse_involutive"
prop_badReverse_involutive
]
```
and now running the tests will give you something like this:
Expand Down
6 changes: 5 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Revision history for tasty-hedgehog

## 1.2.0.0 -- 2022-03-07

* Add `testPropertyNamed` function and deprecate `testProperty`.

## 1.1.0.0 -- 2021-04-03

* Add fromGroup function
Expand All @@ -25,7 +29,7 @@
## 0.2.0.0 -- 2018-03-13

* Removes the verbosity option, which was unsupported
* Fixes a bug in configuration option handling, which
* Fixes a bug in configuration option handling, which
was overwriting use configuration with the defaults.

## 0.1.0.2 -- 2018-01-22
Expand Down
32 changes: 26 additions & 6 deletions src/Test/Tasty/Hedgehog.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
--
-- @
-- testGroup "tasty-hedgehog tests" [
-- testProperty "reverse involutive" prop_reverse_involutive
-- , testProperty "sort idempotent" prop_sort_idempotent
-- testPropertyNamed "reverse involutive" "prop_reverse_involutive" prop_reverse_involutive
-- , testPropertyNamed "sort idempotent" "prop_sort_idempotent" prop_sort_idempotent
-- ]
-- @
--
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module Test.Tasty.Hedgehog (
testProperty
, testPropertyNamed
, fromGroup
-- * Options you can pass in via tasty
, HedgehogReplay(..)
Expand All @@ -36,12 +37,31 @@ import Hedgehog.Internal.Runner as H
import Hedgehog.Internal.Report
import Hedgehog.Internal.Seed as Seed

data HP = HP T.TestName Property
data HP = HP PropertyName Property
deriving (Typeable)

-- | Create a 'T.TestTree' from a Hedgehog 'Property'.
{-# DEPRECATED testProperty "testProperty will cause Hedgehog to provide incorrect instructions for re-checking properties" #-}
testProperty :: T.TestName -> Property -> T.TestTree
testProperty name prop = T.singleTest name (HP name prop)
testProperty name prop = T.singleTest name (HP (PropertyName name) prop)

-- | `testPropertyNamed` @testName propertyName property@ creates a
-- 'T.TestTree' from @property@ using @testName@ as the displayed
-- description for the property. The @propertyName@ is used by Hedgehog
-- when a failure occurs to provide instructions for how to re-run
-- the property and should normally be set to a string representation
-- of the @property@ argument.
--
-- @
-- testPropertyNamed
-- "reverse is involutive"
-- "prop_reverse_involutive"
-- prop_reverse_involutive
-- @
--
-- @since 1.2.0.0
testPropertyNamed :: T.TestName -> PropertyName -> Property -> T.TestTree
testPropertyNamed name propName prop = T.singleTest name (HP propName prop)

-- | Create a 'T.TestTree' from a Hedgehog 'Group'.
fromGroup :: Group -> T.TestTree
Expand Down Expand Up @@ -142,11 +162,11 @@ reportToProgress config (Report testsDone _ _ status) =

reportOutput :: Bool
-> UseColor
-> String
-> PropertyName
-> Report Result
-> IO String
reportOutput showReplay useColor name report = do
s <- renderResult useColor (Just (PropertyName name)) report
s <- renderResult useColor (Just name) report
pure $ case reportStatus report of
Failed fr ->
let
Expand Down
2 changes: 1 addition & 1 deletion tasty-hedgehog.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: tasty-hedgehog
version: 1.1.0.0
version: 1.2.0.0
license: BSD3
license-file: LICENCE
author: Dave Laing
Expand Down
10 changes: 9 additions & 1 deletion test/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,13 @@ main =
prop_reverse_involutive
, expectFail $ testProperty
"badReverse involutive fails"
prop_badReverse_involutive
prop_badReverse_involutive
, testPropertyNamed
"reverse involutive"
"prop_reverse_involutive"
prop_reverse_involutive
, expectFail $ testPropertyNamed
"badReverse involutive fails"
"prop_badReverse_involutive"
prop_badReverse_involutive
]