summaryrefslogtreecommitdiff
path: root/TestConfig.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-04-07 22:03:31 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-04-07 22:03:31 -0400
commite2404ca40933ccdc046d08f7040b2d86e32d5f88 (patch)
tree6dc73067bbfb00cf989970f6b7c178bf6a39c09b /TestConfig.hs
parentb889543507959c0a311bc8387f78ec4c0e93f7a8 (diff)
refactor away whichCmd and some other cleanup
Diffstat (limited to 'TestConfig.hs')
-rw-r--r--TestConfig.hs36
1 files changed, 16 insertions, 20 deletions
diff --git a/TestConfig.hs b/TestConfig.hs
index f6ca2afcd..9b2759e19 100644
--- a/TestConfig.hs
+++ b/TestConfig.hs
@@ -72,30 +72,26 @@ testCmd k cmdline = do
{- Ensures that one of a set of commands is available by running each in
- turn. The Config is set to the first one found. -}
-selectCmd :: ConfigKey -> [String] -> Test
-selectCmd k cmds = search cmds
+selectCmd :: Bool -> ConfigKey -> [String] -> String -> Test
+selectCmd required k cmds param = search cmds
where
- search [] = do
- testEnd $ Config k (BoolConfig False)
- error $ "* need one of these commands, but none are available: " ++ show (map (head . words) cmds)
+ search [] = failure
search (c:cs) = do
- ret <- system $ quiet c
+ ret <- system $ quiet c ++ " " ++ param
if (ret == ExitSuccess)
- then return $ Config k (StringConfig c)
- else search cs
-
-whichCmd :: ConfigKey -> [String] -> Test
-whichCmd k cmds = search cmds
- where
- search [] = do
- 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 (MaybeStringConfig $ Just $ head $ words c)
+ then success c
else search cs
+ success c
+ | required == True = return $ Config k (StringConfig c)
+ | otherwise = return $ Config k (MaybeStringConfig $ Just c)
+ failure
+ | required == True = do
+ testEnd $ Config k (BoolConfig False)
+ error $ "* need one of these commands, but none are available: " ++ show cmds
+ | otherwise = do
+ let r = Config k (MaybeStringConfig Nothing)
+ testEnd r
+ return r
quiet :: String -> String
quiet s = s ++ " >/dev/null 2>&1"