]> gitweb.michael.orlitzky.com - haeredes.git/blobdiff - src/Main.hs
Sort output to fix random breakage in the test suite.
[haeredes.git] / src / Main.hs
index f513ec67ff62149c5ec1409940cedbdab1bae7e2..c9356bfd9318de6d96c279d0bd9dd0608fe9b332 100644 (file)
@@ -1,4 +1,4 @@
-module Main
+module Main (main)
 where
 
 import Control.Concurrent.ParallelIO.Global (
 where
 
 import Control.Concurrent.ParallelIO.Global (
@@ -9,9 +9,9 @@ import qualified Data.ByteString.Char8 as BS (
   getContents,
   pack,
   words )
   getContents,
   pack,
   words )
-import Data.List ( (\\) )
-import Data.String.Utils (join)
+import Data.List ( (\\), intersperse, sort )
 import Network.DNS (
 import Network.DNS (
+  DNSError(NameError),
   Domain,
   FileOrNumericHost(RCHostName),
   ResolvConf(resolvInfo, resolvTimeout),
   Domain,
   FileOrNumericHost(RCHostName),
   ResolvConf(resolvInfo, resolvTimeout),
@@ -20,18 +20,19 @@ import Network.DNS (
   normalize,
   normalizeCase,
   withResolver )
   normalize,
   normalizeCase,
   withResolver )
-import System.Exit (ExitCode(..), exitWith)
+import System.Exit (ExitCode(ExitFailure), exitWith)
 import System.IO (hPutStrLn, stderr)
 
 import System.IO (hPutStrLn, stderr)
 
-
-import CommandLine (Args(..), get_args)
+import CommandLine (
+   Args(NS,MX,delegates,no_append_root,server,timeout),
+   get_args)
 import DNS (
   LookupResult,
   lookupMX',
   lookupNS',
   resolve_address )
 import ExitCodes (exit_bad_server)
 import DNS (
   LookupResult,
   lookupMX',
   lookupNS',
   resolve_address )
 import ExitCodes (exit_bad_server)
-import Timeout (Timeout(..))
+import Timeout (Timeout(seconds))
 
 
 -- | Given a list of delegates, report results for this
 
 
 -- | Given a list of delegates, report results for this
@@ -52,25 +53,34 @@ report :: [Domain] -- ^ The list of @delgts@
        -> LookupResult
        -> IO ()
 
        -> LookupResult
        -> IO ()
 
--- If the lookup resulted in a DNS error, we just ignore the whole
--- thing.
-report _ _ (_, Left _) = return ()
-
 -- If the lookup succeeded but there were no results, report that the
 -- If the lookup succeeded but there were no results, report that the
--- domain is not delegated.
-report _ _ (d, Right []) =
+-- domain is not delegated. Note that the behavior of the DNS library
+-- changed with regard to this at some point: we used to get back
+-- a "success," but with an empty list of results. Now a NameError
+-- (which is not actually an error!) is returned.
+report _ _ (d, Left NameError) =
   putStrLn $ "Domain " ++ (show d) ++ " not delegated."
 
   putStrLn $ "Domain " ++ (show d) ++ " not delegated."
 
+-- If the lookup resulted in some other DNS error, we just ignore the
+-- whole thing.
+report _ _ (_, Left _) = return ()
+
 -- Otherwise, subtract our delegates from the list of results and
 -- report the leftovers.
 report delgts normalize_function (d, Right raw_hosts) = do
   let nrml_hosts = map normalize_function raw_hosts
 -- Otherwise, subtract our delegates from the list of results and
 -- report the leftovers.
 report delgts normalize_function (d, Right raw_hosts) = do
   let nrml_hosts = map normalize_function raw_hosts
-  let leftovers = nrml_hosts \\ delgts
+  -- Sort the leftovers so that we can test the expected output.
+  let leftovers = sort (nrml_hosts \\ delgts)
   unless (null leftovers) $
     putStrLn $ "Domain " ++
                (show d) ++
                " delegates somewhere else: " ++
                (join " " (map show leftovers))
   unless (null leftovers) $
     putStrLn $ "Domain " ++
                (show d) ++
                " delegates somewhere else: " ++
                (join " " (map show leftovers))
+  where
+    -- Create one big string by joining together a list of smaller
+    -- strings and placing a delimiter between them.
+    join :: String -> [String] -> String
+    join delimiter strings = concat (intersperse delimiter strings)
 
 
 main :: IO ()
 
 
 main :: IO ()