Skip to content

Commit

Permalink
refactor: factorize withArgs [] in a helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
guibou committed Sep 22, 2024
1 parent 23baea5 commit 4e317b3
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions sydtest/src/Test/Syd/Runner.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ import Test.Syd.SpecDef
import Text.Colour
import Text.Printf

-- | Set the command line argument of the underlying action to empty.
--
-- The action behaves as if no command line argument were provided. Especially,
-- it removes all the arguments initially provided to sydtest and provides a
-- reproducible environment.
setNullArgs :: IO a -> IO a
setNullArgs action = withArgs [] action

sydTestResult :: Settings -> TestDefM '[] () r -> IO (Timed ResultForest)
sydTestResult settings spec = do
let totalIterations = case settingIterations settings of
Expand All @@ -44,7 +52,7 @@ sydTestOnce :: Settings -> TestDefM '[] () r -> IO (Timed ResultForest)
sydTestOnce settings spec = do
specForest <- execTestDefM settings spec
tc <- deriveTerminalCapababilities settings
withArgs [] $ do
setNullArgs $ do
setPseudorandomness (settingSeed settings)
case settingThreads settings of
Synchronous -> runSpecForestInterleavedWithOutputSynchronously settings specForest
Expand All @@ -71,7 +79,7 @@ sydTestOnce settings spec = do

sydTestIterations :: Maybe Word -> Settings -> TestDefM '[] () r -> IO (Timed ResultForest)
sydTestIterations totalIterations settings spec =
withArgs [] $ do
setNullArgs $ do
nbCapabilities <- fromIntegral <$> getNumCapabilities

let runOnce settings_ = do
Expand Down

0 comments on commit 4e317b3

Please sign in to comment.