about summary refs log tree commit diff
diff options
context:
space:
mode:
authorWilliam Carroll <wpcarro@gmail.com>2020-08-05T20·37+0100
committerWilliam Carroll <wpcarro@gmail.com>2020-08-05T20·37+0100
commit40753e9f3b2df9f620c588d1d385b5ddfb9bd1bc (patch)
tree4d9783a632519a8a8b0415e0aaac2a40782a9adb
parentc4299558a75df8ea173c77dbc8800930dfa6519d (diff)
Add some the scaffolding for testing
As I attempt to habituate TDD, I should have some examples of tests to minimize
all friction preventing me from testing.
-rw-r--r--scratch/brilliant/Spec.hs19
-rw-r--r--scratch/brilliant/shell.nix1
2 files changed, 20 insertions, 0 deletions
diff --git a/scratch/brilliant/Spec.hs b/scratch/brilliant/Spec.hs
new file mode 100644
index 000000000000..f348dd0669a1
--- /dev/null
+++ b/scratch/brilliant/Spec.hs
@@ -0,0 +1,19 @@
+--------------------------------------------------------------------------------
+module Spec where
+--------------------------------------------------------------------------------
+import Test.Hspec
+import Test.QuickCheck
+import Control.Exception (evaluate)
+--------------------------------------------------------------------------------
+
+main :: IO ()
+main = hspec $ do
+  describe "Prelude.head" $ do
+    it "returns the first element of a list" $ do
+      head [23 ..] `shouldBe` (23 :: Integer)
+
+    it "returns the first element of an arbitrary list" $
+      property $ \x xs -> head (x:xs) == (x :: Integer)
+
+    it "throws an exception if used with an empty list" $ do
+      evaluate (head []) `shouldThrow` anyException
diff --git a/scratch/brilliant/shell.nix b/scratch/brilliant/shell.nix
index 58a2e9a6a573..06fcc7979d2e 100644
--- a/scratch/brilliant/shell.nix
+++ b/scratch/brilliant/shell.nix
@@ -3,6 +3,7 @@ let
 in pkgs.mkShell {
   buildInputs = with pkgs; [
     (haskellPackages.ghcWithPackages (hpkgs: with hpkgs; [
+      hspec
       optparse-applicative
     ]))
   ];