@@ -15,11 +15,11 @@ import qualified Data.Conduit as C
15import qualified Control.Monad.Trans.Resource as C
15import qualified Control.Monad.Trans.Resource as C
16import qualified Data.Conduit.List as CL
16import qualified Data.Conduit.List as CL
18−import System.Directory
19import Control.Monad
18import Control.Monad
20import Control.Exception (try, SomeException)
19import Control.Exception (try, SomeException)
21import Test.Hspec
20import Test.Hspec
22−import Test.Hspec.Expectations.Contrib
21+import Data.Either.Compat
22+import Test.Mockery.Directory
24import qualified Data.Yaml as D
24import qualified Data.Yaml as D
25import Data.Yaml (object, array, (.=))
25import Data.Yaml (object, array, (.=))
@@ -237,26 +237,17 @@ caseEncodeDecode = do
237 yamlString = "foo: bar\nbaz:\n - bin1\n - bin2\n"
237 yamlString = "foo: bar\nbaz:\n - bin1\n - bin2\n"
238 yamlBS = B8.pack yamlString
238 yamlBS = B8.pack yamlString
240−removeFile' :: FilePath -> IO ()
242− x <- doesFileExist fp
243− when x $ removeFile fp
245caseEncodeDecodeFile :: Assertion
240caseEncodeDecodeFile :: Assertion
246−caseEncodeDecodeFile = do
241+caseEncodeDecodeFile = withFile "" $ \tmpPath -> do
248 eList <- C.runResourceT $ Y.decodeFile filePath C.$$ CL.consume
242 eList <- C.runResourceT $ Y.decodeFile filePath C.$$ CL.consume
249 C.runResourceT $ CL.sourceList eList C.$$ Y.encodeFile tmpPath
243 C.runResourceT $ CL.sourceList eList C.$$ Y.encodeFile tmpPath
250 eList2 <- C.runResourceT $ Y.decodeFile filePath C.$$ CL.consume
244 eList2 <- C.runResourceT $ Y.decodeFile filePath C.$$ CL.consume
251 map MyEvent eList @=? map MyEvent eList2
245 map MyEvent eList @=? map MyEvent eList2
253 filePath = "test/largest-string.yaml"
247 filePath = "test/largest-string.yaml"
254− tmpPath = "tmp.yaml"
256caseInterleave :: Assertion
249caseInterleave :: Assertion
257−caseInterleave = do
250+caseInterleave = withFile "" $ \tmpPath -> withFile "" $ \tmpPath2 -> do
259− removeFile' tmpPath2
260 () <- C.runResourceT $ Y.decodeFile filePath C.$$ Y.encodeFile tmpPath
251 () <- C.runResourceT $ Y.decodeFile filePath C.$$ Y.encodeFile tmpPath
261 () <- C.runResourceT $ Y.decodeFile tmpPath C.$$ Y.encodeFile tmpPath2
252 () <- C.runResourceT $ Y.decodeFile tmpPath C.$$ Y.encodeFile tmpPath2
262 f1 <- readFile tmpPath
253 f1 <- readFile tmpPath
@@ -264,8 +255,6 @@ caseInterleave = do
264 f1 @=? f2
255 f1 @=? f2
266 filePath = "test/largest-string.yaml"
257 filePath = "test/largest-string.yaml"
267− tmpPath = "tmp.yaml"
268− tmpPath2 = "tmp2.yaml"
270caseDecodeInvalidDocument :: Assertion
259caseDecodeInvalidDocument :: Assertion
271caseDecodeInvalidDocument = do
260caseDecodeInvalidDocument = do
@@ -308,8 +297,7 @@ caseEncodeDecodeData = do
308 out @?= Just sample
297 out @?= Just sample
310caseEncodeDecodeFileData :: Assertion
299caseEncodeDecodeFileData :: Assertion
311−caseEncodeDecodeFileData = do
300+caseEncodeDecodeFileData = withFile "" $ \fp -> do
313 D.encodeFile fp sample
301 D.encodeFile fp sample
314 out <- D.decodeFile fp
302 out <- D.decodeFile fp
315 out @?= Just sample
303 out @?= Just sample