1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
{-# LANGUAGE CPP #-}
module Fixtures where
import Data.Aeson
import Data.ByteString as S
import System.FilePath
import Test.Tasty.HUnit
fixturePath :: FilePath -> FilePath
fixturePath filename = takeDirectory __FILE__ </> "fixtures" </> filename
readFixtureFile :: FilePath -> IO ByteString
readFixtureFile = S.readFile . fixturePath
withFixtureJSON :: FromJSON a => FilePath -> (a -> Assertion) -> Assertion
withFixtureJSON filename assertions = do
body <- readFixtureFile filename
withJSON body assertions
withJSON :: FromJSON a => ByteString -> (a -> Assertion) -> Assertion
withJSON body assertions = do
case eitherDecodeStrict' body of
Left err -> assertFailure $ err
Right result -> assertions result
|