conferer-hspec 0.4.0.1 → 1.0.0.0
raw patch · 3 files changed
+121/−73 lines, 3 filesdep ~confererPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: conferer
API changes (from Hackage documentation)
- Conferer.FromConfig.Hspec: instance Conferer.Types.DefaultConfig Test.Hspec.Core.Config.Options.Config
- Conferer.FromConfig.Hspec: instance Conferer.Types.FromConfig Test.Hspec.Core.Config.Options.ColorMode
- Conferer.FromConfig.Hspec: instance Conferer.Types.FromConfig Test.Hspec.Core.Config.Options.Config
- Conferer.FromConfig.Hspec: instance Conferer.Types.FromConfig Test.Hspec.Core.Formatters.Monad.Formatter
+ Conferer.FromConfig.Hspec: desconstructHspecConfigToDefaults :: Config -> [(Key, Dynamic)]
+ Conferer.FromConfig.Hspec: instance Conferer.FromConfig.Internal.DefaultConfig Test.Hspec.Core.Config.Options.Config
+ Conferer.FromConfig.Hspec: instance Conferer.FromConfig.Internal.FromConfig Test.Hspec.Core.Config.Options.ColorMode
+ Conferer.FromConfig.Hspec: instance Conferer.FromConfig.Internal.FromConfig Test.Hspec.Core.Config.Options.Config
+ Conferer.FromConfig.Hspec: instance Conferer.FromConfig.Internal.FromConfig Test.Hspec.Core.Formatters.Monad.Formatter
Files
- CHANGELOG.md +16/−0
- conferer-hspec.cabal +14/−6
- src/Conferer/FromConfig/Hspec.hs +91/−67
+ CHANGELOG.md view
@@ -0,0 +1,16 @@+# Changelog+All notable changes to this project will be documented in this file.++The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),+and this project adheres to [PVP](https://pvp.haskell.org/).++## [Unreleased]++Nothing++## [v1.0.0.0] 2020-12-29++First release++[Unreleased]: https://github.com/ludat/conferer/compare/conferer-hspec_v1.0.0.0...HEAD+[v1.0.0.0]: https://github.com/ludat/conferer/compare/v0.0.0.0...conferer-hspec_v1.0.0.0
conferer-hspec.cabal view
@@ -4,10 +4,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: d2460b555266871dcd841c5f0ba8a5c5debe7085a5fc311bf534d9960f994eb5+-- hash: 8f226b4b1ae64ea15e4f2be1d5bdb7a15bb089fd67b8fa31c19953d5e8e4524c name: conferer-hspec-version: 0.4.0.1+version: 1.0.0.0 synopsis: conferer's FromConfig instances for hspec Config description: Library to abstract the parsing of many haskell config values from different config sources@@ -15,11 +15,13 @@ homepage: https://conferer.ludat.io author: Lucas David Traverso maintainer: lucas6246@gmail.com+copyright: (c) 2020 Lucas David Traverso license: MPL-2.0 license-file: LICENSE build-type: Simple extra-doc-files: README.md+ CHANGELOG.md LICENSE library@@ -29,12 +31,15 @@ Paths_conferer_hspec hs-source-dirs: src- default-extensions: OverloadedStrings LambdaCase QuasiQuotes ScopedTypeVariables+ default-extensions: OverloadedStrings LambdaCase QuasiQuotes ScopedTypeVariables RecordWildCards StrictData+ ghc-options: -Wall -Wredundant-constraints -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns build-depends: base >=4.3 && <5- , conferer >=0.4.0.0 && <0.5.0.0+ , conferer >=1.0.0.0 && <2.0.0.0 , hspec-core >=2.0.0 && <2.8.0 , text >=1.1 && <1.3+ if impl(ghc >= 8.4.1)+ ghc-options: -Wpartial-fields default-language: Haskell2010 test-suite specs@@ -44,12 +49,15 @@ Paths_conferer_hspec hs-source-dirs: test- default-extensions: OverloadedStrings LambdaCase QuasiQuotes ScopedTypeVariables+ default-extensions: OverloadedStrings LambdaCase QuasiQuotes ScopedTypeVariables RecordWildCards StrictData+ ghc-options: -Wall -Wredundant-constraints -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns build-depends: base >=4.3 && <5- , conferer >=0.4.0.0 && <0.5.0.0+ , conferer >=1.0.0.0 && <2.0.0.0 , conferer-hspec , hspec , hspec-core >=2.0.0 && <2.8.0 , text >=1.1 && <1.3+ if impl(ghc >= 8.4.1)+ ghc-options: -Wpartial-fields default-language: Haskell2010
src/Conferer/FromConfig/Hspec.hs view
@@ -1,94 +1,118 @@+-- |+-- Copyright: (c) 2019 Lucas David Traverso+-- License: MPL-2.0+-- Maintainer: Lucas David Traverso <lucas6246@gmail.com>+-- Stability: stable+-- Portability: portable+--+-- FromConfig instance for hspec+{-# OPTIONS_GHC -fno-warn-orphans #-} {-# LANGUAGE CPP #-}-module Conferer.FromConfig.Hspec- (- -- * How to use this- -- | FromConfig instance for snap server configuration- --- -- @- -- import Conferer- -- import Conferer.FromConfig.Snap ()- --- -- main = do- -- config <- 'defaultConfig' \"awesomeapp\"- -- snapConfig <- 'getFromConfig' \"snap\" config- -- @- --- -- * Internal utility functions- -- | These may be useful for someone but are subject to change at any point so- -- use with care- ) where+module Conferer.FromConfig.Hspec where -import Conferer.Core-import Conferer.Types-import Conferer.FromConfig.Basics+import Conferer.FromConfig -import Data.Either (rights)-import Data.String (fromString)-import Data.Text (Text, unpack, toLower)-import Data.Maybe (fromMaybe)+import Data.Text (toLower)+import Data.Dynamic (toDyn, Dynamic) import qualified Test.Hspec.Core.Runner as Hspec import qualified Test.Hspec.Core.Formatters as Hspec instance FromConfig Hspec.ColorMode where- updateFromConfig = updateAllAtOnceUsingFetch fetchFromConfig =- fetchFromConfigWith- (\t -> case t of- "ColorAuto" -> Just Hspec.ColorAuto- "ColorNever" -> Just Hspec.ColorNever- "ColorAlways" -> Just Hspec.ColorAlways- _ -> Nothing- )+ fetchFromConfigWith $+ (\case+ "auto" -> Just Hspec.ColorAuto+ "never" -> Just Hspec.ColorNever+ "always" -> Just Hspec.ColorAlways+ _ -> Nothing+ ) . toLower instance FromConfig Hspec.Formatter where- updateFromConfig = updateAllAtOnceUsingFetch fetchFromConfig =- fetchFromConfigWith- (\t -> case toLower t of- "silent" -> Just Hspec.silent- "specdoc" -> Just Hspec.specdoc- "progress" -> Just Hspec.progress- "failed_examples" -> Just Hspec.failed_examples- _ -> Nothing- )+ fetchFromConfigWith $+ (\case+ "silent" -> Just Hspec.silent+ "specdoc" -> Just Hspec.specdoc+ "progress" -> Just Hspec.progress+ "failed_examples" -> Just Hspec.failed_examples+ _ -> Nothing+ ) . toLower instance DefaultConfig Hspec.Config where configDef = Hspec.defaultConfig -instance FromConfig Hspec.Config where- fetchFromConfig key config = return Nothing- updateFromConfig k config original = do- pure original- >>= findKeyAndApplyConfig config k "dryRun" Hspec.configDryRun (\v c -> c { Hspec.configDryRun = v })- >>= findKeyAndApplyConfig config k "fastFail" Hspec.configFastFail (\v c -> c { Hspec.configFastFail = v })- >>= findKeyAndApplyConfig config k "rerun" Hspec.configRerun (\v c -> c { Hspec.configRerun = v })- >>= findKeyAndApplyConfig config k "quickCheckMaxSuccess" Hspec.configQuickCheckMaxSuccess (\v c -> c { Hspec.configQuickCheckMaxSuccess = v })- >>= findKeyAndApplyConfig config k "quickCheckMaxDiscardRatio" Hspec.configQuickCheckMaxDiscardRatio (\v c -> c { Hspec.configQuickCheckMaxDiscardRatio = v })- >>= findKeyAndApplyConfig config k "quickCheckMaxSize" Hspec.configQuickCheckMaxSize (\v c -> c { Hspec.configQuickCheckMaxSize = v })- >>= findKeyAndApplyConfig config k "quickCheckSeed" Hspec.configQuickCheckSeed (\v c -> c { Hspec.configQuickCheckSeed = v })- >>= findKeyAndApplyConfig config k "smallCheckDepth" Hspec.configSmallCheckDepth (\v c -> c { Hspec.configSmallCheckDepth = v })- >>= findKeyAndApplyConfig config k "colorMode" Hspec.configColorMode (\v c -> c { Hspec.configColorMode = v })- >>= findKeyAndApplyConfig config k "htmlOutput" Hspec.configHtmlOutput (\v c -> c { Hspec.configHtmlOutput = v })- >>= findKeyAndApplyConfig config k "formatter" Hspec.configFormatter (\v c -> c { Hspec.configFormatter = v })+-- | Deconstruct a 'Hspec.Config' into a many key/dynamic pairs to+-- provide valid defaults for downstream 'fetchFromConfig'+desconstructHspecConfigToDefaults :: Hspec.Config -> [(Key, Dynamic)]+desconstructHspecConfigToDefaults Hspec.Config{..} =+ [ ("dryRun", toDyn configDryRun)+ , ("fastFail", toDyn configFastFail)+ , ("rerun", toDyn configRerun)+ , ("quickCheckMaxSuccess", toDyn configQuickCheckMaxSuccess)+ , ("quickCheckMaxDiscardRatio", toDyn configQuickCheckMaxDiscardRatio)+ , ("quickCheckMaxSize", toDyn configQuickCheckMaxSize)+ , ("quickCheckSeed", toDyn configQuickCheckSeed)+ , ("smallCheckDepth", toDyn configSmallCheckDepth)+ , ("colorMode", toDyn configColorMode)+ , ("htmlOutput", toDyn configHtmlOutput)+ , ("formatter", toDyn configFormatter) #if MIN_VERSION_hspec_core(2,1,1)- -- We ignore configuration of type function that don't have defaults provided by the lib- -- >>= findKeyAndApplyConfig config k "skip-predicate" (\v c -> c { Hspec.configSkipPredicate = v })+ , ("skipPredicate", toDyn configSkipPredicate) #endif #if MIN_VERSION_hspec_core(2,1,9)- >>= findKeyAndApplyConfig config k "concurrentJobs" Hspec.configConcurrentJobs (\v c -> c { Hspec.configConcurrentJobs = v })+ , ("concurrentJobs", toDyn configConcurrentJobs) #endif #if MIN_VERSION_hspec_core(2,4,0)- >>= findKeyAndApplyConfig config k "ignoreConfigFile" Hspec.configIgnoreConfigFile (\v c -> c { Hspec.configIgnoreConfigFile = v })- >>= findKeyAndApplyConfig config k "printCpuTime" Hspec.configPrintCpuTime (\v c -> c { Hspec.configPrintCpuTime = v })- >>= findKeyAndApplyConfig config k "diff" Hspec.configDiff (\v c -> c { Hspec.configDiff = v })+ , ("ignoreConfigFile", toDyn configIgnoreConfigFile)+ , ("printCpuTime", toDyn configPrintCpuTime)+ , ("diff", toDyn configDiff) #endif #if MIN_VERSION_hspec_core(2,4,2)- >>= findKeyAndApplyConfig config k "failureReport" Hspec.configFailureReport (\v c -> c { Hspec.configFailureReport = v })+ , ("failureReport", toDyn configFailureReport) #endif #if MIN_VERSION_hspec_core(2,7,0)- >>= findKeyAndApplyConfig config k "focusedOnly" Hspec.configFocusedOnly (\v c -> c { Hspec.configFocusedOnly = v })- >>= findKeyAndApplyConfig config k "failOnFocused" Hspec.configFailOnFocused (\v c -> c { Hspec.configFailOnFocused = v })+ , ("focusedOnly", toDyn configFocusedOnly)+ , ("failOnFocused", toDyn configFailOnFocused) #endif- >>= return+ ] +instance FromConfig Hspec.Config where+ fetchFromConfig key originalConfig = do+ config <- addDefaultsAfterDeconstructingToDefaults+ desconstructHspecConfigToDefaults+ key originalConfig++ configDryRun <- fetchFromConfig (key /. "dryRun") config+ configFastFail <- fetchFromConfig (key /. "fastFail") config+ configRerun <- fetchFromConfig (key /. "rerun") config+ configQuickCheckMaxSuccess <- fetchFromConfig (key /. "quickCheckMaxSuccess") config+ configQuickCheckMaxDiscardRatio <- fetchFromConfig (key /. "quickCheckMaxDiscardRatio") config+ configQuickCheckMaxSize <- fetchFromConfig (key /. "quickCheckMaxSize") config+ configQuickCheckSeed <- fetchFromConfig (key /. "quickCheckSeed") config+ configSmallCheckDepth <- fetchFromConfig (key /. "smallCheckDepth") config+ configColorMode <- fetchFromConfig (key /. "colorMode") config+ configHtmlOutput <- fetchFromConfig (key /. "htmlOutput") config+ configFormatter <- fetchFromConfig (key /. "formatter") config+ configRerunAllOnSuccess <- fetchFromConfig (key /. "rerunAllOnSuccess") config+ configFilterPredicate <- fetchFromConfig (key /. "filterPredicate") config+ configOutputFile <- fetchFromConfig (key /. "outputFile") config+#if MIN_VERSION_hspec_core(2,1,1)+ configSkipPredicate <- fetchFromConfig (key /. "skipPredicate") config+#endif+#if MIN_VERSION_hspec_core(2,1,9)+ configConcurrentJobs <- fetchFromConfig (key /. "concurrentJobs") config+#endif+#if MIN_VERSION_hspec_core(2,4,0)+ configIgnoreConfigFile <- fetchFromConfig (key /. "ignoreConfigFile") config+ configPrintCpuTime <- fetchFromConfig (key /. "printCpuTime") config+ configDiff <- fetchFromConfig (key /. "diff") config+#endif+#if MIN_VERSION_hspec_core(2,4,2)+ configFailureReport <- fetchFromConfig (key /. "failureReport") config+#endif+#if MIN_VERSION_hspec_core(2,7,0)+ configFocusedOnly <- fetchFromConfig (key /. "focusedOnly") config+ configFailOnFocused <- fetchFromConfig (key /. "failOnFocused") config+#endif+ pure Hspec.Config{..}