diff options
author | Roman Smrž <roman.smrz@seznam.cz> | 2025-06-15 21:00:17 +0200 |
---|---|---|
committer | Roman Smrž <roman.smrz@seznam.cz> | 2025-06-18 20:57:42 +0200 |
commit | 9d3982e6909956c99244fc86756f2476c9a3fe4a (patch) | |
tree | 55d33229fc21f317f9911f62b9afcace12ce5f1d | |
parent | 255e8baa916f9103dc703447474ca38ba118abe8 (diff) |
Timeout setting in config file
Changelog: Added optional `timeout` setting to config file
-rw-r--r-- | README.md | 1 | ||||
-rw-r--r-- | src/Config.hs | 13 | ||||
-rw-r--r-- | src/Main.hs | 1 |
3 files changed, 14 insertions, 1 deletions
@@ -88,6 +88,7 @@ This is a YAML file with following fields: * `tool`: path to the test tool, which may be overridden by the `--tool` command-line option. * `tests`: glob pattern that expands to all the test script files that should be used. +* `timeout`: initial timeout for test steps like `expect`, given as `int` or `float`; defaults to `1` if not specified. Script language --------------- diff --git a/src/Config.hs b/src/Config.hs index e1dcebf..adf0321 100644 --- a/src/Config.hs +++ b/src/Config.hs @@ -8,6 +8,7 @@ module Config ( import Control.Monad.Combinators import Data.ByteString.Lazy qualified as BS +import Data.Scientific import Data.Text qualified as T import Data.YAML @@ -19,7 +20,8 @@ import System.FilePath.Glob data Config = Config { configDir :: FilePath , configTool :: Maybe FilePath - , configTests :: [Pattern] + , configTests :: [ Pattern ] + , configTimeout :: Maybe Scientific } deriving (Show) @@ -31,8 +33,17 @@ instance FromYAML (FilePath -> Config) where , m .:? "tests" .!= [] -- list of patterns ] ) + configTimeout <- fmap fromNumber <$> m .:! "timeout" return $ \configDir -> Config {..} +newtype Number = Number { fromNumber :: Scientific } + +instance FromYAML Number where + parseYAML = \case + Scalar _ (SFloat x) -> return $ Number $ realToFrac x + Scalar _ (SInt x) -> return $ Number $ fromIntegral x + node -> typeMismatch "int or float" node + findConfig :: IO (Maybe FilePath) findConfig = go "." where diff --git a/src/Main.hs b/src/Main.hs index 36f88bd..2f4a0fe 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -114,6 +114,7 @@ main = do { optTest = defaultTestOptions { optDefaultTool = envtool , optTestDir = normalise $ baseDir </> optTestDir defaultTestOptions + , optTimeout = fromMaybe (optTimeout defaultTestOptions) $ configTimeout =<< config } } |