on master help sign in
Merge pull request #61 from zalora/test-tweaks
963ba05Michael Snoyman
.gitignore−2
@@ -1,7 +1,5 @@
1dist
1dist
2*.swp
2*.swp
3−tmp.yaml
4−tmp2.yaml
5cabal-dev/
3cabal-dev/
6.cabal-sandbox/
4.cabal-sandbox/
7cabal.sandbox.config
5cabal.sandbox.config
test/Data/Yaml/IncludeSpec.hs+1−1
@@ -2,7 +2,7 @@
2module Data.Yaml.IncludeSpec (main, spec) where
2module Data.Yaml.IncludeSpec (main, spec) where
3
3
4import Test.Hspec
4import Test.Hspec
5−import Test.Hspec.Expectations.Contrib
5+import Data.Either.Compat
6import Data.Aeson
6import Data.Aeson
7import Data.Aeson.QQ
7import Data.Aeson.QQ
8import Data.Yaml (ParseException)
8import Data.Yaml (ParseException)
test/Data/YamlSpec.hs+5−17
@@ -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
17
17
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
23
23
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
239
239
240−removeFile' :: FilePath -> IO ()
241−removeFile' fp = do
242− x <- doesFileExist fp
243− when x $ removeFile fp
244−
245caseEncodeDecodeFile :: Assertion
240caseEncodeDecodeFile :: Assertion
246−caseEncodeDecodeFile = do
241+caseEncodeDecodeFile = withFile "" $ \tmpPath -> do
247− removeFile' tmpPath
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
252 where
246 where
253 filePath = "test/largest-string.yaml"
247 filePath = "test/largest-string.yaml"
254− tmpPath = "tmp.yaml"
255
248
256caseInterleave :: Assertion
249caseInterleave :: Assertion
257−caseInterleave = do
250+caseInterleave = withFile "" $ \tmpPath -> withFile "" $ \tmpPath2 -> do
258− removeFile' tmpPath
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
265 where
256 where
266 filePath = "test/largest-string.yaml"
257 filePath = "test/largest-string.yaml"
267− tmpPath = "tmp.yaml"
268− tmpPath2 = "tmp2.yaml"
269
258
270caseDecodeInvalidDocument :: Assertion
259caseDecodeInvalidDocument :: Assertion
271caseDecodeInvalidDocument = do
260caseDecodeInvalidDocument = do
@@ -308,8 +297,7 @@ caseEncodeDecodeData = do
308 out @?= Just sample
297 out @?= Just sample
309
298
310caseEncodeDecodeFileData :: Assertion
299caseEncodeDecodeFileData :: Assertion
311−caseEncodeDecodeFileData = do
300+caseEncodeDecodeFileData = withFile "" $ \fp -> do
312− let fp = "tmp.yaml"
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
yaml.cabal+2−2
@@ -114,9 +114,7 @@ test-suite spec
114 Data.Yaml.IncludeSpec
114 Data.Yaml.IncludeSpec
115 cpp-options: -DTEST
115 cpp-options: -DTEST
116 build-depends: hspec >= 1.3
116 build-depends: hspec >= 1.3
117− , hspec-expectations
118 , HUnit
117 , HUnit
119− , directory
120 , base >= 4 && < 5
118 , base >= 4 && < 5
121 , transformers >= 0.1
119 , transformers >= 0.1
122 , bytestring >= 0.9.1.4
120 , bytestring >= 0.9.1.4
@@ -128,6 +126,8 @@ test-suite spec
128 , vector
126 , vector
129 , resourcet
127 , resourcet
130 , aeson-qq
128 , aeson-qq
129+ , mockery
130+ , base-compat
131 ghc-options: -Wall
131 ghc-options: -Wall
132
132
133source-repository head
133source-repository head