diff options
author | Joey Hess <joey@kitenet.net> | 2011-04-08 00:12:00 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2011-04-08 00:18:09 -0400 |
commit | a77c34d2b4795a5d41f82a78e999ce33f43d8862 (patch) | |
tree | 6b387b9bf30dba14c6776862e0d5decc581f428f /TestConfig.hs | |
parent | dfc1bfcc76036549eb49d8e88136d9d40e77a51a (diff) |
refactor
Diffstat (limited to 'TestConfig.hs')
-rw-r--r-- | TestConfig.hs | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/TestConfig.hs b/TestConfig.hs index 9b2759e19..bab297003 100644 --- a/TestConfig.hs +++ b/TestConfig.hs @@ -72,26 +72,28 @@ 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 :: Bool -> ConfigKey -> [String] -> String -> Test -selectCmd required k cmds param = search cmds +selectCmd :: ConfigKey -> [String] -> String -> Test +selectCmd k = searchCmd + (\match -> return $ Config k $ StringConfig match) + (\cmds -> do + testEnd $ Config k $ BoolConfig False + error $ "* need one of these commands, but none are available: " ++ show cmds + ) + +maybeSelectCmd :: ConfigKey -> [String] -> String -> Test +maybeSelectCmd k = searchCmd + (\match -> return $ Config k $ MaybeStringConfig $ Just match) + (\_ -> return $ Config k $ MaybeStringConfig Nothing) + +searchCmd :: (String -> Test) -> ([String] -> Test) -> [String] -> String -> Test +searchCmd success failure cmds param = search cmds where - search [] = failure + search [] = failure cmds search (c:cs) = do ret <- system $ quiet c ++ " " ++ param if (ret == ExitSuccess) 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" |