packages feed

sydtest 0.15.0.0 → 0.15.1.0

raw patch · 22 files changed

+208/−114 lines, 22 files

Files

CHANGELOG.md view
@@ -1,5 +1,9 @@ # Changelog +## [0.15.1.0] - 2023-07-28++* `setupAroundWithAll`: so it's easier to use multiple outer resources to provide an inner resource, without the need of extra type annotation.+ ## [0.15.0.0] - 2023-04-08  * `DefBeforeAllWithNode`: so that `beforeAllWith` can be defined in terms of it and have better parallelism properties.
CONTRIBUTORS view
@@ -1,3 +1,5 @@ NorfairKing igrep mrcjkb+L7R7+TheOddler
+ multi-discover-test/Bar/BarSpec.hs view
@@ -0,0 +1,12 @@+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE TypeOperators #-}++module Bar.BarSpec where++import Test.Syd++spec :: TestDef (String : otherOuters) ()+spec = do+  describe "can access outer resource" $+    itWithOuter "bar is bar" $+      \s -> s `shouldBe` "bar"
+ multi-discover-test/Bar/Spec.hs view
@@ -0,0 +1,1 @@+{-# OPTIONS_GHC -F -pgmF sydtest-discover -optF --no-main #-}
+ multi-discover-test/Baz/Qux/QuxSpec.hs view
@@ -0,0 +1,8 @@+module Baz.Qux.QuxSpec where++import Test.Syd++spec :: Spec+spec = do+  describe "several nesting levels" $+    it "works" True
+ multi-discover-test/Baz/Qux/Spec.hs view
@@ -0,0 +1,1 @@+{-# OPTIONS_GHC -F -pgmF sydtest-discover -optF --no-main #-}
+ multi-discover-test/DoNotDiscover/FooSpec.hs view
@@ -0,0 +1,11 @@+{-# LANGUAGE TypeApplications #-}++module DoNotDiscover.FooSpec where++import Test.Syd++spec :: Spec+spec = do+  describe "do not discover" $+    it "always fails" $+      expectationFailure @() "This test fails because sydtest-discover isn't working properly. This spec should not be discovered"
+ multi-discover-test/Foo/FooSpec.hs view
@@ -0,0 +1,9 @@+module Foo.FooSpec where++import Test.Syd++spec :: Spec+spec = do+  describe "plain test" $+    it "simple example" $+      2 + 3 == (5 :: Int)
+ multi-discover-test/Foo/Spec.hs view
@@ -0,0 +1,1 @@+{-# OPTIONS_GHC -F -pgmF sydtest-discover -optF --no-main #-}
+ multi-discover-test/Main.hs view
@@ -0,0 +1,12 @@+module Main where++import qualified Bar.Spec as Bar+import qualified Baz.Qux.QuxSpec as Qux+import qualified Foo.Spec as Foo+import Test.Syd++main :: IO ()+main = sydTest $ do+  Foo.spec+  beforeAll (pure "bar") Bar.spec+  Qux.spec
output-test/Main.hs view
@@ -50,9 +50,9 @@               erasedTimedInResultForest = fmap (fmap (fmap eraseTimed))               eraseTiming :: Timed ResultForest -> Timed ResultForest               eraseTiming = fmap erasedTimedInResultForest . eraseTimed-          pure $-            TE.encodeUtf8+          pure+            $ TE.encodeUtf8               . LT.toStrict               . TLB.toLazyText               . renderResultReport defaultSettings With24BitColours-              $ eraseTiming rf+            $ eraseTiming rf
output-test/Spec.hs view
@@ -1,7 +1,7 @@ {-# LANGUAGE NumericUnderscores #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-}-{-# OPTIONS_GHC -fno-warn-missing-fields -fno-warn-missing-methods -fno-warn-partial-fields -fno-warn-incomplete-uni-patterns -fno-warn-incomplete-record-updates #-}+{-# OPTIONS_GHC -fno-warn-missing-fields -fno-warn-missing-methods -fno-warn-partial-fields -fno-warn-incomplete-uni-patterns -fno-warn-incomplete-record-updates -fno-warn-overlapping-patterns #-}  module Spec where 
src/Test/Syd/Def/SetupFunc.hs view
@@ -91,6 +91,11 @@   let SetupFunc provideNewInner = f outer oldInner    in provideNewInner $ \newInner -> takeBoth outer newInner +-- | Use all outer resources and the inner resource to provide a new inner resource+-- This is a more constrained version of 'setupAroundWith'' to more easily allow providing an inner resource based on multiple outer resources+setupAroundWithAll :: (HList outers -> oldInner -> SetupFunc newInner) -> TestDefM outers newInner result -> TestDefM outers oldInner result+setupAroundWithAll = setupAroundWith'+ -- | Use 'aroundAll' with a 'SetupFunc' setupAroundAll ::   SetupFunc outer ->
src/Test/Syd/OptParse.hs view
@@ -389,28 +389,28 @@   Env.prefixed "SYDTEST_" $     Environment       <$> Env.var (fmap Just . Env.str) "CONFIG_FILE" (Env.def Nothing <> Env.help "Config file")-        <*> seedSettingEnvironmentParser-        <*> ( Env.var (fmap Just . Env.auto) "RANDOMISE_EXECUTION_ORDER" (Env.def Nothing <> Env.help "Randomise the execution order of the tests in the test suite")-                <|> Env.var (fmap Just . Env.auto) "RANDOMIZE_EXECUTION_ORDER" (Env.def Nothing <> Env.help "Randomize the execution order of the tests in the test suite")-            )-        <*> Env.var (fmap Just . (Env.auto >=> parseThreads)) "PARALLELISM" (Env.def Nothing <> Env.help "How parallel to execute the tests")-        <*> Env.var (fmap Just . Env.auto) "MAX_SIZE" (Env.def Nothing <> Env.help "Maximum size parameter to pass to generators")-        <*> Env.var (fmap Just . Env.auto) "MAX_SUCCESS" (Env.def Nothing <> Env.help "Number of quickcheck examples to run")-        <*> Env.var (fmap Just . Env.auto) "MAX_DISCARD" (Env.def Nothing <> Env.help "Maximum number of discarded tests per successful test before giving up")-        <*> Env.var (fmap Just . Env.auto) "MAX_SHRINKS" (Env.def Nothing <> Env.help "Maximum number of shrinks of a failing test input")-        <*> Env.var (fmap Just . Env.auto) "GOLDEN_START" (Env.def Nothing <> Env.help "Whether to write golden tests if they do not exist yet")-        <*> Env.var (fmap Just . Env.auto) "GOLDEN_RESET" (Env.def Nothing <> Env.help "Whether to overwrite golden tests instead of having them fail")-        <*> ( Env.var (fmap Just . Env.auto) "COLOUR" (Env.def Nothing <> Env.help "Whether to use coloured output")-                <|> Env.var (fmap Just . Env.auto) "COLOR" (Env.def Nothing <> Env.help "Whether to use colored output")-            )-        <*> Env.var (fmap Just . Env.str) "FILTER" (Env.def Nothing <> Env.help "Filter to select which parts of the test tree to run")-        <*> Env.var (fmap Just . Env.auto) "FAIL_FAST" (Env.def Nothing <> Env.help "Whether to stop executing upon the first test failure")-        <*> Env.var (fmap Just . (Env.auto >=> parseIterations)) "ITERATIONS" (Env.def Nothing <> Env.help "How many iterations to use to look diagnose flakiness")-        <*> Env.var (fmap Just . Env.auto) "RETRIES" (Env.def Nothing <> Env.help "The number of retries to use for flakiness diagnostics. 0 means 'no flakiness diagnostics'")-        <*> Env.var (fmap Just . Env.auto) "FAIL_ON_FLAKY" (Env.def Nothing <> Env.help "Whether to fail when flakiness is detected in tests marked as potentially flaky")-        <*> Env.var (fmap Just . Env.auto) "PROGRESS" (Env.def Nothing <> Env.help "Report progress as tests run")-        <*> Env.var (fmap Just . Env.auto) "DEBUG" (Env.def Nothing <> Env.help "Turn on debug mode. This implies RANDOMISE_EXECUTION_ORDER=False, PARALLELISM=1 and FAIL_FAST=True.")-        <*> Env.var (fmap Just . Env.auto) "PROFILE" (Env.def Nothing <> Env.help "Turn on profiling mode.")+      <*> seedSettingEnvironmentParser+      <*> ( Env.var (fmap Just . Env.auto) "RANDOMISE_EXECUTION_ORDER" (Env.def Nothing <> Env.help "Randomise the execution order of the tests in the test suite")+              <|> Env.var (fmap Just . Env.auto) "RANDOMIZE_EXECUTION_ORDER" (Env.def Nothing <> Env.help "Randomize the execution order of the tests in the test suite")+          )+      <*> Env.var (fmap Just . (Env.auto >=> parseThreads)) "PARALLELISM" (Env.def Nothing <> Env.help "How parallel to execute the tests")+      <*> Env.var (fmap Just . Env.auto) "MAX_SIZE" (Env.def Nothing <> Env.help "Maximum size parameter to pass to generators")+      <*> Env.var (fmap Just . Env.auto) "MAX_SUCCESS" (Env.def Nothing <> Env.help "Number of quickcheck examples to run")+      <*> Env.var (fmap Just . Env.auto) "MAX_DISCARD" (Env.def Nothing <> Env.help "Maximum number of discarded tests per successful test before giving up")+      <*> Env.var (fmap Just . Env.auto) "MAX_SHRINKS" (Env.def Nothing <> Env.help "Maximum number of shrinks of a failing test input")+      <*> Env.var (fmap Just . Env.auto) "GOLDEN_START" (Env.def Nothing <> Env.help "Whether to write golden tests if they do not exist yet")+      <*> Env.var (fmap Just . Env.auto) "GOLDEN_RESET" (Env.def Nothing <> Env.help "Whether to overwrite golden tests instead of having them fail")+      <*> ( Env.var (fmap Just . Env.auto) "COLOUR" (Env.def Nothing <> Env.help "Whether to use coloured output")+              <|> Env.var (fmap Just . Env.auto) "COLOR" (Env.def Nothing <> Env.help "Whether to use colored output")+          )+      <*> Env.var (fmap Just . Env.str) "FILTER" (Env.def Nothing <> Env.help "Filter to select which parts of the test tree to run")+      <*> Env.var (fmap Just . Env.auto) "FAIL_FAST" (Env.def Nothing <> Env.help "Whether to stop executing upon the first test failure")+      <*> Env.var (fmap Just . (Env.auto >=> parseIterations)) "ITERATIONS" (Env.def Nothing <> Env.help "How many iterations to use to look diagnose flakiness")+      <*> Env.var (fmap Just . Env.auto) "RETRIES" (Env.def Nothing <> Env.help "The number of retries to use for flakiness diagnostics. 0 means 'no flakiness diagnostics'")+      <*> Env.var (fmap Just . Env.auto) "FAIL_ON_FLAKY" (Env.def Nothing <> Env.help "Whether to fail when flakiness is detected in tests marked as potentially flaky")+      <*> Env.var (fmap Just . Env.auto) "PROGRESS" (Env.def Nothing <> Env.help "Report progress as tests run")+      <*> Env.var (fmap Just . Env.auto) "DEBUG" (Env.def Nothing <> Env.help "Turn on debug mode. This implies RANDOMISE_EXECUTION_ORDER=False, PARALLELISM=1 and FAIL_FAST=True.")+      <*> Env.var (fmap Just . Env.auto) "PROFILE" (Env.def Nothing <> Env.help "Turn on profiling mode.")   where     parseThreads :: Word -> Either e Threads     parseThreads 1 = Right Synchronous
src/Test/Syd/Output.hs view
@@ -238,22 +238,22 @@   | M.null labels = []   | map fst (M.toList labels) == [[]] = []   | otherwise =-    [chunk "Labels"] :-    map-      ( pad-          . ( \(ss, i) ->-                [ chunk-                    ( T.pack-                        ( printf-                            "%5.2f%% %s"-                            (100 * fromIntegral i / fromIntegral totalCount :: Double)-                            (commaList (map show ss))+      [chunk "Labels"]+        : map+          ( pad+              . ( \(ss, i) ->+                    [ chunk+                        ( T.pack+                            ( printf+                                "%5.2f%% %s"+                                (100 * fromIntegral i / fromIntegral totalCount :: Double)+                                (commaList (map show ss))+                            )                         )-                    )-                ]-            )-      )-      (M.toList labels)+                    ]+                )+          )+          (M.toList labels)   where     pad = (chunk (T.pack (replicate paddingSize ' ')) :) @@ -262,19 +262,19 @@ classesChunks (Just classes)   | M.null classes = []   | otherwise =-    [chunk "Classes"] :-    map-      ( pad-          . ( \(s, i) ->-                [ chunk-                    ( T.pack-                        ( printf "%5.2f%% %s" (100 * fromIntegral i / fromIntegral total :: Double) s+      [chunk "Classes"]+        : map+          ( pad+              . ( \(s, i) ->+                    [ chunk+                        ( T.pack+                            ( printf "%5.2f%% %s" (100 * fromIntegral i / fromIntegral total :: Double) s+                            )                         )-                    )-                ]-            )-      )-      (M.toList classes)+                    ]+                )+          )+          (M.toList classes)   where     pad = (chunk (T.pack (replicate paddingSize ' ')) :)     total = sum $ map snd $ M.toList classes@@ -285,20 +285,20 @@   where     goTable :: String -> Map String Int -> [[Chunk]]     goTable tableName percentages =-      [chunk " "] :-      [chunk (T.pack tableName)] :-      map-        ( pad-            . ( \(s, i) ->-                  [ chunk-                      ( T.pack-                          ( printf "%5.2f%% %s" (100 * fromIntegral i / fromIntegral total :: Double) s-                          )-                      )-                  ]-              )-        )-        (M.toList percentages)+      [chunk " "]+        : [chunk (T.pack tableName)]+        : map+          ( pad+              . ( \(s, i) ->+                    [ chunk+                        ( T.pack+                            ( printf "%5.2f%% %s" (100 * fromIntegral i / fromIntegral total :: Double) s+                            )+                        )+                    ]+                )+          )+          (M.toList percentages)       where         pad = (chunk (T.pack (replicate paddingSize ' ')) :)         total = sum $ map snd $ M.toList percentages
src/Test/Syd/Runner/Single.hs view
@@ -65,12 +65,12 @@     go w       | w <= 1 = (:| []) <$> runFunc       | otherwise = do-        result <- runFunc-        if testStatusMatchesExpectationMode (testRunResultStatus result) em-          then pure (result :| [])-          else do-            rest <- go (pred w)-            pure (result NE.<| rest)+          result <- runFunc+          if testStatusMatchesExpectationMode (testRunResultStatus result) em+            then pure (result :| [])+            else do+              rest <- go (pred w)+              pure (result NE.<| rest)       where         runFunc :: IO TestRunResult         runFunc = testDefVal td progressReporter (\f -> f l ())
src/Test/Syd/SVG.hs view
@@ -57,32 +57,32 @@                     ]                     (toElement (show workerIx)),             -- Timing labels-            g_ [] $-              mconcat $-                flip-                  map-                  [ 0,-                    nanosPerSecond -- In steps of 1 second-                    .. totalDuration-                  ]-                  $ \t ->-                    mconcat-                      [ -- Label-                        text_-                          [ X_ <<- fromString (show (timeX maximumTime t)),-                            Y_ <<- fromString (show (topBarHeight - fontSize))-                          ]-                          (toElement (show (t `div` 1_000_000_000) <> " s")),-                        -- Line-                        line_-                          [ X1_ <<- fromString (show (timeX maximumTime t)),-                            Y1_ <<- fromString (show topBarHeight),-                            X2_ <<- fromString (show (timeX maximumTime t)),-                            Y2_ <<- fromString (show (workerY (maxWorker + 1))),-                            Class_ <<- "time"-                          ]-                          ""-                      ],+            g_ []+              $ mconcat+              $ flip+                map+                [ 0,+                  nanosPerSecond -- In steps of 1 second+                  .. totalDuration+                ]+              $ \t ->+                mconcat+                  [ -- Label+                    text_+                      [ X_ <<- fromString (show (timeX maximumTime t)),+                        Y_ <<- fromString (show (topBarHeight - fontSize))+                      ]+                      (toElement (show (t `div` 1_000_000_000) <> " s")),+                    -- Line+                    line_+                      [ X1_ <<- fromString (show (timeX maximumTime t)),+                        Y1_ <<- fromString (show topBarHeight),+                        X2_ <<- fromString (show (timeX maximumTime t)),+                        Y2_ <<- fromString (show (workerY (maxWorker + 1))),+                        Class_ <<- "time"+                      ]+                      ""+                  ],             g_ [] $               mconcat $                 flip map tests $ \(path, TDef timed _) ->
sydtest.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-version:        0.15.0.0+version:        0.15.1.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@@ -93,12 +93,34 @@     , svg-builder     , text     , vector+  default-language: Haskell2010   if os(windows)     build-depends:         ansi-terminal   else     build-depends:         safe-coloured-text-terminfo++test-suite sydtest-multi-discover-test+  type: exitcode-stdio-1.0+  main-is: Main.hs+  other-modules:+      Bar.BarSpec+      Bar.Spec+      Baz.Qux.QuxSpec+      Baz.Qux.Spec+      DoNotDiscover.FooSpec+      Foo.FooSpec+      Foo.Spec+      Paths_sydtest+  hs-source-dirs:+      multi-discover-test+  ghc-options: -threaded -rtsopts -with-rtsopts=-N+  build-tool-depends:+      sydtest-discover:sydtest-discover+  build-depends:+      base >=4.7 && <5+    , sydtest   default-language: Haskell2010  test-suite sydtest-output-test
test/Test/Syd/DiffSpec.hs view
@@ -192,7 +192,8 @@      let rebuildFirst :: Vector (PolyDiff (Vector a) (Vector b)) -> Vector a         rebuildFirst =-          V.concat . V.toList+          V.concat+            . V.toList             . V.mapMaybe               ( \case                   First a -> Just a@@ -206,7 +207,8 @@      let rebuildSecond :: Vector (PolyDiff (Vector a) (Vector b)) -> Vector b         rebuildSecond =-          V.concat . V.toList+          V.concat+            . V.toList             . V.mapMaybe               ( \case                   First _ -> Nothing
test/Test/Syd/SpecifySpec.hs view
@@ -8,7 +8,8 @@   describe "boolean" $ do     it "boolean" True     before (pure (2 :: Int)) $-      it "boolean function (inner)" $ \i -> even i+      it "boolean function (inner)" $+        \i -> even i     beforeAll (pure (2 :: Int)) $ do       itWithOuter "boolean function (one outer)" $ \i -> even i       itWithBoth "boolean function (both inner and outer)" $ \i () -> even i@@ -16,7 +17,8 @@   describe "IO action" $ do     it "IO action" True     before (pure (2 :: Int)) $-      it "IO action function (inner)" $ \i -> i `shouldBe` 2+      it "IO action function (inner)" $+        \i -> i `shouldBe` 2     beforeAll (pure (1 :: Int)) $ do       itWithOuter "IO action function (one outer)" $ \i -> i `shouldBe` 1       itWithBoth "IO action function (both inner and outer)" $ \i () -> i `shouldBe` 1
test/Test/Syd/TimingSpec.hs view
@@ -13,14 +13,16 @@ spec :: Spec spec = doNotRandomiseExecutionOrder $ do   it "takes at least 10 milliseconds (pure)" $-    unsafePerformIO take10ms `seq` True+    unsafePerformIO take10ms `seq`+      True   it "takes at least 10 milliseconds (IO)" $ do     threadDelay 10_000   it "takes at least 10 milliseconds (property) " $     property $ \() -> do       threadDelay 100   it "takes at least 100 milliseconds (pure)" $-    unsafePerformIO take100ms `seq` True+    unsafePerformIO take100ms `seq`+      True   it "takes at least 100 milliseconds (IO)" $ do     threadDelay 100_000   it "takes at least 100 milliseconds (property) " $
test_resources/output-test.txt view
@@ -348,7 +348,7 @@        Retries: 3 (does not look flaky)        Prelude.undefined        CallStack (from HasCallStack):-         error, called at libraries/base/GHC/Err.hs:75:14 in base:GHC.Err+         error, called at libraries/base/GHC/Err.hs:74:14 in base:GHC.Err          undefined, called at output-test/Spec.hs:38:31 in main:Spec      [36m  output-test/Spec.hs:39[m@@ -356,7 +356,7 @@        Retries: 3 (does not look flaky)        Prelude.undefined        CallStack (from HasCallStack):-         error, called at libraries/base/GHC/Err.hs:75:14 in base:GHC.Err+         error, called at libraries/base/GHC/Err.hs:74:14 in base:GHC.Err          undefined, called at output-test/Spec.hs:39:28 in main:Spec      [36m  output-test/Spec.hs:40[m@@ -773,7 +773,7 @@        Retries: 3 (does not look flaky)        Prelude.undefined        CallStack (from HasCallStack):-         error, called at libraries/base/GHC/Err.hs:75:14 in base:GHC.Err+         error, called at libraries/base/GHC/Err.hs:74:14 in base:GHC.Err          undefined, called at output-test/Spec.hs:204:26 in main:Spec        context   @@ -882,7 +882,7 @@        Generated: [33m0[m        Prelude.undefined        CallStack (from HasCallStack):-         error, called at libraries/base/GHC/Err.hs:75:14 in base:GHC.Err+         error, called at libraries/base/GHC/Err.hs:74:14 in base:GHC.Err          undefined, called at output-test/Spec.hs:338:80 in main:Spec      [36m  output-test/Spec.hs:339[m@@ -892,12 +892,12 @@        Generated: [33mException thrown while showing test case:   Prelude.undefined   CallStack (from HasCallStack):-    error, called at libraries/base/GHC/Err.hs:75:14 in base:GHC.Err+    error, called at libraries/base/GHC/Err.hs:74:14 in base:GHC.Err     undefined, called at output-test/Spec.hs:339:74 in main:Spec [m        Prelude.undefined        CallStack (from HasCallStack):-         error, called at libraries/base/GHC/Err.hs:75:14 in base:GHC.Err+         error, called at libraries/base/GHC/Err.hs:74:14 in base:GHC.Err          undefined, called at output-test/Spec.hs:339:74 in main:Spec      [36m  output-test/Spec.hs:342[m@@ -909,7 +909,7 @@        Retries: 3 (does not look flaky)        Prelude.undefined        CallStack (from HasCallStack):-         error, called at libraries/base/GHC/Err.hs:75:14 in base:GHC.Err+         error, called at libraries/base/GHC/Err.hs:74:14 in base:GHC.Err          undefined, called at output-test/Spec.hs:345:29 in main:Spec      [36m  output-test/Spec.hs:348[m