Skip to content

Commit

Permalink
Test error handling when call fails
Browse files Browse the repository at this point in the history
  • Loading branch information
tarleb committed Jul 23, 2017
1 parent 92bd543 commit 1db5653
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions test/Foreign/LuaTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module Foreign.LuaTest (tests) where
import Prelude hiding (concat)

import Control.Applicative ((<|>))
import Control.Monad (when)
import Data.ByteString (ByteString)
import Data.Either (isLeft, isRight)
import Data.Monoid ((<>))
Expand Down Expand Up @@ -152,6 +153,16 @@ tests = testGroup "lua integration tests"
, testCase "second alternative is used when first fails" $
assertEqual "alternative failed" (Right True) =<<
runLuaEither (throwLuaError "test" <|> return True)

, testCase "calling a function that errors throws exception" $
let msg = "error message"
luaCode = "return error('" ++ msg ++ "')"
err = "[string \"" ++ luaCode ++ "\"]:1: " ++ msg
in assertEqual "problem in error" (Left (LuaException err)) =<<
(runLuaEither $ do
openbase
res <- loadstring luaCode
when (res == LuaOK) $ call 0 0)
]
]

Expand Down

0 comments on commit 1db5653

Please sign in to comment.