diff --git a/test-setup/package.yaml b/test-setup/package.yaml index 8d22b76..806982f 100644 --- a/test-setup/package.yaml +++ b/test-setup/package.yaml @@ -10,4 +10,8 @@ executables: source-dirs: src ghc-options: -Wall dependencies: + - aeson - directory + - lens + - lens-aeson + - yaml diff --git a/test-setup/src/Main.hs b/test-setup/src/Main.hs index dd1fae9..703bb99 100644 --- a/test-setup/src/Main.hs +++ b/test-setup/src/Main.hs @@ -1,3 +1,6 @@ +{-# LANGUAGE OverloadedLists #-} +{-# LANGUAGE OverloadedStrings #-} + {-# OPTIONS_GHC -Wno-unrecognised-pragmas #-} module Main (main) where import Data.List (findIndex, isInfixOf) @@ -6,6 +9,10 @@ import System.Environment (getArgs) import Control.Arrow ((>>>)) import Control.Monad (when) import System.Directory (copyFile) +import Data.Aeson.Lens (key, _Array) +import Control.Lens ((%~)) +import Data.Yaml ( decodeFileThrow, encodeFile ) +import qualified Data.Yaml as Yaml main :: IO () main = do @@ -34,10 +41,11 @@ modifyTests inputDir = do {-# HLINT ignore "Use null" #-} when (length newTestFileData > 0) $ writeFile testFile (unlines newTestFileData) - -- Add aeson, aeson-pretty, bytestring, hspec-core, stm and text packages to `tests` section of - -- package.yaml. - -- (assumes that the tests.test.dependencies is the last item in package.yaml!) - appendFile packageFile " - aeson\n - aeson-pretty\n - bytestring\n - hspec-core\n - stm\n - text\n" + -- Add aeson, aeson-pretty, bytestring, hspec-core, stm and text packages to `tests` section of package.yaml. + let missingDependencies = ["aeson", "aeson-pretty", "bytestring", "hspec-core", "stm", "text"] + addDepependencies = key "tests" . key "test" . key "dependencies" . _Array %~ (<> missingDependencies) + originalYaml <- decodeFileThrow packageFile :: IO Yaml.Value + encodeFile packageFile (addDepependencies originalYaml) -- Copy our custom hspec formatter into the input code directory so it can be used copyFile hspecFormatterPath (inputDir ++ "/test/HspecFormatter.hs")