diff options
author | Roman Smrž <roman.smrz@seznam.cz> | 2025-06-01 20:49:29 +0200 |
---|---|---|
committer | Roman Smrž <roman.smrz@seznam.cz> | 2025-06-02 21:51:28 +0200 |
commit | 23a5528e2b5a6008b3572a172e5f1671a13d28b8 (patch) | |
tree | 9a15f9b903cdc016c24a4d9ef0e38b5da005e70f /src/Config.hs | |
parent | b698fa819723635ddbdde15e592c3b7acc018024 (diff) |
Test script execution based on config file
Diffstat (limited to 'src/Config.hs')
-rw-r--r-- | src/Config.hs | 30 |
1 files changed, 12 insertions, 18 deletions
diff --git a/src/Config.hs b/src/Config.hs index 7f5895c..e1dcebf 100644 --- a/src/Config.hs +++ b/src/Config.hs @@ -2,6 +2,7 @@ module Config ( Config(..), findConfig, parseConfig, + getConfigTestFiles, ) where import Control.Monad.Combinators @@ -16,31 +17,21 @@ import System.FilePath import System.FilePath.Glob data Config = Config - { configTool :: Maybe FilePath + { configDir :: FilePath + , configTool :: Maybe FilePath , configTests :: [Pattern] } deriving (Show) -instance Semigroup Config where - a <> b = Config - { configTool = maybe (configTool b) Just (configTool a) - , configTests = configTests a ++ configTests b - } - -instance Monoid Config where - mempty = Config - { configTool = Nothing - , configTests = [] - } - -instance FromYAML Config where - parseYAML = withMap "Config" $ \m -> Config - <$> (fmap T.unpack <$> m .:? "tool") - <*> (map (compile . T.unpack) <$> foldr1 (<|>) +instance FromYAML (FilePath -> Config) where + parseYAML = withMap "Config" $ \m -> do + configTool <- (fmap T.unpack <$> m .:? "tool") + configTests <- (map (compile . T.unpack) <$> foldr1 (<|>) [ fmap (:[]) (m .: "tests") -- single pattern , m .:? "tests" .!= [] -- list of patterns ] ) + return $ \configDir -> Config {..} findConfig :: IO (Maybe FilePath) findConfig = go "." @@ -63,4 +54,7 @@ parseConfig path = do Left (pos, err) -> do putStr $ prettyPosWithSource pos contents err exitFailure - Right conf -> return conf + Right conf -> return $ conf $ takeDirectory path + +getConfigTestFiles :: Config -> IO [ FilePath ] +getConfigTestFiles config = concat <$> mapM (flip globDir1 $ configDir config) (configTests config) |