File: Fixtures.hs

package info (click to toggle)
haskell-twitter-types 0.11.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 340 kB
  • sloc: haskell: 1,784; makefile: 5
file content (25 lines) | stat: -rw-r--r-- 741 bytes parent folder | download | duplicates (3)
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