From 9d3982e6909956c99244fc86756f2476c9a3fe4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Sun, 15 Jun 2025 21:00:17 +0200 Subject: Timeout setting in config file Changelog: Added optional `timeout` setting to config file --- README.md | 1 + src/Config.hs | 13 ++++++++++++- src/Main.hs | 1 + 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f9a64a2..77d6baa 100644 --- a/README.md +++ b/README.md @@ -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 } } -- cgit v1.2.3