Skip to content

Commit

Permalink
Parse yaml before working on it (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthijsBlom authored Apr 24, 2024
1 parent 96f97c4 commit ad17ccc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
4 changes: 4 additions & 0 deletions test-setup/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ executables:
source-dirs: src
ghc-options: -Wall
dependencies:
- aeson
- directory
- lens
- lens-aeson
- yaml
16 changes: 12 additions & 4 deletions test-setup/src/Main.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{-# LANGUAGE OverloadedLists #-}
{-# LANGUAGE OverloadedStrings #-}

{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}
module Main (main) where
import Data.List (findIndex, isInfixOf)
Expand All @@ -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
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit ad17ccc

Please sign in to comment.