From 020ce4ca32627a92a6ed47922543912a57195377 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Fri, 1 Mar 2019 22:20:55 -0500 Subject: [PATCH] test: add a shelltestrunner test suite for the man page examples. --- haeredes.cabal | 30 ++++++++++++++++++++ test/ShellTests.hs | 24 ++++++++++++++++ test/shell/bad-dns-server.test | 7 +++++ test/shell/manpage-dns-errors.test | 6 ++++ test/shell/manpage-example.com.test | 6 ++++ test/shell/manpage-no-append-root.test | 9 ++++++ test/shell/manpage-not-delegated.test | 6 ++++ test/shell/manpage-orlitzky.com-failure.test | 6 ++++ test/shell/manpage-orlitzky.com-success.test | 6 ++++ 9 files changed, 100 insertions(+) create mode 100644 test/ShellTests.hs create mode 100644 test/shell/bad-dns-server.test create mode 100644 test/shell/manpage-dns-errors.test create mode 100644 test/shell/manpage-example.com.test create mode 100644 test/shell/manpage-no-append-root.test create mode 100644 test/shell/manpage-not-delegated.test create mode 100644 test/shell/manpage-orlitzky.com-failure.test create mode 100644 test/shell/manpage-orlitzky.com-success.test diff --git a/haeredes.cabal b/haeredes.cabal index f4a4121..4bfcf04 100644 --- a/haeredes.cabal +++ b/haeredes.cabal @@ -138,6 +138,36 @@ test-suite doctests -optc-O3 -optc-march=native + +-- These won't work without shelltestrunner installed in your +-- $PATH. Maybe there is some way to tell Cabal that. +test-suite shelltests + type: exitcode-stdio-1.0 + hs-source-dirs: test + main-is: ShellTests.hs + + build-depends: + base == 4.*, + bytestring >= 0.10, + cmdargs >= 0.10, + dns >= 1.4, + iproute >= 1.2, + parallel-io >= 0.3, + process >= 1.1 + + -- It's not entirely clear to me why I have to reproduce all of this. + ghc-options: + -Weverything + -Wno-implicit-prelude + -Wno-safe + -Wno-unsafe + -Wno-all-missed-specialisations + -rtsopts + -threaded + -optc-O3 + -optc-march=native + + source-repository head type: git location: http://gitweb.michael.orlitzky.com/haeredes.git diff --git a/test/ShellTests.hs b/test/ShellTests.hs new file mode 100644 index 0000000..8874fcf --- /dev/null +++ b/test/ShellTests.hs @@ -0,0 +1,24 @@ +module Main (main) +where + +import System.Process ( + CreateProcess( env ), + createProcess, + shell, + waitForProcess ) +import System.Exit ( exitWith ) + +main :: IO () +main = do + -- Get a CreateProcess object corresponding to our shell command. + let createproc = shell "shelltest test/shell/*.test" + + -- But clear its environment before running the command. + let empty_env_createproc = createproc { env = Just [] } + + -- Ignore stdin/stdout/stderr... + (_,_,_,hproc) <- createProcess empty_env_createproc + + -- Now run the ProcessHandle and exit with its result. + result <- waitForProcess hproc + exitWith result diff --git a/test/shell/bad-dns-server.test b/test/shell/bad-dns-server.test new file mode 100644 index 0000000..3ef0893 --- /dev/null +++ b/test/shell/bad-dns-server.test @@ -0,0 +1,7 @@ +# Test that we get an error code upon exiting if the given --server +# is unusable for some reason. + +echo "example.com" | dist/build/haeredes/haeredes --server localhost a.iana-servers.net b.iana-servers.net +>>>2 +Bad DNS server or lookup error: IllegalDomain +>>>= 1 diff --git a/test/shell/manpage-dns-errors.test b/test/shell/manpage-dns-errors.test new file mode 100644 index 0000000..f3e9251 --- /dev/null +++ b/test/shell/manpage-dns-errors.test @@ -0,0 +1,6 @@ +# Test the example given in the man page which shows that most DNS +# errors are ignored. + +echo "example.com" | dist/build/haeredes/haeredes --timeout=1 --server 10.1.46.12 ns1.example.com +>>> +>>>= 0 diff --git a/test/shell/manpage-example.com.test b/test/shell/manpage-example.com.test new file mode 100644 index 0000000..3f36a14 --- /dev/null +++ b/test/shell/manpage-example.com.test @@ -0,0 +1,6 @@ +# Test the "example.com" example from the man page. + +# These are the two expected name servers, so haerdes should be quiet. +echo "example.com" | dist/build/haeredes/haeredes a.iana-servers.net b.iana-servers.net +>>> +>>>= 0 diff --git a/test/shell/manpage-no-append-root.test b/test/shell/manpage-no-append-root.test new file mode 100644 index 0000000..8b7efce --- /dev/null +++ b/test/shell/manpage-no-append-root.test @@ -0,0 +1,9 @@ +# Test the "no-append-root" example from the man page. + +# If you add "--no-append-root" to the previous "example.com" example +# (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." +>>>= 0 + diff --git a/test/shell/manpage-not-delegated.test b/test/shell/manpage-not-delegated.test new file mode 100644 index 0000000..dd9015e --- /dev/null +++ b/test/shell/manpage-not-delegated.test @@ -0,0 +1,6 @@ +# Test the "not delegated" example from the man page. + +echo "foo.doesnt-exist" | dist/build/haeredes/haeredes +>>> +Domain "foo.doesnt-exist." not delegated. +>>>= 0 diff --git a/test/shell/manpage-orlitzky.com-failure.test b/test/shell/manpage-orlitzky.com-failure.test new file mode 100644 index 0000000..afbd07a --- /dev/null +++ b/test/shell/manpage-orlitzky.com-failure.test @@ -0,0 +1,6 @@ +# Test the failing "orlitzky.com" example from the man page. + +echo "orlitzky.com" | dist/build/haeredes/haeredes dns1.viabit.com +>>> +Domain "orlitzky.com." delegates somewhere else: "dns2.viabit.com." +>>>= 0 diff --git a/test/shell/manpage-orlitzky.com-success.test b/test/shell/manpage-orlitzky.com-success.test new file mode 100644 index 0000000..8afa67d --- /dev/null +++ b/test/shell/manpage-orlitzky.com-success.test @@ -0,0 +1,6 @@ +# Test the successful "orlitzky.com" example from the man page. + +# These are the two expected name servers, so haerdes should be quiet. +echo "orlitzky.com" | dist/build/haeredes/haeredes --server d.gtld-servers.net dns1.viabit.com dns2.viabit.com +>>> +>>>= 0 -- 2.44.2