1+ {-# LANGUAGE NamedFieldPuns #-}
2+
13module Testnet.Property.Run
24 ( runTestnet
35 -- Ignore tests on various OSs
@@ -19,11 +21,12 @@ import Data.Bool (bool)
1921import Data.String (IsString (.. ))
2022import qualified System.Console.ANSI as ANSI
2123import System.Console.ANSI (Color (.. ), ColorIntensity (.. ), ConsoleLayer (.. ), SGR (.. ))
24+ import System.Directory
2225import qualified System.Exit as IO
2326import qualified System.Info as SYS
2427import qualified System.IO as IO
2528
26- import Testnet.Property.Util (integrationWorkspace )
29+ import Testnet.Property.Util (integration , integrationWorkspace )
2730import Testnet.Start.Types
2831
2932import Hedgehog (Property )
@@ -35,11 +38,11 @@ import qualified Test.Tasty.Hedgehog as H
3538import Test.Tasty.Providers (testPassed )
3639import Test.Tasty.Runners (Result (resultShortDescription ), TestTree )
3740
38- runTestnet :: (Conf -> H. Integration a ) -> IO ()
39- runTestnet tn = do
41+ runTestnet :: CardanoTestnetOptions -> (Conf -> H. Integration a ) -> IO ()
42+ runTestnet tnOpts tn = do
4043 tvRunning <- STM. newTVarIO False
4144
42- void . H. check $ testnetProperty $ \ c -> do
45+ void . H. check $ testnetProperty tnOpts $ \ c -> do
4346 void $ tn c
4447 H. evalIO . STM. atomically $ STM. writeTVar tvRunning True
4548
@@ -60,17 +63,30 @@ runTestnet tn = do
6063 IO. exitFailure
6164
6265
63- testnetProperty :: (Conf -> H. Integration () ) -> H. Property
64- testnetProperty tn = integrationWorkspace " testnet" $ \ workspaceDir -> do
65- conf <- mkConf workspaceDir
66-
67- -- Fork a thread to keep alive indefinitely any resources allocated by testnet.
68- void . H. evalM . liftResourceT . resourceForkIO . forever . liftIO $ IO. threadDelay 10000000
69-
70- void $ tn conf
71-
72- H. failure -- Intentional failure to force failure report
73-
66+ testnetProperty :: CardanoTestnetOptions -> (Conf -> H. Integration () ) -> H. Property
67+ testnetProperty CardanoTestnetOptions {cardanoOutputDir} runTn =
68+ case cardanoOutputDir of
69+ Nothing -> do
70+ integrationWorkspace " testnet" $ \ workspaceDir -> do
71+ mkConf workspaceDir >>= forkAndRunTestnet
72+ Just userOutputDir ->
73+ integration $ do
74+ absUserOutputDir <- H. evalIO $ makeAbsolute userOutputDir
75+ dirExists <- H. evalIO $ doesDirectoryExist absUserOutputDir
76+ (if dirExists then
77+ -- Likely dangerous, but who are we to judge the user?
78+ H. note_ $ " Reusing " <> absUserOutputDir
79+ else do
80+ liftIO $ createDirectory absUserOutputDir
81+ H. note_ $ " Created " <> absUserOutputDir)
82+ conf <- mkConf absUserOutputDir
83+ forkAndRunTestnet conf
84+ where
85+ forkAndRunTestnet conf = do
86+ -- Fork a thread to keep alive indefinitely any resources allocated by testnet.
87+ void $ H. evalM . liftResourceT . resourceForkIO . forever . liftIO $ IO. threadDelay 10000000
88+ void $ runTn conf
89+ H. failure -- Intentional failure to force failure report
7490
7591-- Ignore properties on various OSs
7692
0 commit comments