sydtest-hspec 0.4.0.3 → 0.4.0.4
raw patch · 5 files changed
+117/−5 lines, 5 filesdep +safe-coloured-textdep +textPVP ok
version bump matches the API change (PVP)
Dependencies added: safe-coloured-text, text
API changes (from Hackage documentation)
Files
- CHANGELOG.md +6/−0
- src/Test/Syd/Hspec.hs +11/−4
- sydtest-hspec.cabal +5/−1
- test/Test/Syd/OutputSpec.hs +52/−0
- test_resources/output-test.txt +43/−0
CHANGELOG.md view
@@ -1,5 +1,11 @@ # Changelog +## [0.4.0.4] - 2025-01-07++### Changed++ * Fixed test failure report when using `mkNotEqualButShouldHaveBeenEqual`+ ## [0.4.0.3] - 2024-10-13 ### Added
src/Test/Syd/Hspec.hs view
@@ -140,11 +140,13 @@ niceLocation Hspec.Location {..} = intercalate ":" [locationFile, show locationLine, show locationColumn] withLocationContext :: SomeException -> SomeException withLocationContext = withExtraContext $ niceLocation <$> mloc+ withContext :: SomeException -> Contextual+ withContext e = addContextToException (withLocationContext e) (Hspec.resultInfo result)+ exception <- failureReasonToException withExtraContext fr- pure- ( TestFailed,- Just $ SomeException $ addContextToException (withLocationContext exception) (Hspec.resultInfo result)- )++ pure (TestFailed, Just $ maybeAddContextToException withContext exception fr)+ let testRunResultNumTests = Nothing let testRunResultNumShrinks = Nothing let testRunResultGoldenCase = Nothing@@ -165,3 +167,8 @@ #if MIN_VERSION_hspec_core(2,11,0) Hspec.ColorizedReason s -> pure $ SomeException $ ExpectationFailed s #endif++maybeAddContextToException :: (SomeException -> Contextual) -> SomeException -> Hspec.FailureReason -> SomeException+maybeAddContextToException withContext e = \case+ Hspec.ExpectedButGot {} -> e+ _ -> SomeException (withContext e)
sydtest-hspec.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack name: sydtest-hspec-version: 0.4.0.3+version: 0.4.0.4 synopsis: An Hspec companion library for sydtest category: Testing homepage: https://github.com/NorfairKing/sydtest#readme@@ -19,6 +19,7 @@ extra-source-files: CHANGELOG.md LICENSE.md+ test_resources/output-test.txt source-repository head type: git@@ -46,6 +47,7 @@ other-modules: Spec Test.Syd.HspecSpec+ Test.Syd.OutputSpec Paths_sydtest_hspec hs-source-dirs: test@@ -55,7 +57,9 @@ build-depends: base >=4.7 && <5 , hspec+ , safe-coloured-text , stm , sydtest , sydtest-hspec+ , text default-language: Haskell2010
+ test/Test/Syd/OutputSpec.hs view
@@ -0,0 +1,52 @@+{-# LANGUAGE OverloadedStrings #-}++module Test.Syd.OutputSpec (spec) where++import Control.Exception (AssertionFailed (..), throwIO)+import qualified Data.Text.Lazy as LT+import qualified Data.Text.Lazy.Builder as TLB+import Test.Hspec+import qualified Test.Syd as Syd+import Test.Syd.Hspec (fromHspec)+import Test.Syd.OptParse (getSettings)+import Text.Colour++spec :: Syd.Spec+spec =+ Syd.describe "Golden Output" $+ Syd.it "renders output in the same way as before" $+ Syd.goldenTextFile "test_resources/output-test.txt" $ do+ settings <- getSettings+ testForest <- Syd.execTestDefM settings (fromHspec hspecSpec)+ res <- Syd.timeItT 0 $ Syd.runSpecForestSynchronously settings testForest++ pure+ $ LT.toStrict+ . TLB.toLazyText+ . Syd.renderResultReport settings WithoutColours+ $ eraseTiming res++hspecSpec :: Spec+hspecSpec = do+ it "failure with no reason" False++ it "failure with reason" $ expectationFailure "failure reason"++ it "failure with \"expected x but got y\"" $ 8 `shouldBe` (6 :: Int)++ it "failure with error" $ do+ throwIO (AssertionFailed "error msg") :: IO ()++eraseTiming :: Syd.Timed Syd.ResultForest -> Syd.Timed Syd.ResultForest+eraseTiming = fmap erasedTimedInResultForest . eraseTimed+ where+ eraseTimed :: Syd.Timed a -> Syd.Timed a+ eraseTimed t =+ t+ { Syd.timedBegin = 0,+ Syd.timedEnd = 0,+ Syd.timedWorker = 0+ }++ erasedTimedInResultForest :: Syd.ResultForest -> Syd.ResultForest+ erasedTimedInResultForest = fmap (fmap (fmap eraseTimed))
+ test_resources/output-test.txt view
@@ -0,0 +1,43 @@+Tests:++✗ failure with no reason 0.00 ms+ Retries: 3 (does not look flaky)+✗ failure with reason 0.00 ms+ Retries: 3 (does not look flaky)+✗ failure with "expected x but got y" 0.00 ms+ Retries: 3 (does not look flaky)+✗ failure with error 0.00 ms+ Retries: 3 (does not look flaky)+++Failures:++ src/Test/Syd/Hspec.hs:68+ ✗ 1 failure with no reason+ Retries: 3 (does not look flaky)+ ExpectationFailed "Hspec had no more information about this failure."+ + src/Test/Syd/Hspec.hs:68+ ✗ 2 failure with reason+ Retries: 3 (does not look flaky)+ Contextual "ExpectationFailed \"failure reason\"" "test/Test/Syd/OutputSpec.hs:33:30"+ + src/Test/Syd/Hspec.hs:68+ ✗ 3 failure with "expected x but got y"+ Retries: 3 (does not look flaky)+ Expected these values to be equal:+ Actual: 8+ Expected: 6+ + src/Test/Syd/Hspec.hs:68+ ✗ 4 failure with error+ Retries: 3 (does not look flaky)+ error msg+ ++ Examples: 12+ Passed: 0+ Failed: 4+ Sum of test runtimes: 0.00 seconds+ Test suite took: 0.00 seconds+