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.
This commit is contained in:
William Carroll 2020-08-05 21:37:08 +01:00
parent c4299558a7
commit 40753e9f3b
2 changed files with 20 additions and 0 deletions

19
scratch/brilliant/Spec.hs Normal file
View file

@ -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

View file

@ -3,6 +3,7 @@ let
in pkgs.mkShell { in pkgs.mkShell {
buildInputs = with pkgs; [ buildInputs = with pkgs; [
(haskellPackages.ghcWithPackages (hpkgs: with hpkgs; [ (haskellPackages.ghcWithPackages (hpkgs: with hpkgs; [
hspec
optparse-applicative optparse-applicative
])) ]))
]; ];