{-# LANGUAGE CPP #-}

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

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

#ifdef CARDANO_CRYPTO_TEST
import Paths_cardano_crypto_test (getDataFileName)

addPrefix :: FilePath -> FilePath
addPrefix = id
#else
import Paths_cardano_crypto_wrapper (getDataFileName)
import System.FilePath

addPrefix :: FilePath -> FilePath
addPrefix :: FilePath -> FilePath
addPrefix FilePath
fp = FilePath
"test" FilePath -> FilePath -> FilePath
</> FilePath
fp
#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 forall a b. (a -> b) -> a -> b
$ FilePath -> FilePath
addPrefix 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