]> gitweb.michael.orlitzky.com - haeredes.git/commitdiff
test: add a shelltestrunner test suite for the man page examples.
authorMichael Orlitzky <michael@orlitzky.com>
Sat, 2 Mar 2019 03:20:55 +0000 (22:20 -0500)
committerMichael Orlitzky <michael@orlitzky.com>
Sat, 2 Mar 2019 03:20:55 +0000 (22:20 -0500)
haeredes.cabal
test/ShellTests.hs [new file with mode: 0644]
test/shell/bad-dns-server.test [new file with mode: 0644]
test/shell/manpage-dns-errors.test [new file with mode: 0644]
test/shell/manpage-example.com.test [new file with mode: 0644]
test/shell/manpage-no-append-root.test [new file with mode: 0644]
test/shell/manpage-not-delegated.test [new file with mode: 0644]
test/shell/manpage-orlitzky.com-failure.test [new file with mode: 0644]
test/shell/manpage-orlitzky.com-success.test [new file with mode: 0644]

index f4a41215862f6c5c88ec09a97592edb03df1a88e..4bfcf04090ffc23c3c41a2f2e49850c2ada84838 100644 (file)
@@ -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 (file)
index 0000000..8874fcf
--- /dev/null
@@ -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 (file)
index 0000000..3ef0893
--- /dev/null
@@ -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 (file)
index 0000000..f3e9251
--- /dev/null
@@ -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 (file)
index 0000000..3f36a14
--- /dev/null
@@ -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 (file)
index 0000000..8b7efce
--- /dev/null
@@ -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 (file)
index 0000000..dd9015e
--- /dev/null
@@ -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 (file)
index 0000000..afbd07a
--- /dev/null
@@ -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 (file)
index 0000000..8afa67d
--- /dev/null
@@ -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