From fdf3555b3e8a1f937172baa691ca219b0e54a35f Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Fri, 1 Mar 2019 22:33:36 -0500 Subject: [PATCH] Sort output to fix random breakage in the test suite. The results that we get back from DNS are returned in an arbitrary order. Technically that's fine, because all we want to see is the set-difference between the actual/expected results. However, it breaks our test suite which needs to know what certain examples will output. This commit sorts the results, so that the output is a little bit more deterministic (subject to network issues and changes). --- doc/man1/haeredes.1 | 2 +- src/Main.hs | 5 +++-- test/shell/manpage-no-append-root.test | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/doc/man1/haeredes.1 b/doc/man1/haeredes.1 index 197b7e8..6ea57eb 100644 --- a/doc/man1/haeredes.1 +++ b/doc/man1/haeredes.1 @@ -143,7 +143,7 @@ get false positives. .I $ echo \(dqexample.com\(dq | \\\\ .I " haeredes \-\-no\-append\-root a.iana-servers.net b.iana-servers.net" Domain \(dqexample.com\(dq delegates somewhere else: -\(dqb.iana-servers.net.\(dq \(dqa.iana-servers.net.\(dq +\(dqa.iana-servers.net.\(dq \(dqb.iana-servers.net.\(dq .fi .IP \[bu] Check orlitzky.com against the expected name servers, using diff --git a/src/Main.hs b/src/Main.hs index c93697a..c9356bf 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -9,7 +9,7 @@ import qualified Data.ByteString.Char8 as BS ( getContents, pack, words ) -import Data.List ( (\\), intersperse ) +import Data.List ( (\\), intersperse, sort ) import Network.DNS ( DNSError(NameError), Domain, @@ -69,7 +69,8 @@ report _ _ (_, Left _) = return () -- 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) ++ diff --git a/test/shell/manpage-no-append-root.test b/test/shell/manpage-no-append-root.test index 8b7efce..f81ba8d 100644 --- a/test/shell/manpage-no-append-root.test +++ b/test/shell/manpage-no-append-root.test @@ -4,6 +4,6 @@ # (without adding the trailing dot), then things go wrong. echo "example.com" | dist/build/haeredes/haeredes --no-append-root a.iana-servers.net b.iana-servers.net >>> -Domain "example.com" delegates somewhere else: "b.iana-servers.net." "a.iana-servers.net." +Domain "example.com" delegates somewhere else: "a.iana-servers.net." "b.iana-servers.net." >>>= 0 -- 2.44.2