packages feed

sandwich 0.1.2.0 → 0.1.3.0

raw patch · 9 files changed

+75/−10 lines, 9 files

Files

CHANGELOG.md view
@@ -2,6 +2,10 @@  ## Unreleased changes +## 0.1.3.0++* Add the --prune option (#69)+ ## 0.1.2.0  * Be able to control `sandwich-webdriver` download directory.
LICENSE view
@@ -1,4 +1,4 @@-Copyright Tom McLaughlin (c) 2022+Copyright Tom McLaughlin (c) 2023  All rights reserved. 
sandwich.cabal view
@@ -1,11 +1,11 @@ cabal-version: 1.12 --- This file has been generated from package.yaml by hpack version 0.35.0.+-- This file has been generated from package.yaml by hpack version 0.35.1. -- -- see: https://github.com/sol/hpack  name:           sandwich-version:        0.1.2.0+version:        0.1.3.0 synopsis:       Yet another test framework for Haskell description:    Please see the <https://codedownio.github.io/sandwich documentation>. category:       Testing@@ -13,7 +13,7 @@ bug-reports:    https://github.com/codedownio/sandwich/issues author:         Tom McLaughlin maintainer:     tom@codedown.io-copyright:      2022 Tom McLaughlin+copyright:      2023 Tom McLaughlin license:        BSD3 license-file:   LICENSE build-type:     Simple@@ -60,6 +60,7 @@       Test.Sandwich.Interpreters.FilterTree       Test.Sandwich.Interpreters.FilterTreeModule       Test.Sandwich.Interpreters.PrettyShow+      Test.Sandwich.Interpreters.PruneTree       Test.Sandwich.Interpreters.RunTree       Test.Sandwich.Interpreters.RunTree.Logging       Test.Sandwich.Interpreters.RunTree.Util
src/Test/Sandwich/ArgParsing.hs view
@@ -86,7 +86,8 @@   <$> formatter   <*> logLevel   <*> optional (option auto (long "visibility-threshold" <> short 'v' <> showDefault <> help "Set the visibility threshold for formatters" <> metavar "INT"))-  <*> many (strOption (long "filter" <> short 'f' <> help "Filter test tree by string matching text example labels" <> metavar "STRING"))+  <*> many (strOption (long "prune" <> short 'p' <> help "Prune test subtrees by string matching text example labels. The matched test and all its children are removed. Pruning happens before filtering, if any" <> metavar "STRING"))+  <*> many (strOption (long "filter" <> short 'f' <> help "Filter test tree by string matching text example labels. Filtering happens after pruning, if any" <> metavar "STRING"))   <*> option auto (long "repeat" <> short 'r' <> showDefault <> help "Repeat the test N times and report how many failures occur" <> value 1 <> metavar "INT")   <*> optional (strOption (long "fixed-root" <> help "Store test artifacts at a fixed path" <> metavar "STRING"))   <*> optional (flag False True (long "dry-run" <> help "Skip actually launching the tests. This is useful if you want to see the set of the tests that would be run, or start them manually in the terminal UI."))@@ -260,6 +261,9 @@     optionsTestArtifactsDirectory = case optFixedRoot of       Nothing -> TestArtifactsGeneratedDirectory "test_runs" (formatTime <$> getCurrentTime)       Just path -> TestArtifactsFixedDirectory path+    , optionsPruneTree = case optTreePrune of+        [] -> Nothing+        xs -> Just $ TreeFilter xs     , optionsFilterTree = case optTreeFilter of         [] -> Nothing         xs -> Just $ TreeFilter xs
src/Test/Sandwich/Internal/Running.hs view
@@ -18,6 +18,7 @@ import System.Exit import System.FilePath import Test.Sandwich.Interpreters.FilterTree+import Test.Sandwich.Interpreters.PruneTree import Test.Sandwich.Interpreters.RunTree import Test.Sandwich.Interpreters.RunTree.Util import Test.Sandwich.Interpreters.StartTree@@ -36,15 +37,19 @@   startSandwichTree' baseContext options spec  startSandwichTree' :: BaseContext -> Options -> CoreSpec -> IO [RunNode BaseContext]-startSandwichTree' baseContext (Options {..}) spec' = do-  let spec = maybe spec' (L.foldl' filterTree spec' . unTreeFilter) optionsFilterTree--  runTree <- atomically $ specToRunTreeVariable baseContext spec+startSandwichTree' baseContext (Options {optionsPruneTree=(unwrapTreeFilter -> pruneOpts), optionsFilterTree=(unwrapTreeFilter -> filterOpts), optionsDryRun}) spec = do+  runTree <- spec+    & (\tree -> L.foldl' pruneTree tree pruneOpts)+    & (\tree -> L.foldl' filterTree tree filterOpts)+    & atomically . specToRunTreeVariable baseContext    if | optionsDryRun -> markAllChildrenWithResult runTree baseContext DryRun      | otherwise -> void $ async $ void $ runNodesSequentially runTree baseContext    return runTree++unwrapTreeFilter :: Maybe TreeFilter -> [String]+unwrapTreeFilter = maybe [] unTreeFilter  runSandwichTree :: Options -> CoreSpec -> IO [RunNode BaseContext] runSandwichTree options spec = do
+ src/Test/Sandwich/Interpreters/PruneTree.hs view
@@ -0,0 +1,46 @@++-- | Prunes any nodes and their children in a spec tree that match any of a list of names++module Test.Sandwich.Interpreters.PruneTree (pruneTree) where++import Control.Monad.Free+import qualified Data.List as L+import Test.Sandwich.Types.Spec++pruneTree :: Free (SpecCommand context m) () -> String -> Free (SpecCommand context m) ()+pruneTree tree pruneLabel = go tree+  where+    go :: Free (SpecCommand context m) () -> Free (SpecCommand context m) ()+    go = \case+      (Free (It'' loc no label' ex next))+        | label' `doesNotMatch` pruneLabel -> Free (It'' loc no label' ex (go next))+        | otherwise -> go next+      (Free (Introduce'' loc no label' cl alloc cleanup subspec next))+        | label' `doesNotMatch` pruneLabel ->+          case go subspec of+            (Pure _) -> go next+            subspec' -> Free (Introduce'' loc no label' cl alloc cleanup subspec' (go next))+        | otherwise -> go next++      (Free (IntroduceWith'' loc no label' cl action subspec next))+        | label' `doesNotMatch` pruneLabel ->+          case go subspec of+            (Pure _) -> go next+            subspec' -> Free (IntroduceWith'' loc no label' cl action subspec' (go next))+        | otherwise -> go next+      (Free (Parallel'' loc no subspec next)) ->+        case go subspec of+          (Pure _) -> go next+          subspec' -> Free (Parallel'' loc no subspec' (go next))+      -- Before'', After'', Around'', Describe''+      (Free x)+        | label x `doesNotMatch` pruneLabel ->+          case go (subspec x) of+            (Pure _) -> go (next x)+            subspec' -> Free (x { subspec = subspec', next = go (next x) })+        | otherwise ->+          go (next x)+      pureM@(Pure _) -> pureM++doesNotMatch :: String -> String -> Bool+doesNotMatch label match = not $ match `L.isInfixOf` label
src/Test/Sandwich/Options.hs view
@@ -20,6 +20,7 @@    -- * Filtering   , optionsFilterTree+  , optionsPruneTree   , TreeFilter(..)    -- * Timing@@ -43,6 +44,7 @@   , optionsSavedLogLevel = Just LevelDebug   , optionsMemoryLogLevel = Just LevelDebug   , optionsLogFormatter = defaultLogEntryFormatter+  , optionsPruneTree = Nothing   , optionsFilterTree = Nothing   , optionsDryRun = False   , optionsFormatters = [SomeFormatter defaultPrintFormatter]
src/Test/Sandwich/Types/ArgParsing.hs view
@@ -57,6 +57,7 @@   optFormatter :: FormatterType   , optLogLevel :: Maybe LogLevel   , optVisibilityThreshold :: Maybe Int+  , optTreePrune :: [String]   , optTreeFilter :: [String]   , optRepeatCount :: Int   , optFixedRoot :: Maybe String
src/Test/Sandwich/Types/RunTree.hs view
@@ -259,8 +259,10 @@   -- ^ Test log level to store in memory while tests are running. (These logs are presented in formatters, etc.).   , optionsLogFormatter :: LogEntryFormatter   -- ^ Formatter function for log entries.+  , optionsPruneTree :: Maybe TreeFilter+  -- ^ Filter to apply to the text tree before running that prunes out the matched tests and their subtrees.   , optionsFilterTree :: Maybe TreeFilter-  -- ^ Filter to apply to the text tree before running.+  -- ^ Filter to apply to the text tree before running that only retains the matched tests.   , optionsDryRun :: Bool   -- ^ Whether to skip actually launching the tests. This is useful if you want to see the set of the tests that would be run, or start them manually in the terminal UI.   , optionsFormatters :: [SomeFormatter]