diff --git a/.gitignore b/.gitignore index 45a644c..9f66d7f 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,5 @@ /cabal.sandbox.config /cabal.project.local result + +.stack-work/ diff --git a/README.md b/README.md index 8cfb11f..72b6b50 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,7 @@ main = testGroup "tasty-hedgehog tests" [ testProperty "reverse involutive" + "prop_reverse_involutive" prop_reverse_involutive ] ``` @@ -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: diff --git a/changelog.md b/changelog.md index 5ce1445..1dfa5ac 100644 --- a/changelog.md +++ b/changelog.md @@ -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 @@ -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 diff --git a/src/Test/Tasty/Hedgehog.hs b/src/Test/Tasty/Hedgehog.hs index 12e5ae6..a593d84 100644 --- a/src/Test/Tasty/Hedgehog.hs +++ b/src/Test/Tasty/Hedgehog.hs @@ -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(..) @@ -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 @@ -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 diff --git a/tasty-hedgehog.cabal b/tasty-hedgehog.cabal index 83f066b..dd8c50a 100644 --- a/tasty-hedgehog.cabal +++ b/tasty-hedgehog.cabal @@ -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 diff --git a/test/Main.hs b/test/Main.hs index 46d1804..2978bdb 100644 --- a/test/Main.hs +++ b/test/Main.hs @@ -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 ]