From e42e92270752fcbe049a3d0cbd6ff9bbb2c926e6 Mon Sep 17 00:00:00 2001 From: John Ky Date: Tue, 14 Jan 2025 01:09:53 +1100 Subject: [PATCH] Support for tasty-discover --- .../Zoo/Hedgehog/Test/PropertySpec.hs | 10 +++++----- components/hedgehog-test/Main.hs | 18 +----------------- .../hedgehog/Effectful/Zoo/Hedgehog/Api.hs | 1 + .../Zoo/Hedgehog/Api/Tasty/Orphans.hs | 18 ++++++++++++++++++ effectful-zoo.cabal | 7 ++++++- 5 files changed, 31 insertions(+), 23 deletions(-) create mode 100644 components/hedgehog/Effectful/Zoo/Hedgehog/Api/Tasty/Orphans.hs diff --git a/components/hedgehog-test/Effectful/Zoo/Hedgehog/Test/PropertySpec.hs b/components/hedgehog-test/Effectful/Zoo/Hedgehog/Test/PropertySpec.hs index 0f83f1c..a1dbd38 100644 --- a/components/hedgehog-test/Effectful/Zoo/Hedgehog/Test/PropertySpec.hs +++ b/components/hedgehog-test/Effectful/Zoo/Hedgehog/Test/PropertySpec.hs @@ -2,22 +2,22 @@ module Effectful.Zoo.Hedgehog.Test.PropertySpec where +import Effectful.Zoo.Hedgehog import Effectful.Zoo.Hedgehog.Effect.Run import HaskellWorks.Prelude -import Hedgehog hiding (property, forAll) import Hedgehog qualified as H import Hedgehog.Gen qualified as G import Hedgehog.Range qualified as R -property_spec :: H.PropertyT IO () -property_spec = property do +tasty_property_spec :: PropertyT IO () +tasty_property_spec = property do a <- forAll $ G.int (R.linear 0 100) True === True a === a H.success -test_spec :: H.TestT IO () -test_spec = unit do +tasty_unit_spec :: TestT IO () +tasty_unit_spec = unit do True === True True === True H.success diff --git a/components/hedgehog-test/Main.hs b/components/hedgehog-test/Main.hs index 1d0568e..70c55f5 100644 --- a/components/hedgehog-test/Main.hs +++ b/components/hedgehog-test/Main.hs @@ -1,17 +1 @@ -module Main where - -import Effectful.Zoo.Hedgehog.Api.Tasty -import Effectful.Zoo.Hedgehog.Test.PropertySpec -import Test.Tasty (TestTree, defaultMain, testGroup) -import HaskellWorks.Prelude - -tests :: TestTree -tests = - testGroup "all" - [ toTestTree "Simple property spec" property_spec - , toTestTree "Simple test spec" test_spec - ] - -main :: IO () -main = - defaultMain tests +{-# OPTIONS_GHC -F -pgmF tasty-discover #-} diff --git a/components/hedgehog/Effectful/Zoo/Hedgehog/Api.hs b/components/hedgehog/Effectful/Zoo/Hedgehog/Api.hs index 37a5e26..e027637 100644 --- a/components/hedgehog/Effectful/Zoo/Hedgehog/Api.hs +++ b/components/hedgehog/Effectful/Zoo/Hedgehog/Api.hs @@ -13,4 +13,5 @@ import Effectful.Zoo.Hedgehog.Api.Assert import Effectful.Zoo.Hedgehog.Api.Failure import Effectful.Zoo.Hedgehog.Api.Hedgehog import Effectful.Zoo.Hedgehog.Api.Journal +import Effectful.Zoo.Hedgehog.Api.Tasty.Orphans () import Hedgehog diff --git a/components/hedgehog/Effectful/Zoo/Hedgehog/Api/Tasty/Orphans.hs b/components/hedgehog/Effectful/Zoo/Hedgehog/Api/Tasty/Orphans.hs new file mode 100644 index 0000000..cca75ed --- /dev/null +++ b/components/hedgehog/Effectful/Zoo/Hedgehog/Api/Tasty/Orphans.hs @@ -0,0 +1,18 @@ +{-# OPTIONS_GHC -fno-warn-orphans #-} + +module Effectful.Zoo.Hedgehog.Api.Tasty.Orphans where + +import Data.Monoid +import HaskellWorks.Prelude +import Hedgehog (PropertyT, TestT) +import Hedgehog qualified as H +import Test.Tasty.Discover +import Test.Tasty.Discover.TastyInfo +import Test.Tasty.Hedgehog + +instance Tasty (PropertyT IO ()) where + tasty info = pure . testProperty testName . H.property + where testName = fromMaybe "" $ getLast info.name + +instance Tasty (TestT IO ()) where + tasty info = tasty info . H.test diff --git a/effectful-zoo.cabal b/effectful-zoo.cabal index f0f099b..ec89b6e 100644 --- a/effectful-zoo.cabal +++ b/effectful-zoo.cabal @@ -58,6 +58,7 @@ common resourcet { build-depends: resourcet >= common resourcet-effectful { build-depends: resourcet-effectful >= 1.0.1 && < 2 } common stm { build-depends: stm >= 2.5.1 && < 3 } common tasty { build-depends: tasty >= 1.5 && < 2 } +common tasty-discover { build-depends: tasty-discover >= 5 && < 6 } common tasty-hedgehog { build-depends: tasty-hedgehog >= 1.1.0.0 && < 1.5 } common temporary { build-depends: temporary >= 1.3 && < 2 } common testcontainers { build-depends: testcontainers >= 0.5 && < 0.6 } @@ -300,6 +301,7 @@ library hedgehog lifted-base, resourcet, stm, + tasty-discover, tasty-hedgehog, tasty, text, @@ -327,6 +329,7 @@ library hedgehog Effectful.Zoo.Hedgehog.Api.Range Effectful.Zoo.Hedgehog.Api.Stack Effectful.Zoo.Hedgehog.Api.Tasty + Effectful.Zoo.Hedgehog.Api.Tasty.Orphans Effectful.Zoo.Hedgehog.Api.Workspace Effectful.Zoo.Hedgehog.Data Effectful.Zoo.Hedgehog.Data.PackagePath @@ -372,14 +375,16 @@ library testcontainers-localstack hs-source-dirs: components/testcontainers-localstack test-suite effectful-zoo-test - import: project-config, + import: base, project-config, effectful-zoo-hedgehog, hedgehog, hw-prelude, tasty, + tasty-discover, type: exitcode-stdio-1.0 main-is: Main.hs other-modules: Effectful.Zoo.Hedgehog.Test.PropertySpec + build-tool-depends: tasty-discover:tasty-discover hs-source-dirs: components/hedgehog-test ghc-options: -threaded -rtsopts