aboutsummaryrefslogtreecommitdiffstats
path: root/test/TestUtils.hs
blob: 676df1d436e1418f4896995cb8784bf5d1feb104 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
{-# OPTIONS_GHC -Wno-missing-export-lists #-}
module TestUtils where

import Control.Monad.Except
import Control.Monad.Reader
import Utils

initialConfig :: Config
initialConfig = Config {
    configScriptFileName = Nothing,
    configVerboseMode = False,
    configShowHelp = False
}

testRunL :: LContext a -> IO (Either LException a)
testRunL lc = runExceptT $ runReaderT lc initialConfig

expectSuccessL :: LContext a -> IO a
expectSuccessL lc =
     do res <- testRunL lc
        case res of
            Left (LException err) -> error $ "unexpected error: " ++ err
            Right val -> return val

expectErrorL :: Show a => LContext a -> IO String
expectErrorL lc =
     do res <- testRunL lc
        case res of
            Left (LException err) -> return err
            Right val -> error $ "unexpected success: " ++ show val