packages feed

hspec-golden-aeson 0.5.1.0 → 0.6.0.0

raw patch · 5 files changed

+65/−17 lines, 5 filesnew-uploader

Files

hspec-golden-aeson.cabal view
@@ -1,9 +1,11 @@--- This file has been generated from package.yaml by hpack version 0.17.1.+-- This file has been generated from package.yaml by hpack version 0.28.2. -- -- see: https://github.com/sol/hpack+--+-- hash: fd3131a3ad56f72d492984264b8e7c4a6a6fadd8afc71dac6295c5758fdcf4ce  name:           hspec-golden-aeson-version:        0.5.1.0+version:        0.6.0.0 synopsis:       Use tests to monitor changes in Aeson serialization description:    Use tests to monitor changes in Aeson serialization category:       Testing@@ -26,16 +28,16 @@       src   ghc-options: -Wall   build-depends:-      base >= 4.7 && < 5+      QuickCheck     , aeson     , aeson-pretty+    , base >=4.7 && <5     , bytestring     , directory     , filepath     , hspec+    , quickcheck-arbitrary-adt >=0.3.0.0     , random-    , quickcheck-arbitrary-adt >= 0.3.0.0-    , QuickCheck     , transformers   exposed-modules:       Test.Aeson.GenericSpecs@@ -56,15 +58,15 @@       test   ghc-options: -Wall   build-depends:-      base+      QuickCheck     , aeson+    , base     , directory     , hspec     , hspec-core     , hspec-golden-aeson-    , silently     , quickcheck-arbitrary-adt-    , QuickCheck+    , silently     , transformers   other-modules:       Test.Aeson.GenericSpecsSpec@@ -74,4 +76,5 @@       Test.Types.MismatchedToAndFromSerialization       Test.Types.NewSelector       Test.Utils+      Paths_hspec_golden_aeson   default-language: Haskell2010
src/Test/Aeson/Internal/ADT/GoldenSpecs.hs view
@@ -96,11 +96,12 @@   sampleSize <- readSampleSize =<< readFile goldenFile   newSamples <- mkRandomADTSamplesForConstructor sampleSize (Proxy :: Proxy a) (capConstructor cap) goldenSeed   whenFails (writeComparisonFile newSamples) $ do+    goldenBytes <- readFile goldenFile     goldenSamples :: RandomSamples a <--      either (throwIO . ErrorCall) return =<<-      A.eitherDecode' <$>-      readFile goldenFile+      either (throwIO . ErrorCall) return $+      A.eitherDecode' goldenBytes     newSamples `shouldBe` goldenSamples+    encodePretty newSamples `shouldBe` goldenBytes   where     whenFails :: forall b c. IO c -> IO b -> IO b     whenFails = flip onException
test/Test/Aeson/GenericSpecsSpec.hs view
@@ -171,6 +171,50 @@       (s1,_) <- hspecSilently $ goldenADTSpecs defaultSettings (Proxy :: Proxy TAS.Person)       summaryFailures s1 `shouldBe` 1 +    it "encoding change should fail test" $ do+      -- clean up previously existing golden folder+      bg <- doesDirectoryExist "golden"+      if bg+        then removeDirectoryRecursive "golden"+        else return ()++      -- manually create golden file which appends `.0` to all ages.+      -- write as inline text to make test case clearer+      let+        goldenTweaked = "{\+\    \"seed\": -558805430132139320,\+\    \"samples\": [\+\        {\+\            \"age\": -24.0,\+\            \"name\": \"<\147\158\\u000e\251\133]V_t\167\&2\210\148\194Q\196_\150\145\\u0017Hf&\"\+\        },\+\        {\+\            \"age\": -9.0,\+\            \"name\": \"<\\n\\u0018O\\n>\"\+\        },\+\        {\+\            \"age\": -1.0,\+\            \"name\": \"m0x\217\\u000c\\u000fg4\188\197\\u000bF\227\\u0013\\u00042F\\u001f\176%`\224Iw\\u0011\231/\204\"\+\        },\+\        {\+\            \"age\": -22.0,\+\            \"name\": \"x\221\250{\\u001bG\244\\u0012\232\\u0004)\"\+\        },\+\        {\+\            \"age\": 26.0,\+\            \"name\": \"\153\\u0005n\\u001a$q27\184=\\u0012ba\\u001b\\u0010\252]\242A.\139w\234\&0\239\\u0004\204\"\+\        }\+\    ]\+\}"++      createDirectoryIfMissing True "golden/Person"+      writeFile "golden/Person/Person.json" goldenTweaked++      -- Aeson can decode "10.0" as `10 :: Int` but it will encode `10 :: Int` as 10+      -- This should cause the golden test to fail since it indicates a change in encoding+      (s1,_) <- hspecSilently $ goldenADTSpecs defaultSettings (Proxy :: Proxy T.Person)+      summaryFailures s1 `shouldBe` 1+   describe "mkGoldenFileForType" $ do     it "create a single file in a dir for a Product type" $ do       -- clean up previously existing golden folder
test/Test/Types/BrokenSerialization.hs view
@@ -13,9 +13,9 @@ } deriving (Eq,Show,Generic)  instance ToJSON Person where-  toJSON (Person name age) = object [-       "personName" .= name-    ,  "personAge"  .= age+  toJSON (Person name' age') = object [+       "personName" .= name'+    ,  "personAge"  .= age'     ] instance FromJSON Person where   parseJSON = withObject "Expected a Person object" $ \o ->
test/Test/Types/MismatchedToAndFromSerialization.hs view
@@ -14,9 +14,9 @@  -- ToJSON and FromJSON use different strings, this should break. instance ToJSON Person where-  toJSON (Person name age) = object [-       "personName" .= name-    ,  "personAge"  .= age+  toJSON (Person name' age') = object [+       "personName" .= name'+    ,  "personAge"  .= age'     ]  instance FromJSON Person where