From 5f892bc3cd212f362b0a8f29528b783b142da8e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Sat, 17 Oct 2026 11:10:40 +0200 Subject: Config option to find tool path using cabal Changelog: Added config file option to find test tool executable via cabal. --- src/Config.hs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'src/Config.hs') diff --git a/src/Config.hs b/src/Config.hs index af2161a..8555540 100644 --- a/src/Config.hs +++ b/src/Config.hs @@ -1,5 +1,6 @@ module Config ( Config(..), + ConfigTool(..), findConfig, parseConfig, getConfigTestFiles, @@ -20,7 +21,7 @@ import System.FilePath.Glob data Config = Config { configDir :: FilePath - , configTool :: Maybe FilePath + , configTool :: Maybe ConfigTool , configTests :: [ Pattern ] , configSelect :: Maybe [ Text ] , configExclude :: [ Text ] @@ -28,9 +29,18 @@ data Config = Config } deriving (Show) +data ConfigTool + = ToolPath FilePath + | ToolCabal Text + deriving (Show) + instance FromYAML (FilePath -> Config) where parseYAML = withMap "Config" $ \m -> do - configTool <- (fmap T.unpack <$> m .:? "tool") + configTool <- foldr1 (<|>) + [ Just . ToolPath . T.unpack <$> m .: "tool" -- tool path as string + , Just <$> m .: "tool" + , return Nothing + ] configTests <- (map (compile . T.unpack) <$> foldr1 (<|>) [ fmap (:[]) (m .: "tests") -- single pattern , m .:? "tests" .!= [] -- list of patterns @@ -55,6 +65,12 @@ instance FromYAML Number where Scalar _ (SInt x) -> return $ Number $ fromIntegral x node -> typeMismatch "int or float" node +instance FromYAML ConfigTool where + parseYAML = withMap "tool specification" $ \m -> foldr1 (<|>) + [ ToolPath . T.unpack <$> m .: "path" + , ToolCabal <$> m .: "cabal" + ] + findConfig :: IO (Maybe FilePath) findConfig = go "." where -- cgit v1.2.3