1
+ {-# LANGUAGE ScopedTypeVariables #-}
2
+ {-# LANGUAGE LambdaCase #-}
1
3
{-# LANGUAGE OverloadedStrings #-}
2
4
3
5
module Main where
@@ -10,18 +12,27 @@ import qualified Test.QuickCheck as QC
10
12
import qualified Test.QuickCheck.Monadic as QC
11
13
import Data.Aeson (Value (.. ))
12
14
import Control.Monad.IO.Class (liftIO )
13
- import Control.Monad.Catch (SomeException , MonadCatch (.. ))
15
+ import Control.Monad.Catch (try , SomeException , MonadCatch (.. ))
14
16
import Data.Text (pack )
15
17
import qualified Data.HashMap.Strict as HM
16
18
import qualified Data.Vector as V
17
19
import Quickjs
20
+ import Test.HUnit (assertFailure )
21
+ import Quickjs.Error (SomeJSRuntimeException )
18
22
19
23
20
24
eval_1_plus_2 :: Assertion
21
25
eval_1_plus_2 = quickjsMultithreaded $ do
22
26
v <- eval " 1 + 2;"
23
27
liftIO $ v @?= Number 3
24
28
29
+
30
+ eval_throw :: Assertion
31
+ eval_throw = quickjsMultithreaded $
32
+ try (eval " throw 'Error'" ) >>= \ case
33
+ Left (_ :: SomeJSRuntimeException ) -> return ()
34
+ Right _ -> liftIO $ assertFailure " should fail with an Exception..."
35
+
25
36
genText = do
26
37
k <- QC. choose (0 ,200 )
27
38
pack <$> QC. vectorOf k (QC. oneof $ map pure $ [' 0' .. ' ~' ])
@@ -63,6 +74,7 @@ tests =
63
74
testGroup " Quickjs"
64
75
[ testCase " empty quickjs call" (quickjsMultithreaded $ pure () )
65
76
, testCase " eval '1 + 2;'" eval_1_plus_2
77
+ , testCase " eval throw" eval_throw
66
78
, testProperty " marshalling Value to JSValue and back" marshall_to_from_JSValue
67
79
]
68
80
0 commit comments