From bf804f73ce3494be430054499c5ce18f232f68ca Mon Sep 17 00:00:00 2001 From: Joris Date: Fri, 18 Mar 2016 09:50:39 +0100 Subject: Add optional imports --- tests/Helper.hs | 2 +- tests/Test.hs | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/Helper.hs b/tests/Helper.hs index 3dcc267..00bccc9 100644 --- a/tests/Helper.hs +++ b/tests/Helper.hs @@ -14,7 +14,7 @@ import qualified Data.Text.IO as T import Data.Maybe (fromJust) import Data.ConfigManager -import Data.ConfigManager.Config +import Data.ConfigManager.Types (Config) forceGetConfig :: Text -> IO Config forceGetConfig = (fmap fromJust) . getConfig diff --git a/tests/Test.hs b/tests/Test.hs index 957f3ae..03dc979 100644 --- a/tests/Test.hs +++ b/tests/Test.hs @@ -14,7 +14,7 @@ import Test.Framework.Providers.HUnit import Test.HUnit hiding (Test) import Data.ConfigManager -import Data.ConfigManager.Config +import Data.ConfigManager.Types (Config(..)) import qualified Data.Text as T import Helper (forceGetConfig, getConfig, eitherToMaybe) @@ -115,3 +115,12 @@ importAssertion = do assertEqual "d" (Just "zap") (lookup "d" config :: Maybe String) assertEqual "e" (Just "re nam") (lookup "e" config :: Maybe String) assertEqual "f" (Just 8.5) (lookup "f" config :: Maybe Double) + + missingConfig <- getConfig "import \"required.conf\"" + assertEqual "missing config" Nothing missingConfig + + missingOptionalConfig <- forceGetConfig $ T.unlines + [ "importMaybe \"required.conf\"" + , "x = 4" + ] + assertEqual "missing optional config" (Just 4) (lookup "x" missingOptionalConfig :: Maybe Int) -- cgit v1.2.3