sydtest-hspec 0.4.0.0 → 0.4.0.1
raw patch · 3 files changed
+33/−13 lines, 3 files
Files
- CHANGELOG.md +6/−0
- src/Test/Syd/Hspec.hs +25/−11
- sydtest-hspec.cabal +2/−2
CHANGELOG.md view
@@ -1,5 +1,11 @@ # Changelog +## [0.4.0.1] - 2023-10-09++### Added++* Compatibility with `hspec-core >= 2.11`+ ## [0.4.0.0] - 2022-06-05 ### Added
src/Test/Syd/Hspec.hs view
@@ -26,28 +26,37 @@ -- For this reason, and because hspec doesn't tell you wether a test is pending -- until after you run it, pending tests are imported as passing tests. fromHspec :: Hspec.Spec -> Syd.Spec-fromHspec (Hspec.SpecM specWriter) = do- (result, trees) <- liftIO $ runWriterT specWriter+fromHspec spec = do+ trees <- liftIO $ runSpecM_ spec -- We have to use 'doNotRandomiseExecutionOrder' and 'sequential' because otherwise -- passing hspec tests would stop working when imported into sydtest doNotRandomiseExecutionOrder $ sequential $ mapM_ importSpecTree trees- pure result +runSpecM_ :: Hspec.SpecWith () -> IO [Hspec.SpecTree ()]+#if MIN_VERSION_hspec_core(2,11,0)+runSpecM_ = fmap snd . Hspec.runSpecM+#else+runSpecM_ = Hspec.runSpecM+#endif+ -- Hspec.NodeWithCleanup's semantics are so weird that we can only do -- this translation if inner equals (). importSpecTree :: Hspec.SpecTree () -> Syd.Spec importSpecTree = go where+ go :: Hspec.SpecTree () -> Syd.Spec go = \case Hspec.Leaf item -> importItem item Hspec.Node d ts -> describe d $ mapM_ go ts-+#if MIN_VERSION_hspec_core(2,11,0)+ Hspec.NodeWithCleanup _ cleanup ts -> afterAll_ cleanup (mapM_ go ts)+#else #if MIN_VERSION_hspec_core(2,8,0) Hspec.NodeWithCleanup _ cleanup ts -> afterAll_ (cleanup ()) (mapM_ go ts)- #else Hspec.NodeWithCleanup cleanup ts -> afterAll_ (cleanup ()) (mapM_ go ts) #endif+#endif importItem :: forall inner. Hspec.Item inner -> Syd.TestDefM '[] inner () importItem item@Hspec.Item {..} =@@ -131,12 +140,7 @@ niceLocation Hspec.Location {..} = intercalate ":" [locationFile, show locationLine, show locationColumn] withLocationContext :: SomeException -> SomeException withLocationContext = withExtraContext $ niceLocation <$> mloc- exception :: SomeException- exception = case fr of- Hspec.NoReason -> SomeException $ ExpectationFailed "Hspec had no more information about this failure."- Hspec.Reason s -> SomeException $ ExpectationFailed s- Hspec.ExpectedButGot mExtraContext expected actual -> withExtraContext mExtraContext $ SomeException $ NotEqualButShouldHaveBeenEqual actual expected- Hspec.Error mExtraContext e -> withExtraContext mExtraContext e+ exception = failureReasonToException withExtraContext fr in ( TestFailed, Just $ SomeException $ addContextToException (withLocationContext exception) (Hspec.resultInfo result) )@@ -150,3 +154,13 @@ let testRunResultTables = Nothing pure TestRunResult {..}++failureReasonToException :: (Maybe String -> SomeException -> SomeException) -> Hspec.FailureReason -> SomeException+failureReasonToException withExtraContext = \case+ Hspec.NoReason -> SomeException $ ExpectationFailed "Hspec had no more information about this failure."+ Hspec.Reason s -> SomeException $ ExpectationFailed s+ Hspec.ExpectedButGot mExtraContext expected actual -> withExtraContext mExtraContext $ SomeException $ NotEqualButShouldHaveBeenEqual actual expected+ Hspec.Error mExtraContext e -> withExtraContext mExtraContext e+#if MIN_VERSION_hspec_core(2,11,0)+ Hspec.ColorizedReason s -> SomeException $ ExpectationFailed s+#endif
sydtest-hspec.cabal view
@@ -1,11 +1,11 @@ cabal-version: 1.12 --- This file has been generated from package.yaml by hpack version 0.34.7.+-- This file has been generated from package.yaml by hpack version 0.35.2. -- -- see: https://github.com/sol/hpack name: sydtest-hspec-version: 0.4.0.0+version: 0.4.0.1 synopsis: An Hspec companion library for sydtest category: Testing homepage: https://github.com/NorfairKing/sydtest#readme