{-# LANGUAGE ExistentialQuantification #-}
module Test.Tasty.Golden.Extra.GoldenVsShow
( goldenVsShow,
GoldenVsShow (..),
)
where
import qualified Data.Text.Lazy as Text
import Data.Text.Lazy.Encoding (encodeUtf8)
import Test.Tasty (TestName, TestTree)
import qualified Test.Tasty.Discover as Discover
import Test.Tasty.Golden
import Text.Show.Pretty (ppShow)
data GoldenVsShow = forall a. (Show a) => GoldenVsShow FilePath (IO a)
instance Discover.Tasty GoldenVsShow where
tasty :: TastyInfo -> GoldenVsShow -> IO TestTree
tasty TastyInfo
info (GoldenVsShow FilePath
ref IO a
act) =
TestTree -> IO TestTree
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (TestTree -> IO TestTree) -> TestTree -> IO TestTree
forall a b. (a -> b) -> a -> b
$ FilePath -> FilePath -> IO a -> TestTree
forall a. Show a => FilePath -> FilePath -> IO a -> TestTree
goldenVsShow (TastyInfo -> FilePath
Discover.nameOf TastyInfo
info) FilePath
ref IO a
act
goldenVsShow ::
(Show a) =>
TestName ->
FilePath ->
IO a ->
TestTree
goldenVsShow :: forall a. Show a => FilePath -> FilePath -> IO a -> TestTree
goldenVsShow FilePath
name FilePath
ref =
FilePath -> FilePath -> IO ByteString -> TestTree
goldenVsString FilePath
name FilePath
ref (IO ByteString -> TestTree)
-> (IO a -> IO ByteString) -> IO a -> TestTree
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> ByteString) -> IO a -> IO ByteString
forall a b. (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Text -> ByteString
encodeUtf8 (Text -> ByteString) -> (a -> Text) -> a -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FilePath -> Text
Text.pack (FilePath -> Text) -> (a -> FilePath) -> a -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> FilePath
forall a. Show a => a -> FilePath
ppShow)