summaryrefslogtreecommitdiff
path: root/TestConfig.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-04-07 21:47:56 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-04-07 21:47:56 -0400
commitb889543507959c0a311bc8387f78ec4c0e93f7a8 (patch)
treee51d144458d551a0232572ed89ef795f907ae9c1 /TestConfig.hs
parentf5b2d650bb75dc7ca2f77dae59fb1ab7f7405e03 (diff)
let's use Maybe String for commands that may not be avilable
Diffstat (limited to 'TestConfig.hs')
-rw-r--r--TestConfig.hs18
1 files changed, 13 insertions, 5 deletions
diff --git a/TestConfig.hs b/TestConfig.hs
index d1560b660..f6ca2afcd 100644
--- a/TestConfig.hs
+++ b/TestConfig.hs
@@ -7,7 +7,10 @@ import System.Cmd
import System.Exit
type ConfigKey = String
-data ConfigValue = BoolConfig Bool | StringConfig String
+data ConfigValue =
+ BoolConfig Bool |
+ StringConfig String |
+ MaybeStringConfig (Maybe String)
data Config = Config ConfigKey ConfigValue
type Test = IO Config
@@ -17,15 +20,17 @@ data TestCase = TestCase TestName Test
instance Show ConfigValue where
show (BoolConfig b) = show b
show (StringConfig s) = show s
+ show (MaybeStringConfig s) = show s
instance Show Config where
- show (Config key value) = unlines
+ show (Config key value) = unlines
[ key ++ " :: " ++ valuetype value
, key ++ " = " ++ show value
]
where
valuetype (BoolConfig _) = "Bool"
valuetype (StringConfig _) = "String"
+ valuetype (MaybeStringConfig _) = "Maybe String"
writeSysConfig :: [Config] -> IO ()
writeSysConfig config = writeFile "SysConfig.hs" body
@@ -83,12 +88,13 @@ whichCmd :: ConfigKey -> [String] -> Test
whichCmd k cmds = search cmds
where
search [] = do
- testEnd $ Config k (StringConfig "")
- return $ Config k (StringConfig "")
+ let r = Config k (MaybeStringConfig Nothing)
+ testEnd r
+ return r
search (c:cs) = do
ret <- system $ quiet c
if (ret == ExitSuccess)
- then return $ Config k (StringConfig $ head $ words c)
+ then return $ Config k (MaybeStringConfig $ Just $ head $ words c)
else search cs
quiet :: String -> String
@@ -103,3 +109,5 @@ testEnd :: Config -> IO ()
testEnd (Config _ (BoolConfig True)) = putStrLn $ " yes"
testEnd (Config _ (BoolConfig False)) = putStrLn $ " no"
testEnd (Config _ (StringConfig s)) = putStrLn $ " " ++ s
+testEnd (Config _ (MaybeStringConfig (Just s))) = putStrLn $ " " ++ s
+testEnd (Config _ (MaybeStringConfig Nothing)) = putStrLn $ " not available"