packages feed

sydtest 0.16.0.0 → 0.17.0.0

raw patch · 4 files changed

+34/−22 lines, 4 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

- Test.Syd: GoldenTest :: IO (Maybe a) -> IO a -> (a -> IO ()) -> (a -> a -> Maybe Assertion) -> GoldenTest a
+ Test.Syd: GoldenTest :: IO (Maybe a) -> IO a -> (a -> IO ()) -> (a -> a -> IO (Maybe Assertion)) -> GoldenTest a
- Test.Syd: [goldenTestCompare] :: GoldenTest a -> a -> a -> Maybe Assertion
+ Test.Syd: [goldenTestCompare] :: GoldenTest a -> a -> a -> IO (Maybe Assertion)
- Test.Syd.Def.Golden: GoldenTest :: IO (Maybe a) -> IO a -> (a -> IO ()) -> (a -> a -> Maybe Assertion) -> GoldenTest a
+ Test.Syd.Def.Golden: GoldenTest :: IO (Maybe a) -> IO a -> (a -> IO ()) -> (a -> a -> IO (Maybe Assertion)) -> GoldenTest a
- Test.Syd.Def.Golden: [goldenTestCompare] :: GoldenTest a -> a -> a -> Maybe Assertion
+ Test.Syd.Def.Golden: [goldenTestCompare] :: GoldenTest a -> a -> a -> IO (Maybe Assertion)
- Test.Syd.Run: GoldenTest :: IO (Maybe a) -> IO a -> (a -> IO ()) -> (a -> a -> Maybe Assertion) -> GoldenTest a
+ Test.Syd.Run: GoldenTest :: IO (Maybe a) -> IO a -> (a -> IO ()) -> (a -> a -> IO (Maybe Assertion)) -> GoldenTest a
- Test.Syd.Run: [goldenTestCompare] :: GoldenTest a -> a -> a -> Maybe Assertion
+ Test.Syd.Run: [goldenTestCompare] :: GoldenTest a -> a -> a -> IO (Maybe Assertion)

Files

CHANGELOG.md view
@@ -1,5 +1,11 @@ # Changelog +## [0.17.0.0] - 2024-08-04++### Changed++* Allow golden tests to perform IO during comparisons+ ## [0.16.0.0] - 2024-08-03  ### Changed
src/Test/Syd/Def/Golden.hs view
@@ -34,9 +34,10 @@         ensureDir $ parent resolvedFile         SB.writeFile (fromAbsFile resolvedFile) actual,       goldenTestCompare = \actual expected ->-        if actual == expected-          then Nothing-          else Just $ Context (bytestringsNotEqualButShouldHaveBeenEqual actual expected) (goldenContext fp)+        pure $+          if actual == expected+            then Nothing+            else Just $ Context (bytestringsNotEqualButShouldHaveBeenEqual actual expected) (goldenContext fp)     }  -- | Test that the given lazy bytestring is the same as what we find in the given golden file.@@ -60,11 +61,12 @@         ensureDir $ parent resolvedFile         SB.writeFile (fromAbsFile resolvedFile) (LB.toStrict actual),       goldenTestCompare = \actual expected ->-        let actualBS = LB.toStrict actual-            expectedBS = LB.toStrict expected-         in if actualBS == expectedBS-              then Nothing-              else Just $ Context (bytestringsNotEqualButShouldHaveBeenEqual actualBS expectedBS) (goldenContext fp)+        pure $+          let actualBS = LB.toStrict actual+              expectedBS = LB.toStrict expected+           in if actualBS == expectedBS+                then Nothing+                else Just $ Context (bytestringsNotEqualButShouldHaveBeenEqual actualBS expectedBS) (goldenContext fp)     }  -- | Test that the given lazy bytestring is the same as what we find in the given golden file.@@ -88,11 +90,12 @@         ensureDir $ parent resolvedFile         SB.writeFile (fromAbsFile resolvedFile) (LB.toStrict (SBB.toLazyByteString actual)),       goldenTestCompare = \actual expected ->-        let actualBS = LB.toStrict (SBB.toLazyByteString actual)-            expectedBS = LB.toStrict (SBB.toLazyByteString expected)-         in if actualBS == expectedBS-              then Nothing-              else Just $ Context (bytestringsNotEqualButShouldHaveBeenEqual actualBS expectedBS) (goldenContext fp)+        pure $+          let actualBS = LB.toStrict (SBB.toLazyByteString actual)+              expectedBS = LB.toStrict (SBB.toLazyByteString expected)+           in if actualBS == expectedBS+                then Nothing+                else Just $ Context (bytestringsNotEqualButShouldHaveBeenEqual actualBS expectedBS) (goldenContext fp)     }  -- | Test that the given text is the same as what we find in the given golden file.@@ -112,9 +115,10 @@         ensureDir $ parent resolvedFile         SB.writeFile (fromAbsFile resolvedFile) (TE.encodeUtf8 actual),       goldenTestCompare = \actual expected ->-        if actual == expected-          then Nothing-          else Just $ Context (textsNotEqualButShouldHaveBeenEqual actual expected) (goldenContext fp)+        pure $+          if actual == expected+            then Nothing+            else Just $ Context (textsNotEqualButShouldHaveBeenEqual actual expected) (goldenContext fp)     }  -- | Test that the given string is the same as what we find in the given golden file.@@ -134,9 +138,10 @@         ensureDir $ parent resolvedFile         SB.writeFile (fromAbsFile resolvedFile) (TE.encodeUtf8 (T.pack actual)),       goldenTestCompare = \actual expected ->-        if actual == expected-          then Nothing-          else Just $ Context (stringsNotEqualButShouldHaveBeenEqual actual expected) (goldenContext fp)+        pure $+          if actual == expected+            then Nothing+            else Just $ Context (stringsNotEqualButShouldHaveBeenEqual actual expected) (goldenContext fp)     }  -- | Test that the show instance has not changed for the given value.
src/Test/Syd/Run.hs view
@@ -298,7 +298,7 @@     -- | Compare golden output with current output     --     -- The first argument is the current output, the second is the golden output-    goldenTestCompare :: a -> a -> Maybe Assertion+    goldenTestCompare :: a -> a -> IO (Maybe Assertion)   }  instance IsTest (GoldenTest a) where@@ -351,7 +351,8 @@           else pure (TestFailed, Just GoldenNotFound, Nothing)       Just golden -> do         actual <- goldenTestProduce >>= evaluate-        case goldenTestCompare actual golden of+        mAssertion <- goldenTestCompare actual golden+        case mAssertion of           Nothing -> pure (TestPassed, Nothing, Nothing)           Just assertion ->             if testRunSettingGoldenReset
sydtest.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack  name:           sydtest-version:        0.16.0.0+version:        0.17.0.0 synopsis:       A modern testing framework for Haskell with good defaults and advanced testing features. description:    A modern testing framework for Haskell with good defaults and advanced testing features. Sydtest aims to make the common easy and the hard possible. See https://github.com/NorfairKing/sydtest#readme for more information. category:       Testing