Advertisement
kpfp_linux

Untitled

Aug 25th, 2014
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. foo :: Monad m => m Int
  2. foo = fail "nope"
  3.  
  4. shouldThrowH x y = x `seq` y `seq` shouldThrow x y
  5.  
  6. spec :: Spec
  7. spec = do
  8.   describe "foo" $ do
  9.     it "does not work, heatsink (I)" $ do
  10.       let res :: Either String Int
  11.           res = foo
  12.       res @?= Left "nope"
  13.       --uncaught exception: ErrorCall (nope)
  14.     it "does not work, heatsink (II)" $ do
  15.       let res :: Either String Int
  16.           res = foo
  17.       return res `shouldReturn` Left "nope"
  18.       --uncaught exception: ErrorCall (nope)
  19.     it "does not work, heatsink (III)" $ do
  20.       let res :: Either String Int
  21.           res = foo
  22.       evaluate res `shouldReturn` Left "nope"
  23.       --uncaught exception: ErrorCall (nope)
  24.     it "does not work, heatsink (IV)" $ do
  25.       let res :: Either String Int
  26.           res = foo
  27.           x = res `seq` ()
  28.       res `shouldBe` Left "nope"
  29.       --uncaught exception: ErrorCall (nope)
  30.     it "does not work, heatsink (V)" $ do
  31.       let res :: Either String Int
  32.           res = foo
  33.           x = res `seq` ()
  34.       return res `shouldThrowH` errorCall "nope"
  35.       --uncaught exception: ErrorCall (nope)
  36.     it "**does** work, heatsink (VI)" $ do
  37.       let res :: Either String Int
  38.           res = foo
  39.           x = res `seq` ()
  40.       evaluate res `shouldThrowH` errorCall "nope"
  41.     it "**does** work, heatsink (VII)" $ do
  42.       let res :: Either String Int
  43.           res = foo
  44.           x = res `seq` ()
  45.       evaluate res `shouldThrow` errorCall "nope"
  46.     it "works!" $ do
  47.       let res :: Maybe Int
  48.           res = foo
  49.       res `shouldBe` Nothing
  50.     it "this does not work" $ do
  51.       let res :: Either String Int
  52.           res = foo
  53.           exp :: Either String Int
  54.           exp = Left "nope"
  55.       res `shouldBe` exp
  56.       -- uncaught exception: ErrorCall (nope)
  57.     it "this does not work either..." $ do
  58.       let res :: Either String Int
  59.           res = foo
  60.       return res `shouldThrow` anyException
  61.       -- did not get expected exception: SomeException
  62.     it "...neither this" $ do
  63.       let res :: Either String Int
  64.           res = foo
  65.       return res `shouldThrow` errorCall "nope"
  66.       -- did not get expected exception: ErrorCall
  67.     it "...nor this" $ do
  68.       let res :: Either String Int
  69.           res = foo
  70.       return res `shouldThrow` anyErrorCall
  71.       -- did not get expected exception: ErrorCall
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement