{-# LANGUAGE CPP #-}

module GetDataFileName (
  withTestFileProperty,
  (<:<),
)
where

import Control.Monad.IO.Class
import Hedgehog.Internal.Property
import Prelude

#ifdef CARDANO_LEDGER_BYRON_TEST
import Paths_cardano_ledger_byron_test (getDataFileName)
#else
import Paths_cardano_ledger_byron (getDataFileName)
#endif

-- | This contraption is necessary because test modules in the folder are used
-- in two different packages, but the file paths for test files are relative to
-- the package itself, which has to accounted for.
withTestFileProperty :: FilePath -> (FilePath -> Property) -> Property
withTestFileProperty :: FilePath -> (FilePath -> Property) -> Property
withTestFileProperty FilePath
fp FilePath -> Property
mkProperty = PropertyConfig -> PropertyT IO () -> Property
Property PropertyConfig
config forall a b. (a -> b) -> a -> b
$ do
  FilePath
actualFilePath <- forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ FilePath -> IO FilePath
getDataFileName FilePath
fp
  Property -> PropertyT IO ()
propertyTest forall a b. (a -> b) -> a -> b
$ FilePath -> Property
mkProperty FilePath
actualFilePath
  where
    config :: PropertyConfig
config = Property -> PropertyConfig
propertyConfig forall a b. (a -> b) -> a -> b
$ FilePath -> Property
mkProperty FilePath
""

(<:<) :: (FilePath -> Property) -> FilePath -> Property
<:< :: (FilePath -> Property) -> FilePath -> Property
(<:<) = forall a b c. (a -> b -> c) -> b -> a -> c
flip FilePath -> (FilePath -> Property) -> Property
withTestFileProperty