diff --git a/rhine/test/Clock/Except.hs b/rhine/test/Clock/Except.hs new file mode 100644 index 000000000..699c61c72 --- /dev/null +++ b/rhine/test/Clock/Except.hs @@ -0,0 +1,63 @@ +{-# LANGUAGE Arrows #-} +{-# LANGUAGE OverloadedStrings #-} + +module Clock.Except where + +-- base +import GHC.IO.Handle (hDuplicateTo) +import System.IO (IOMode (ReadMode), stdin, withFile) + +-- transformers +import Control.Monad.Trans.Writer.CPS + +-- text +import Data.Text (Text) + +-- tasty +import Test.Tasty (testGroup) + +-- tasty-hunit +import Test.Tasty.HUnit (testCase, (@?)) + +-- rhine +import FRP.Rhine +import FRP.Rhine.Clock.Except (CatchClock (CatchClock), ExceptClock (ExceptClock)) +import Paths_rhine +import System.IO.Error (isEOFError) + +type E = ExceptT IOError IO +type WT = WriterT [Text] +type M = WT E +type EClock = ExceptClock StdinClock IOError + + +type TestClock = + LiftClock + E + WT + ( CatchClock + EClock + IOError + EClock + IOError + ) + +-- FIXME also need to test the other branch of CatchClock +testClock :: TestClock +testClock = liftClock $ CatchClock (ExceptClock StdinClock) $ const $ Right $ ExceptClock StdinClock + +clsf :: ClSF M TestClock () () +clsf = proc () -> do + tag <- tagS -< () + arrMCl tell -< either (const ["weird"]) pure tag + +tests = + testGroup + "ExceptClock" + [ testCase "Outputs the exception on EOF" $ do + testdataFile <- getDataFileName "test/assets/testdata.txt" + withFile testdataFile ReadMode $ \h -> do + hDuplicateTo h stdin + Left result <- runExceptT $ runWriterT $ flow $ clsf @@ testClock + isEOFError result @? "It's an EOF error" + ]