@@ -79,26 +79,26 @@ general_tests = testGroup
7979 let input = " {\" etc/entries\" :{\" greeting\" :123}}"
8080 keys = [" greeting" ]
8181
82- config <- SUT. parseConfigSpec input
82+ ( config :: ConfigSpec () ) <- SUT. parseConfigSpec input
8383 case getConfigValue keys (specConfigValues config) of
84- Nothing -> assertFailure
84+ Just (ConfigValue value) -> assertEqual " should contain default value"
85+ (Just (JSON. Number 123 ))
86+ (defaultValue value)
87+ _ -> assertFailure
8588 (show keys ++ " should map to a config value, got sub config map instead" )
86- Just (value :: ConfigValue () ) -> assertEqual " should contain default value"
87- (Just (JSON. Number 123 ))
88- (defaultValue value)
8989 , testCase " entries that finish with arrays sets them as default value" $ do
9090 let input = " {\" etc/entries\" :{\" greeting\" :[123]}}"
9191 keys = [" greeting" ]
9292
93- config <- SUT. parseConfigSpec input
93+ ( config :: ConfigSpec () ) <- SUT. parseConfigSpec input
9494
9595 case getConfigValue keys (specConfigValues config) of
96- Nothing -> assertFailure
97- (show keys ++ " should map to a config value, got sub config map instead" )
98- Just (value :: ConfigValue () ) -> assertEqual
96+ Just (ConfigValue value) -> assertEqual
9997 " should contain default value"
10098 (Just (JSON. Array (Vector. fromList [JSON. Number 123 ])))
10199 (defaultValue value)
100+ _ -> assertFailure
101+ (show keys ++ " should map to a config value, got sub config map instead" )
102102 , testCase " entries with empty arrays as values fail because type cannot be infered" $ do
103103 let input = " {\" etc/entries\" :{\" greeting\" : []}}"
104104 case SUT. parseConfigSpec input of
@@ -115,44 +115,43 @@ general_tests = testGroup
115115 = " {\" etc/entries\" :{\" greeting\" :{\" etc/spec\" :{\" default\" :[],\" type\" :\" [string]\" }}}}"
116116 keys = [" greeting" ]
117117
118- config <- SUT. parseConfigSpec input
118+ ( config :: ConfigSpec () ) <- SUT. parseConfigSpec input
119119 case getConfigValue keys (specConfigValues config) of
120- Nothing -> assertFailure
121- (show keys ++ " should map to an array config value, got sub config map instead" )
120+ Just (ConfigValue value) -> assertEqual " should contain default array value"
121+ (Just (JSON. Array (Vector. fromList [] )))
122+ (defaultValue value)
122123
123- Just (value :: ConfigValue () ) -> assertEqual
124- " should contain default array value"
125- (Just (JSON. Array (Vector. fromList [] )))
126- (defaultValue value)
124+ _ -> assertFailure
125+ (show keys ++ " should map to an array config value, got sub config map instead" )
127126 , testCase " entries with array of objects do not fail" $ do
128127 let
129128 input
130129 = " {\" etc/entries\" :{\" greeting\" :{\" etc/spec\" :{\" default\" :[{\" hello\" :\" world\" }],\" type\" :\" [object]\" }}}}"
131130 keys = [" greeting" ]
132131
133- config <- SUT. parseConfigSpec input
132+ ( config :: ConfigSpec () ) <- SUT. parseConfigSpec input
134133 case getConfigValue keys (specConfigValues config) of
135- Nothing -> assertFailure
136- (show keys ++ " should map to an array config value, got sub config map instead" )
137-
138- Just (value :: ConfigValue () ) -> assertEqual
134+ Just (ConfigValue value) -> assertEqual
139135 " should contain default array value"
140136 (Just
141137 (JSON. Array (Vector. fromList [JSON. object [" hello" JSON. .= (" world" :: Text )]]))
142138 )
143139 (defaultValue value)
140+
141+ _ -> assertFailure
142+ (show keys ++ " should map to an array config value, got sub config map instead" )
144143 , testCase " entries can have many levels of nesting" $ do
145144 let input = " {\" etc/entries\" :{\" english\" :{\" greeting\" :\" hello\" }}}"
146145 keys = [" english" , " greeting" ]
147146
148- config <- SUT. parseConfigSpec input
147+ ( config :: ConfigSpec () ) <- SUT. parseConfigSpec input
149148
150149 case getConfigValue keys (specConfigValues config) of
151- Nothing -> assertFailure
150+ Just (ConfigValue value) -> assertEqual " should contain default value"
151+ (Just (JSON. String " hello" ))
152+ (defaultValue value)
153+ _ -> assertFailure
152154 (show keys ++ " should map to a config value, got sub config map instead" )
153- Just (value :: ConfigValue () ) -> assertEqual " should contain default value"
154- (Just (JSON. String " hello" ))
155- (defaultValue value)
156155 , testCase " spec map cannot be empty object" $ do
157156 let input = " {\" etc/entries\" :{\" greeting\" :{\" etc/spec\" :{}}}"
158157
@@ -233,11 +232,15 @@ cli_tests =
233232
234233 let
235234 result = do
236- value <- getConfigValue keys (specConfigValues config)
237- let valueType = configValueType value
238- PlainEntry metadata <- cliEntry (configSources value)
239- short <- optShort metadata
240- return (short, valueType)
235+ configValue <- getConfigValue keys (specConfigValues config)
236+ case configValue of
237+ ConfigValue value -> do
238+ let valueType = configValueType value
239+ PlainEntry metadata <- cliEntry (configSources value)
240+ short <- optShort metadata
241+ return (short, valueType)
242+ _ ->
243+ Nothing
241244
242245 case result of
243246 Nothing ->
@@ -255,11 +258,15 @@ cli_tests =
255258
256259 let
257260 result = do
258- value <- getConfigValue keys (specConfigValues config)
259- let valueType = configValueType value
260- PlainEntry metadata <- cliEntry (configSources value)
261- long <- optLong metadata
262- return (long, valueType)
261+ configValue <- getConfigValue keys (specConfigValues config)
262+ case configValue of
263+ ConfigValue value -> do
264+ let valueType = configValueType value
265+ PlainEntry metadata <- cliEntry (configSources value)
266+ long <- optLong metadata
267+ return (long, valueType)
268+ _ ->
269+ Nothing
263270
264271 case result of
265272 Nothing ->
@@ -277,11 +284,15 @@ cli_tests =
277284
278285 let
279286 result = do
280- value <- getConfigValue keys (specConfigValues config)
281- let valueType = configValueType value
282- CmdEntry cmd metadata <- cliEntry (configSources value)
283- long <- optLong metadata
284- return (cmd, long, valueType)
287+ configValue <- getConfigValue keys (specConfigValues config)
288+ case configValue of
289+ (ConfigValue value) -> do
290+ let valueType = configValueType value
291+ CmdEntry cmd metadata <- cliEntry (configSources value)
292+ long <- optLong metadata
293+ return (cmd, long, valueType)
294+ _ ->
295+ Nothing
285296
286297 case result of
287298 Nothing ->
@@ -317,11 +328,11 @@ envvar_tests = testGroup
317328 (config :: ConfigSpec () ) <- SUT. parseConfigSpec input
318329
319330 case getConfigValue keys (specConfigValues config) of
320- Nothing -> assertFailure
331+ Just (ConfigValue value) -> assertEqual " should contain EnvVar value"
332+ (ConfigSources (Just " GREETING" ) Nothing )
333+ (configSources value)
334+ _ -> assertFailure
321335 (show keys ++ " should map to a config value, got sub config map instead" )
322- Just value -> assertEqual " should contain EnvVar value"
323- (ConfigSources (Just " GREETING" ) Nothing )
324- (configSources value)
325336 ]
326337
327338#ifdef WITH_YAML
@@ -341,13 +352,13 @@ yaml_tests =
341352
342353 Right (config :: ConfigSpec () ) ->
343354 case getConfigValue keys (specConfigValues config) of
344- Nothing ->
345- assertFailure (show keys ++ " should map to a config value, got sub config map instead" )
346-
347- Just value ->
355+ Just (ConfigValue value) ->
348356 assertEqual " should contain EnvVar value"
349357 (ConfigSources (Just " GREETING" ) Nothing )
350358 (configSources value)
359+ _ ->
360+ assertFailure (show keys ++ " should map to a config value, got sub config map instead" )
361+
351362 ]
352363#endif
353364
0 commit comments