-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
70 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,5 +100,7 @@ tests: | |
- hspec-expectations-lifted | ||
- lens-aeson | ||
- load-env | ||
- opt-env-conf | ||
- restyler | ||
- text | ||
- unliftio |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
module Restyler.ConfigSpec | ||
( spec | ||
) where | ||
|
||
import Restyler.Prelude | ||
|
||
import Data.Text.IO (hPutStr) | ||
import OptEnvConf.Args (parseArgs) | ||
import OptEnvConf.EnvMap qualified as EnvMap | ||
import OptEnvConf.Run (runParserOn) | ||
import Restyler.Config | ||
import System.IO (hClose) | ||
import Test.Hspec | ||
import UnliftIO.Temporary (withSystemTempFile) | ||
|
||
spec :: Spec | ||
spec = do | ||
it "uses defined defaults" $ do | ||
config <- loadTestConfig [] [] ["Foo.hs"] | ||
config.enabled `shouldBe` True | ||
|
||
loadTestConfig | ||
:: HasCallStack | ||
=> [Text] | ||
-- ^ Lines of Yaml | ||
-- | ||
-- Empty means to behave as if no file at all. | ||
-> [(String, String)] | ||
-- ^ ENV | ||
-> [String] | ||
-- ^ Args | ||
-> IO Config | ||
loadTestConfig yaml env args = do | ||
result <- case yaml of | ||
[] -> runParser ["config/default.yaml"] | ||
ls -> withSystemTempFile "restyler-test-config.yaml" $ \path h -> do | ||
hPutStr h (unlines ls) >> hClose h | ||
runParser [path, "config/default.yaml"] | ||
|
||
case result of | ||
Left errs -> do | ||
expectationFailure $ show errs | ||
error "unreachable" | ||
Right config -> pure config | ||
where | ||
runParser paths = | ||
runParserOn | ||
Nothing | ||
(configParser paths) | ||
(parseArgs args) | ||
(EnvMap.parse env) | ||
Nothing |