packages feed

sydtest-aeson 0.0.0.0 → 0.1.0.0

raw patch · 8 files changed

+80/−12 lines, 8 filesdep +deepseqdep +directoryPVP ok

version bump matches the API change (PVP)

Dependencies added: deepseq, directory

API changes (from Hackage documentation)

Files

LICENSE.md view
@@ -1,5 +1,5 @@ # Sydtest License -Copyright (c) 2021 Tom Sydney Kerckhove+Copyright (c) 2021-2022 Tom Sydney Kerckhove  See the Sydtest License at https://github.com/NorfairKing/sydtest/blob/master/sydtest/LICENSE.md for the full license text.
src/Test/Syd/Aeson.hs view
@@ -1,5 +1,4 @@ {-# LANGUAGE DataKinds #-}-{-# LANGUAGE OverloadedStrings #-}  module Test.Syd.Aeson   ( -- * Golden tests@@ -10,6 +9,8 @@   ) where +import Control.DeepSeq+import Control.Exception import Control.Monad import Data.Aeson as JSON import Data.Aeson.Encode.Pretty as JSON@@ -35,9 +36,10 @@             Right r -> pure r,       goldenTestProduce = produceActualValue,       goldenTestWrite = \v -> do+        value <- evaluate $ force $ toJSON v         p <- resolveFile' fp         ensureDir (parent p)-        SB.writeFile (fromAbsFile p) $ LB.toStrict $ JSON.encodePretty v,+        SB.writeFile (fromAbsFile p) $ LB.toStrict $ JSON.encodePretty value,       goldenTestCompare = \actual expected ->         if actual == expected           then Nothing@@ -75,9 +77,10 @@             Right r -> pure r,       goldenTestProduce = produceActualValue,       goldenTestWrite = \v -> do+        value <- evaluate $ force $ toJSON v         p <- resolveFile' fp         ensureDir (parent p)-        SB.writeFile (fromAbsFile p) $ LB.toStrict $ JSON.encodePretty v,+        SB.writeFile (fromAbsFile p) $ LB.toStrict $ JSON.encodePretty value,       goldenTestCompare = \actual expected ->         if actual == expected           then Nothing
sydtest-aeson.cabal view
@@ -1,23 +1,29 @@ cabal-version: 1.12 --- This file has been generated from package.yaml by hpack version 0.34.4.+-- This file has been generated from package.yaml by hpack version 0.34.7. -- -- see: https://github.com/sol/hpack ----- hash: 2fe968a3a35d7b58c088bbfec8b58386928f7006a3424e650e765781459c162a+-- hash: 146fca0f19cd3781f36f8b0224fcd12370fa9dc1506f8adbd22c3078a82992fd  name:           sydtest-aeson-version:        0.0.0.0+version:        0.1.0.0 synopsis:       An aeson companion library for sydtest category:       Testing homepage:       https://github.com/NorfairKing/sydtest#readme bug-reports:    https://github.com/NorfairKing/sydtest/issues author:         Tom Sydney Kerckhove maintainer:     syd@cs-syd.eu-copyright:      Copyright (c) 2021 Tom Sydney Kerckhove+copyright:      Copyright (c) 2021-2022 Tom Sydney Kerckhove license:        OtherLicense license-file:   LICENSE.md build-type:     Simple+extra-source-files:+    LICENSE.md+    test_resources/example-value.json+    test_resources/example.json+    test_resources/pure-example-value.json+    test_resources/pure-example.json  source-repository head   type: git@@ -35,6 +41,7 @@     , aeson-pretty     , base >=4.7 && <5     , bytestring+    , deepseq     , path     , path-io     , sydtest@@ -55,6 +62,7 @@   build-depends:       aeson     , base >=4.7 && <5+    , directory     , sydtest     , sydtest-aeson     , text
test/Test/Syd/AesonSpec.hs view
@@ -1,33 +1,70 @@ {-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE ScopedTypeVariables #-}  module Test.Syd.AesonSpec (spec) where +import Control.Exception+import Control.Monad import Data.Aeson as JSON import Data.Text (Text)+import System.Directory (doesFileExist, removeFile) import Test.Syd import Test.Syd.Aeson  spec :: Spec spec = do-  describe "pureGoldenJSONFile" $+  describe "pureGoldenJSONFile" $ do     it "outputs this example the same as before" $       pureGoldenJSONFile         "test_resources/pure-example.json"         $ JSON.object           ["hello" .= ("world" :: Text), "a" .= (1 :: Int), "b" .= True]++    it "does not write an empty file if encoding fails" $ do+      let path = "test_resources/pure-example-exception.json"+      let result = JSON.object ["undefined" .= (undefined :: Text)]+      let goldenTest = pureGoldenJSONFile path result+      -- Make sure there is nothing in the way+      existsBefore <- doesFileExist path+      when existsBefore $ removeFile path++      -- Try to write, this will fail+      goldenTestWrite goldenTest result `catch` (\(_ :: ErrorCall) -> pure ())++      -- Make sure there is no file afterwards+      exists <- doesFileExist path+      exists `shouldBe` False+   describe "goldenJSONFile" $     it "outputs this example the same as before" $       goldenJSONFile         "test_resources/example.json"         $ pure $ JSON.object ["hello" .= ("world" :: Text), "a" .= (1 :: Int), "b" .= True]-  describe "pureGoldenJSONValueFile" $++  describe "pureGoldenJSONValueFile" $ do     it "outputs this example the same as before" $       pureGoldenJSONValueFile-        "test_resources/pure-example.json"+        "test_resources/pure-example-value.json"         $ JSON.object           ["hello" .= ("world" :: Text), "a" .= (1 :: Int), "b" .= True]++    it "does not write an empty file if encoding fails" $ do+      let path = "test_resources/pure-example-value-exception.json"+      let result = JSON.object ["undefined" .= (undefined :: Text)]+      let goldenTest = pureGoldenJSONValueFile path result+      -- Make sure there is nothing in the way+      existsBefore <- doesFileExist path+      when existsBefore $ removeFile path++      -- Try to write, this will fail+      goldenTestWrite goldenTest result `catch` (\(_ :: ErrorCall) -> pure ())++      -- Make sure there is no file afterwards+      existsAfter <- doesFileExist path+      existsAfter `shouldBe` False+   describe "goldenJSONValueFile" $     it "outputs this example the same as before" $       goldenJSONValueFile-        "test_resources/example.json"+        "test_resources/example-value.json"         $ pure $ JSON.object ["hello" .= ("world" :: Text), "a" .= (1 :: Int), "b" .= True]
+ test_resources/example-value.json view
@@ -0,0 +1,5 @@+{+    "a": 1,+    "b": true,+    "hello": "world"+}
+ test_resources/example.json view
@@ -0,0 +1,5 @@+{+    "hello": "world",+    "a": 1,+    "b": true+}
+ test_resources/pure-example-value.json view
@@ -0,0 +1,5 @@+{+    "a": 1,+    "b": true,+    "hello": "world"+}
+ test_resources/pure-example.json view
@@ -0,0 +1,5 @@+{+  "hello" : "world",+  "a" : 1,+  "b" : true+}