summaryrefslogtreecommitdiff
path: root/src/Config.hs
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2026-10-17 11:10:40 +0200
committerRoman Smrž <roman.smrz@seznam.cz>2026-10-20 20:21:44 +0200
commit5f892bc3cd212f362b0a8f29528b783b142da8e8 (patch)
treea345cab6908eb72632684be751caf0ea1c793f1c /src/Config.hs
parentdb6cd2706417d38b670438475c30a657ce2e5ed4 (diff)
Config option to find tool path using cabal
Changelog: Added config file option to find test tool executable via cabal.
Diffstat (limited to 'src/Config.hs')
-rw-r--r--src/Config.hs20
1 files changed, 18 insertions, 2 deletions
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